🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Josh Marantz Tue, 25 Aug 1992 21:30
empty-else-body warning
#996
Author: Josh Marantz
Date: Tue, 25 Aug 1992 21:30
36 lines
1687 bytes
A number of people suggested that I do something like:

	#define MAC()	if (whatever) something ; else {}

in place of what I had, which is this:

	#define MAC()	if (whatever) something ; else

The problem is that I want to allow users of the macro to
use them in the following context:

    if (some_condition)
        MAC ();
    else
        do_something_else;

which won't work if I end the else clause with {}.  I need to let the
macro caller supply the ";" to make the macro call look like a
statement.

Skip Montanaro suggested I do this:

    #define TEST(a) do { if (a) printf("a") ; } while (0)

That would work.  In fact, I already use this form to make macros out
of a blocks of statements that are *not* in an if statement, but I'm a
little concerned that some compilers (not gcc, I assume, but I have to
use others as well) will fail to optimize this ersatz loop away, so I
didn't put one in except where necessary.  It doesn't appear to be
necessary to put in the do{...}while(0) syntax when there's a
conditional, so I'd prefer not to do it.  Unfortunately for me, gcc
2.2.2 warns about this (though not 1.39), so I'm hoping I can lobby
for the ability to disable this warning message.  What are my chances?

Thanks,
-Josh
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads