• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: new uint8_t
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new uint8_t


  • Subject: Re: new uint8_t
  • From: James Bucanek <email@hidden>
  • Date: Wed, 13 Dec 2006 07:47:39 -0700

Keith Alperin wrote on Wednesday, December 13, 2006:

>Greetings cocoa-devs,
>
>Like the original poster in the recent "init char buffer to null"
>thread, I know some cocoa, but am not very familiar with straight up
>C.  I'm working on some license verification code using examples
>provided in these excellent articles: http://tinyurl.com/yeus87 and
>http://tinyurl.com/y7rp5n .  Unfortunately, the compiler gives me a
>"'new' undeclared (first use in this function)" on the following:
>   uint8_t* destination;
>   destination = new uint8_t[returnedRSASize];
>
>I'm trying to allocate this buffer in a C function in one of my cocoa
>classes.  I suspect that the "new unint8_t" semantic is not allowed
>in an objective-c file but i haven't been able to find any
>information about it.

You guessed correctly. That's C++ syntax.

You need to allocate a buffer big enough to hold returnedRSASize number of uint8_t (which is just a typedef for unsigned char).

If you want to stick with Cocoa, use

    NSData* destination = [NSMutalbeData dataWithLength:(returnedRSASize*sizeof(uint8_t)]

If you want to do it the "C" way

    uint8_t* destnation = calloc(returnedRSASize,sizeof(uint8_t)); /* initialized to all zeros */
or
    uint8_t* destination = malloc(returnedRSASize*sizeof(uint8_t)) /* uninitialized block of memory
*/

You might have to cast some of this, depending on how strict your compiler warnings are set. You'll have to release the buffer with free() when you're done with it.

--
James Bucanek
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >new uint8_t (From: Keith Alperin <email@hidden>)

  • Prev by Date: Cocoa UI
  • Next by Date: Re: Cocoa UI
  • Previous by thread: new uint8_t
  • Next by thread: Re: new uint8_t
  • Index(es):
    • Date
    • Thread