From: Eric Backus Subject: Re: How do you eliminate dead code? To: pcrowley AT qdeck DOT com Date: Tue, 6 Jul 93 15:42:50 PDT Cc: djgpp AT sun DOT soe DOT clarkson DOT edu (djgpp) Mailer: Elm [revision: 66.25] > #define TRACE 0 > > if (TRACE) fprintf(stderr... > > this gets assembled as > jmp --\ > push | > ... | > call fprintf | > <-/ > > I am compiling this with -O2 -m486. Does anyone know if there is a switch > to eliminate the inaccessable code? I am quite surprised that gcc does not eliminate the dead code. However, I usually do this in one of two ways: Way 1: /* At the beginning of the file */ #define DEBUG /* To print debug info */ #ifdef DEBUG fprintf(stderr, "stuff"); #endif In this case, I turn off debugging by commenting out the #define DEBUG. Way 2: /* At the beginning of the file */ #define DEBUG(s) s /* To print debug info */ DEBUG(fprintf(stderr, "stuff")); In this case, I turn off debugging by commenting out the "s" that is the definition of the DEBUG macro. In either case, if I turn off debug, the compiler doesn't even see the debugging fprintf statements. -- Eric Backus ericb AT lsid DOT hp DOT com (206) 335-2495