• 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: Calling a Cocoa library from C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling a Cocoa library from C


  • Subject: Re: Calling a Cocoa library from C
  • From: Nathan Sims <email@hidden>
  • Date: Sat, 12 Nov 2011 12:01:28 -0800

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

> On Nov 12, 2011, at 10:56 AM, Thomas Davie wrote:
>> 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.

Hmm, if not a global, where would the declaration go? The C function certainly shouldn't return it, so if it is to remain persistent across calls, wouldn't the logical (the only?) place for it be as a global in the library's .m file?

Something like this:

mylibrary.m:
-------------------------------------------------

#import "ObjcCode.h"
ObjcCode *objcCode;

. . .

int setup_data()
{
	objcCode = [[ObjcCode alloc]init];
	return 0;
}
int get_float_data(float *result1, float *result2)
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	[objcCode call];
	*result1 = [more stuff];
	etc.;

	[pool drain];
	return 0;
}
int quit_data()
{
	[objcCode release];
	objcCode = nil;
	return 0;
}


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Calling a Cocoa library from C
      • From: Jens Alfke <email@hidden>
References: 
 >Calling a Cocoa library from C (From: Nathan Sims <email@hidden>)
 >Re: Calling a Cocoa library from C (From: Wim Lewis <email@hidden>)
 >Re: Calling a Cocoa library from C (From: Nathan Sims <email@hidden>)
 >Re: Calling a Cocoa library from C (From: Thomas Davie <email@hidden>)

  • Prev by Date: Re: Calling a Cocoa library from C
  • Next by Date: Re: Calling a Cocoa library from C
  • Previous by thread: Re: Calling a Cocoa library from C
  • Next by thread: Re: Calling a Cocoa library from C
  • Index(es):
    • Date
    • Thread