Next: , Previous: Customizing Indentation, Up: Top

12 Customizing Macros

Preprocessor macros in C, C++, and Objective C (introduced by #define) have a syntax different from the main language—for example, a macro declaration is not terminated by a semicolon, and if it is more than a line long, line breaks in it must be escaped with backslashes. CC Mode has some commands to manipulate these, see Macro Backslashes.

Normally, the lines in a multi-line macro are indented relative to each other as though they were code. You can suppress this behavior by setting the following user option:

— User Option: c-syntactic-indentation-in-macros

Enable syntactic analysis inside macros, which is the default. If this is nil, all lines inside macro definitions are analyzed as cpp-macro-cont.

Because a macro can expand into anything at all, near where one is invoked CC Mode can only indent and fontify code heuristically. Sometimes it gets it wrong. Usually you should try to design your macros so that they ”look like ordinary code” when you invoke them. However, one situation is so common that CC Mode handles it specially: that is when certain macros needn't (or mustn't) be followed by a ‘;’. You need to configure CC Mode to handle these macros properly, see Macros with ;.