null if statements
Steve Summit
scs at adam.pika.mit.edu
Sat Jul 15 10:27:20 AEST 1989
in article <713 at srhqla.SR.COM>, tcm at srhqla.SR.COM (Tim Meighan) writes:
> 1. There is rarely, if ever, a case when it would be reasonable for a
> program to contain an if() statement that, when evaluated as true,
> does absolutely nothing. (In other words, simply fall through to
> the code to be executed when the if() is false.)
Just yesterday I discovered, to my considerable astonishment, a
good use for an if statement which always evaluates as false, and
does nothing:
if(0)
;
#ifdef onething
else if(Streq(command, "agitate"))
agitate();
#endif
#ifdef anotherthing
else if(Streq(command, "blend"))
blend();
#endif
#ifdef yetanotherthing
else if(Streq(command, "churn"))
churn();
#endif
else fprintf(stderr, "unknown command \"%s\"\n", command);
The first, empty if keeps the code syntactically correct
regardless of which of the "real" branches are #ifdeffed out.
Steve Summit
scs at adam.pika.mit.edu
More information about the Comp.lang.c
mailing list