This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
How to turn off a warning for one line of code.
- To: egcs at cygnus dot com
- Subject: How to turn off a warning for one line of code.
- From: Benjamin Scherrey <scherrey at switchco dot com>
- Date: Sat, 10 Oct 1998 03:32:25 -0400
- Organization: Proteus Technologies, Inc.
- Reply-To: scherrey at proteus-tech dot com
Thanx to some previous replies, I've found a way to get my debug command
to take up zero space/time when turned off. I do the following:
--- debug.hpp
#ifdef DEBUG
#define PDBUG cout __FILE__ << ":" __LINE__ <<
// Its actually a lot more complicated than this but you get the
idea.
#else
#define PDBUG false && cout
// used to be able to #define PDBUG /##/ but egcs won't let me. :-(
#endif // DEBUG
--- test.cpp
#include "debug.hpp"
PDBUG << "My error message..." << endl;
Now this code generates warnings that say:
warning: statement with no effect
every time I used PDBUG with debugging turned off. That's a LOT of
places!
Of course, I can kill this globally with a -Wno-unused param at the
command line but I don't want to lose this warning globally, just on my
lines of code that use the PDBUG macro. I've tried to get an
__attribute__ (unused) thing going but with no success. Is there a
#pragma or something I can declare within my macro that will silence the
compiler for this one instance?
thanx & later,
Ben Scherrey