• 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
namespace/encapsulation problems with mixed C/Obj-C app...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

namespace/encapsulation problems with mixed C/Obj-C app...


  • Subject: namespace/encapsulation problems with mixed C/Obj-C app...
  • From: Philip George <email@hidden>
  • Date: Sun, 31 Aug 2003 18:11:17 -0500

I want C functions in my Cocoa app to be able to reference object state
variables declared in its @interface section. How can I do this?

I realize that passing the address of an object's state variable would work,
but there is a 3rd-party API that I'm using that has a specific protoype for
a C function that I have to follow so I can't add another argument for
passing that info.

I also realize that I can put global variables outside of the @interface
section (which is my current workaround), but that ruins my data
encapsulation.

Thanks.

(example below)...

- Philip



SUPER-SIMPLIFIED EXAMPLE:



#import <Cocoa/Cocoa.h>
#include <stdio.h>

void plainCFunction();

@interface MyObject : NSObject {
int jenny;
}

@end



@implementation MyObject

// compiles and works perfectly...
- (void)applicationDidFinishLaunching:(NSNotification *)notif {
jenny = 5;
printf("%d\n", jenny);
plainCFunction();
return;
}

// fails to compile, because the compiler can't see jenny from in here...
void plainCFunction() {
printf("%d\n", jenny);
return;
}

@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Application menu won't change
  • Next by Date: NSImage from Palm Bitmap?
  • Previous by thread: Re: Application menu won't change
  • Next by thread: NSImage from Palm Bitmap?
  • Index(es):
    • Date
    • Thread