[comp.lang.c++] if

guido@cwi.nl (Guido van Rossum) (03/03/88)

I've noticed that cfront eliminates some forms of unreachable code: if
the condition of an if statement is a constant expression, it only
output the code for the branch that would be taken.

This is very useful for debugging: no more clumsy

	#ifdef DEBUG
		printf("foobar called\n");
	#endif

but simply

		if (debug) printf("it's foobar time again!\n");

which you can leave in your code without fear for inefficiencies (simply
put "const debug = 0;" in the program when it's debugged and the
debugging code won't leave a trace).

HOWEVER, the C++ reference manual doesn't explicitly mention this (in
fact it promotes #ifdef for conditional compilation).  So, should I be
afraid that this is an accidental feature of cfront, which may go away
in another version, and won't necessarily be implemented by other C++
compilers (G++?)???  Or can I depend on this for programs with expected
lifetimes of more than a year?
--
Guido van Rossum, Centre for Mathematics and Computer Science (CWI), Amsterdam
guido@cwi.nl or mcvax!guido or (from ARPAnet) guido%cwi.nl@uunet.uu.net

jima@hplsla.HP.COM ( Jim Adcock) (03/29/88)

While historically, the AT&T compiler has been the defacto
definition of the C++ language, there are becoming independent
C++ compilers from a variety of sources.

One would hope that the compilers that are coming out are
"modern" enough to handle "obvious" cases of dead code optimization,
but I see no way to gaurantee that assumption.