Using Macros

Michael Yoke yoke at astro.pc.ab.com
Wed Aug 8 01:54:04 AEST 1990


Could some of you give me your opinion on the best way to handle multiple 
statement macros.  For example, let's say that I have a macro that looks
like the following:

         #define A_MACRO       (stmt1)

and the code that uses the macro looks like this:

        if (expr)
           A_MACRO;

Now let's say that the macro has to be modified such that it requires
more than one statement.  If I define the macro like this,

      #define A_MACRO (stmt1; stmt2;)

then all the code using the macro must be changed to
  
      if (expr) {
         A_MACRO;
      }

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.

I guess what I'm really looking for is a good set of guidelines for using 
macros.

                            Thanks in advance,

                            Mike



More information about the Comp.lang.c mailing list