Re: new uint8_t
Re: new uint8_t
- Subject: Re: new uint8_t
- From: Keith Alperin <email@hidden>
- Date: Wed, 13 Dec 2006 22:09:42 -0600
That worked beautifully. Thank you both so much!
Best,
Keith
On Dec 13, 2006, at 9:00 AM, Timothy Klein wrote:
On 13 Dec 2006, at 5:54 AM, Keith Alperin wrote:
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. Is there some other way to create the
buffer in .m file?
'new' is a C++ construct, not a C one.
Normal C would use:
destination = (uint8_t*)malloc(sizeof(uint8_t)*returnedRSASize);.
At least that would be my first thought. Managing memory the C way
is labor intensive.
You cast the pointer returned to the proper type to avoid a
warning, and help with type-checking for the compiler (malloc
returns a void*); you ask for returnedRSASize blocks, but you make
each one as big as a uint8_t in memory, which is what the sizeof()
operator does (use sizeof, even if you know the size. It can vary
by machine).
Sincerely,
Timothy Klein
--
email@hidden
_______________________________________________
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
_______________________________________________
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