Yes, thanks, that works when changing the orignal code (I use similar constructs in code that I write.). But I was intending to not modify the orignal source....thinking more like gcc test.c -o test.o -c -include GoofyMacroToAllowRuntimeSwithingOf_PoundIf_DebugStatements.h Where test.c has the ----------------- #ifdef DEBUG_XXX printf("Some debug data\n"); #endif ----------------- in it......... Or uglier, "perl/sed DebugToGlobVar.pl test.c > dbg.test.c ;gcc dbg.test.c -c -o test.o " Elden Crom Tucson Embedded Systems, Inc 520-575-7283 x141 Fax: 520-575-5563 Cell: 520-429-2771 Email:EldenC@xxxxxxxxxxxxxxxxxx 5620 N. Kolb Road Suite 160 Tucson, AZ 85750-1384 -----Original Message----- From: John (Eljay) Love-Jensen [mailto:eljay@xxxxxxxxx] Sent: Wednesday, March 31, 2010 3:13 PM To: Elden Crom Subject: RE: C/C++ Preprocessor -- #ifdef to if(){....} Hi Elden Crom, #define DEBUG_MSG(msg) \ do { if (global_debug_print > 0) \ { \ std::cerr << msg; \ }} while(false) Example of usage: DEBUG_MSG("x:" << point.x << " y:" << point.y); The do/while wrapper is to prevent the if() from getting attached to the wrong else. if (foo) DEBUG_MSG(blah); else DestroyTheWorld(); You can get arbitrarily fancy with your DEBUG_MSG macro. #define DEBUG_MSG(msg) \ do { if (global_debug_print > 0) \ { \ std::ostringstream out; \ out << msg; \ std::string s = out.str(); \ PostErrorLog(s.c_str()); \ }} while(false) Sincerely, --Eljay ________________________________________ From: gcc-help-owner@xxxxxxxxxxx [gcc-help-owner@xxxxxxxxxxx] On Behalf Of Elden Crom [EldenC@xxxxxxxxxxxxxxxxxx] Sent: Wednesday, March 31, 2010 4:24 PM To: gcc-help@xxxxxxxxxxx Subject: C/C++ Preprocessor -- #ifdef to if(){....} Is there a slick-but-evil (preprocessor?) mechanism to replace ----------------------- #ifdef DEBUG_XXX printf("Some debug data\n"); #endif ----------------------- With ============================= extern "C" int global_debug_print; if(global_debug_print>0){ printf("Some debug data\n"); } ============================= While not touching other '#if ... [#else] ... #endif' constructs Elden Crom Tucson Embedded Systems, Inc 520-575-7283 x141 Fax: 520-575-5563 Cell: 520-429-2771 Email:EldenC@xxxxxxxxxxxxxxxxxx 5620 N. Kolb Road Suite 160 Tucson, AZ 85750-1384