This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
warning: statement with no effect
- To: "'bug-gcc at gnu dot org'" <bug-gcc at gnu dot org>
- Subject: warning: statement with no effect
- From: Chris Doran <cdoran at globespan dot net>
- Date: Thu, 24 Aug 2000 20:16:50 -0400
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.");
}
<-----------------