Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2006:
[Freeciv-Dev] Re: (PR#15126) patch: fc_free macro

[Freeciv-Dev] Re: (PR#15126) patch: fc_free macro

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#15126) patch: fc_free macro
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 10 Jan 2006 12:10:08 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: >

Christian Prochaska wrote:
> <URL: >
>>[jdorje - Di 10. Jan 2006, 19:00:23]:
>>Such a macro violates the rules of function-looking macros.  That is, it 
>>looks like a function but it behaves as no function ever could.
>>If we have it (code like this is used in several places) it should be 
> The macro in gui-sdl/gui_mem.h is actually
> #define FREE(ptr) do { if (ptr) free(ptr); ptr = NULL; } while(0)
> So as I now understand the do {} while(0) construct is just to make it
> not look like a function and thus the macro in utility/mem.h should be
> #define FC_FREE(ptr) do { free(ptr); ptr = NULL; } while(0)
> correct?

The do...while construct is to make it act like a single statement.  For 
instance in

   if (x)

without the do...while bits the code is quite a bit different, even if 
you use brackets in the FREE (as your original did).


[Prev in Thread] Current Thread [Next in Thread]