• 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: NS_INLINE and obj = nil;?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NS_INLINE and obj = nil;?


  • Subject: Re: NS_INLINE and obj = nil;?
  • From: Clark Cox <email@hidden>
  • Date: Sat, 2 Jan 2010 08:28:23 -0800

On Sat, Jan 2, 2010 at 6:29 AM, Alexander Spohr <email@hidden> wrote:
>
> Am 02.01.2010 um 05:09 schrieb Stephen J. Butler:
>
>> If you really wanted a macro, it would look like this:
>>
>> #define GDRelease(x) do { [(x) release]; (x) = nil; } while (0)
>
> What is the do while good for?
>
> Would this not work as well:
> #define GDRelease(x) { [(x) release]; (x) = nil; }
>
> Or even this:
> #define GDRelease(x) [(x) release], (x) = nil;
>

No, neither would work as well. Consider the following:

if(x)
    GDRelease(x);
else
    foo(x);


With the do/while, that expands to:

if(x)
    do { [(x) release]; (x) = nil; } while (0);
else
    foo(x);

which works just fine. However, your first example, would expand to:

if(x)
    { [(x) release]; (x) = nil; };
else
    foo(x);

That semi-colon makes that statement a parse error. and your second
example expands to:

if(x)
    [(x) release]; (x) = nil;
else
    foo(x);

which is also a parse error.

--
Clark S. Cox III
email@hidden
_______________________________________________

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: NS_INLINE and obj = nil;?
      • From: Alexander Spohr <email@hidden>
References: 
 >NS_INLINE and obj = nil;? (From: aaron smith <email@hidden>)
 >Re: NS_INLINE and obj = nil;? (From: "Stephen J. Butler" <email@hidden>)
 >Re: NS_INLINE and obj = nil;? (From: Alexander Spohr <email@hidden>)

  • Prev by Date: Re: NS_INLINE and obj = nil;?
  • Next by Date: Re: NS_INLINE and obj = nil;?
  • Previous by thread: Re: NS_INLINE and obj = nil;?
  • Next by thread: Re: NS_INLINE and obj = nil;?
  • Index(es):
    • Date
    • Thread