warning: statement with no effect
Chris Doran
cdoran@globespan.net
Thu Aug 24 17:17:00 GMT 2000
Hello,
I have a debug function of the form
----------------->
int DbgOut(int Filter, char *Format, ...);
<-----------------
which is used to provide printf() functionality in my debug builds. But in
my release builds I want all calls to DbgOut() to drop out _completely_
during preprocessing. So I have the following code in my DbgOut.h:
----------------->
#if DBGOUT
extern int DbgOut(int Filter, char *Format, ...);
#else
#define DbgOut(Filter,Format,args...) 0
#endif
<-----------------
However, compiling with DBGOUT=0 causes the following code
----------------->
1 void DumpFunction(void) {
2 if(DbgOut(1,"This returns nonzero only if filter 1 is enabled.")) {
3 DbgOut(1,"More extensive dump since I know filter 1 is enabled.");
4 }
5 }
<-----------------
to generate the "warning: statement with no effect" on line 3.
If a change my DbgOut macro to
#define DbgOut(Filter,Format,args...) (void)0
I get "error: void value not ignored as it ought to be" on line 2.
I already tried variations on
#define DbgOut(Filter,Format,args...) (1 ? (int)0:(void)0)
to no avail.
I would be satisfied with a command-line option to suppress the "warning:
statement with no effect" message, but there doesn't seem to be one. Note
that "statement with no effect" is exactly what I want. 8)
Any help would be appreciated.
Chris Doran
cdoran@icompression.com
gcc i386 version 2.91.66 19990314/Linux (egcs-1.1.2 release)
Complete test code:
----------------->
#define DBGOUT 0
#if DBGOUT
extern int DbgOut(int Filter, char *Format, ...);
#else
#define DbgOut(Filter,Format,args...) 0
#endif
void DumpFunction(void) {
if(DbgOut(1,"This returns nonzero only if filter 1 is enabled.")) {
DbgOut(1,"More extensive dump since I know filter 1 is enabled.");
}
DbgOut(2,"Another filter.");
}
<-----------------
More information about the Gcc-bugs
mailing list