On 12 Nov 2011, at 18:45, Nathan Sims wrote:

> On Nov 11, 2011, at 6:22 PM, Wim Lewis wrote:
> 
>> int get_float_data(float *result1, float *result2)
>> {
>> NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>> @try {
>>  [objcCode call];
>>  *result1 = [more stuff];
>>  etc.;
>> } @catch {
>>  fprintf(stderr, "omg doomed!\n");
>>  etc.;
>> } @finally {
>>  [pool drain];
>> }
>> 
>> return blahblah;
>> }
> 
> Wow, I didn't realize how integrated C and Objc are, that you could employ 
> Objc code from a C function. Kewl.

Strictly speaking, this is an objective-c function.  But, Objective-C is a 
superset of C – this means that all valid C programs are valid objective-c 
programs with the same meaning.  In this case, the C function definition syntax 
has the same meaning when you're writing objective-c, only now we can make 
objective-c calls, and use objective-c exception catching because we're writing 
objective-c.

As someone else mentioned, this should now be written with the @autoreleasepool 
directive.

> Okay, does this mean that an object instantiated by a C function has 
> persistence across C function calls? In the example above you have:
>    [objcCode call];
> I'm guessing I would have to have:
>    ObjcCode *objcCode;
> declared globally in the library, and that would suffice?

Declared somewhere certainly – I would highly recommend against it being a 
global though for all the usual reasons to avoid globals.

Tom Davie_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to