• 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: C typedef for NS ptrs?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C typedef for NS ptrs?


  • Subject: Re: C typedef for NS ptrs?
  • From: Greg Parker <email@hidden>
  • Date: Fri, 2 Apr 2010 14:51:19 -0700

On Apr 2, 2010, at 2:38 PM, Andy O'Meara wrote:
> Hey folks, quick question...
>
> A have a couple vanilla NS object ptrs (e.g. NSWindow*) that I have to pass through some cross-plaform C++ code until it ends up in a .mm file where where the NS object is accessed.  The problem is that in the .cpp code, there's no obvious way to declare a NSWindow ptr so that thinks will link without complaint.  If, for example, in a key header I use:
>
> #ifdef __OBJC__
>    #define NSWindowPtr   NSWindow*
> #else
>    #define NSWindowPtr   void*
> #endif
>
> then everything of course compiles, but nothing links (since all the .cpp object files are looking for proc arguments with void* while the .mm object files are are declared with the real deal).
>
> So, what can I replace that second macro with such that it meshes with ObjC's typedef mangling scheme?

You can't fool C++ name mangling using typedefs or macros. But you can tell C++ that NSWindow is an opaque struct. Then you can use `NSWindow *` or `typedef NSWindow* NSWindowPtr` on both sides without trouble.

    #ifdef __OBJC__
    # include <AppKit/AppKit.h>
    #else
    struct NSWindow;
    #endif


--
Greg Parker     email@hidden     Runtime Wrangler


_______________________________________________

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

References: 
 >C typedef for NS ptrs? (From: Andy O'Meara <email@hidden>)

  • Prev by Date: Re: NSPredicate/NSExpression - can they solve this Core Data problem?
  • Next by Date: Re: How to save and restore NSScrollView scroll position?
  • Previous by thread: C typedef for NS ptrs?
  • Next by thread: Re: C typedef for NS ptrs?
  • Index(es):
    • Date
    • Thread