views:

88

answers:

2

Hello,

Are multi-line macros supported(compilable) in gcc version 3.2.4. I am trying to build my source which has multi-line macros on a linux host using above mentioned gcc version. I get compilation error at the macro, which is multiline.

      #define YYCOPY(To, From, Count)       \
      do                    \
     {                  \
       YYSIZE_T yyi;                \
       for (yyi = 0; yyi < (Count); yyi++)  \
         (To)[yyi] = (From)[yyi];       \
     }                  \
      while (0)

If they are not supported, what is the workaround for this, converting the macro to a function or some other compiler option can help?

thank you.

-AD

+1  A: 

Backslashes to continue the macro is standard preprocessor. Check for extra spaces or other invisible characters after your backslash.

ergosys
@ergosys: It has backslashes, a do while loop and some other macros being used in this multi-line macro.
goldenmean
A: 

The ANSI C specification requires compilers to support this -- specifically, the standard says that if a line ends in a backslash immediately before the newline, the preprocessor is to treat that line and the subsequent line as one logical line, as if both the backslash and the newline did not exist. If a preprocessor does not do this, it is not a conforming preprocessor (or more technically, a translator, as the standard calls it).

GCC strives to be as conforming as possible to the ANSI C standard. Yes, it support multiline macros defined with backslashes at the end of lines.

The reason you're getting compiler errors is something else. You're not using the macro properly. Without posting the exact error messages you're receiving and the code which invokes the macro, it's impossible to say what you're doing wrong.

Adam Rosenfield