Using Macros

Christopher R Volpe volpe at underdog.crd.ge.com
Wed Aug 8 03:55:36 AEST 1990


In article <14339 at shlump.nac.dec.com>, farrell at onedge.enet.dec.com
(Bernard Farrell) writes:
|>
|>In article <362.26be9dcc at astro.pc.ab.com>, yoke at astro.pc.ab.com
(Michael Yoke) writes...
|>>But, if I define the macro like this
|>> 
|>>      #define A_MACRO { stmt1; stmt2; }
|>> 
|>>then the semi-colon at the end of the macro reference screws things up.
|>> 
|>The presence of an empty statement after
|>the closing brace should not cause any problems, though I seem to recall
|>certain C compilers don't like it being placed here.

Can someone with a copy of the Standard tell us if a semicolon is 
allowed? K&R2 is vague on the issue ("there is no semicolon after the
closing brace". Does this mean "no semicolon necessary" or 
"no semicolon allowed"?). 

Anyway, if the compiler is coughing on it, try the following:

         #define A_MACRO {stmt1;stmt2;} 0  /* yes, trailing zero */

Expanding "A_MACRO;" yields the dummy statement "0;" which is
basically a value that goes unused, much like ignoring the return value
of a function, except that no function gets called and no code (should)
be generated. (Sun C and GNU C accept "0;" as a statement and generate
no code.) 
                                  



More information about the Comp.lang.c mailing list