On Sat, Jan 2, 2010 at 6:29 AM, Alexander Spohr <[email protected]> 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 protected]
_______________________________________________

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