🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #996

empty-else-body warning

#996
From: 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
Technical Details
Message-ID: <9208252130.AA03357@elvis>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!rutgers!att!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!viewlogic.COM!josh

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!rutgers!att!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!viewlogic.COM!josh
From: josh@viewlogic.COM (Josh Marantz)
Newsgroups: gnu.gcc.bug
Subject: empty-else-body warning
Message-ID: <9208252130.AA03357@elvis>
Date: 25 Aug 92 21:30:51 GMT
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 36
Approved: bug-gcc@prep.ai.mit.edu