Am 02.01.2010 um 17:28 schrieb Clark Cox:

> On Sat, Jan 2, 2010 at 6:29 AM, Alexander Spohr <[email protected]> wrote:

>> 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.

I see.

> 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.

Right.

> and your second example expands to:
> 
> if(x)
>    [(x) release]; (x) = nil;
> else
>    foo(x);
> 
> which is also a parse error.

No to this.
I put a , not a ; between the statements. So at least my last example would 
work - had I just left the last ; out of it:

#define GDRelease(x) [(x) release], (x) = nil
expands to:
if(x)
   [(x) release], (x) = nil;
else
   foo(x);

But the while(0) looks not as fragile.

        atze

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to