Forum Topic - warning on if-zero-ed code on gcc 4.3.x, bug or feature? : (4 Items)
   
warning on if-zero-ed code on gcc 4.3.x, bug or feature?  
Look into the following code a.c, gcc or qcc a.c shows warning of the line begining with !!. Interesting is the warning 
is on the missing of the end " in the 3rd arg in snprintf(). Why the compiler parses the line that is not in action? 

Also, the parsing looks a bit selective: it won't say anything on the !!. If you add a line of garbage, say, aaaaaa, the
 compiler also says nothing on it. 

Thanks
Weijie

===================
#include <stdio.h>

void afunc(int status)
{
        char buf[1024];
#if 0
!!      snprintf(buf, sizeof(buf), "%04x, status);
#else
        snprintf(buf, sizeof(buf), "%04x", status);
#endif
}

int main() {
	return 0; 
}
Re: warning on if-zero-ed code on gcc 4.3.x, bug or feature?  
this is highly unlikely, you sure you compile THIS code? Shift it by one line to check.


Weijie Zhang wrote:
> Look into the following code a.c, gcc or qcc a.c shows warning of the line begining with !!. Interesting is the 
warning is on the missing of the end " in the 3rd arg in snprintf(). Why the compiler parses the line that is not in 
action? 
> 
> Also, the parsing looks a bit selective: it won't say anything on the !!. If you add a line of garbage, say, aaaaaa, 
the compiler also says nothing on it. 
> 
> Thanks
> Weijie
> 
> ===================
> #include <stdio.h>
> 
> void afunc(int status)
> {
>         char buf[1024];
> #if 0
> !!      snprintf(buf, sizeof(buf), "%04x, status);
> #else
>         snprintf(buf, sizeof(buf), "%04x", status);
> #endif
> }
> 
> int main() {
> 	return 0; 
> }
> 
> _______________________________________________
> General
> http://community.qnx.com/sf/go/post29444
> 
Re: warning on if-zero-ed code on gcc 4.3.x, bug or feature?  
Weijie Zhang wrote:
> Look into the following code a.c, gcc or qcc a.c shows warning of the line begining with !!. Interesting is the 
warning is on the missing of the end " in the 3rd arg in snprintf(). Why the compiler parses the line that is not in 
action? 
> 
> Also, the parsing looks a bit selective: it won't say anything on the !!. If you add a line of garbage, say, aaaaaa, 
the compiler also says nothing on it. 

This is to be expected. The tokens have to be parsable by the 
preprocessor. Use comments instead.

Regards,

Ryan Mansfield
Re: warning on if-zero-ed code on gcc 4.3.x, bug or feature?  
Thanks Ryan. So it indicates at least theoretically if a code has too many if 0, it costs longer time to be built. Thus 
the same thing (cost longer time to build) for if the code is written for targeting many os platforms if it has many 
ifdef OS_A, and else ifdef OS_B etc.