• 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: Nil and nil Macro Conflict
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Nil and nil Macro Conflict


  • Subject: Re: Nil and nil Macro Conflict
  • From: Andreas Grosam <email@hidden>
  • Date: Wed, 02 May 2012 08:52:57 +0200

On May 1, 2012, at 7:16 PM, Greg Parker wrote:

> On May 1, 2012, at 7:10 AM, Andreas Grosam <email@hidden> wrote:
>> Hm, the library is a header only template library - namely its spirit (from boost), so my chances to never include this library are zero ;)
>>
>> Basically, I need something like the following to compile:
>>
>> // file foo.m:
>>
>> #include <Foundation/Foundation.h>
>>
>> namespace nm {
>>   struct nil {};
>>   struct Nil {};
>> }
>>
>> NSObject* o = nil;
>
> If you never need to use boost's nil in your own code, you can carefully order your includes so the boost headers are always first.
>
> #include <boost/header-that-uses-nil.h>  // uses nil
> #include <Foundation/Foundation.h>       // #defines nil but doesn't affect the boost header
> NSObject *o = nil;  // uses objc's nil

I thought about this, too. But Foundation.h is often in a Prefix header, as in my case. So this would require to include the boost header(s) in the prefix header as well. It's a viable solution, since I control the prefix header. It makes the project setup a bit fragile, though (removing the prefix will cause the project to not compile anymore).

But as you too would suggest it, and it seems this is still the least intrusive solution to this issue, I'll give it a try.


>
> If you do need to use boost's nil in your own code, you can use macro tricks to rename their nil.
>
> #define nil boost_nil
> #include <boost/header-that-uses-nil.h>
> #undef nil
> #include <Foundation/Foundation.h>
> // now you have objc's nil and boost::boost_nil

That's a handy trick - still I need to put the boost header in front of the Foundation header within the prefix file.


Thank you Greg, and thank you all others for the tips!

Regards
Andreas


_______________________________________________

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: 
 >Nil and nil Macro Conflict (From: Andreas Grosam <email@hidden>)
 >Re: Nil and nil Macro Conflict (From: Scott Ribe <email@hidden>)
 >Re: Nil and nil Macro Conflict (From: Andreas Grosam <email@hidden>)
 >Re: Nil and nil Macro Conflict (From: Greg Parker <email@hidden>)

  • Prev by Date: Re: Nil and nil Macro Conflict
  • Next by Date: Re: Nil and nil Macro Conflict
  • Previous by thread: Re: Nil and nil Macro Conflict
  • Next by thread: Re: Modal-loop Event-handling question
  • Index(es):
    • Date
    • Thread