Re: NS_INLINE and obj = nil;?
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