[cfe-dev] warning: if statement has empty body

रजनीश rdogra at earthlink.net
Sun Mar 15 18:11:38 PDT 2009


On Mar 15, 2009, at 3:24 PM, Pierre Habouzit wrote:

> On Sat, Mar 14, 2009 at 05:37:20AM +0000, रजनीश wrote:
>> never mind then.
>> code expands to
>> 	if (0) ;
>> So what is the purpose of this kind of coding.
>
> It's just bad, CF_OBJC_FUNCDISPATCH? should expand to (void)0 or
> `do { } while (0)` or anything similar that the compiler will optimize
> out and is a valid expression, when it's meant to do nothing.
>
> Defining it to expand to nothing is just bad. For example, had you
> written something like:
>
> `if (CF_OBJC_FUNCDISPATCH(...), 10)` it would result in a compilation
> failure instead of just a warning. Arguably this kind of coding  
> style is
> even worse, but ...

Apparently, it looks like all this is last minute
hack because only part of the code was open sourced by Apple.

#define CFDictionary 0
#define CFSet 0
#define CFBag 0
#undef CFBag
#define CFBag 1

So things like the above violate all kind of coding style for Cocoa  
framework.
Why it was code this way in the first place is beyond my comprehension.

CF_OBJC_FUNCDISPATCH expands to (void(0)), if it is __WIN32__.

CoreFoundation in principle could be great standard library that goes  
with the C compiler (Clang).
but l am sure Apple wouldn't want that and license would preclude it  
too.
After seeing this kind of kludge,  I am reluctant to advocate it.



More information about the cfe-dev mailing list