Search code examples
c++macrosc-preprocessorwxwidgetspreprocessor-directive

#define directive with multiple replacements?


I am relatively new to programming, and I am trying to learn to use wxWidgets in C++ (with Visual Studio 2010).

I was looking through the wxWidgets header file "app.h" and I see some #define directives that I can't understand. Here is an example:

#define wxIMPLEMENT_APP(appname)            \
   wxIMPLEMENT_WX_THEME_SUPPORT            \
   wxIMPLEMENT_APP_NO_THEMES(appname)"

I'm used to seeing #define with one "identifier" and one "replacement", so I can't understand if this macro has two "identifiers" (wxIMPLEMENT_APP(appname) and wxIMPLEMENT_WX_THEME_SUPPORT) and one "replacement" (wxIMPLEMENT_APP_NO_THEMES (appname)), or one "identifier" (wxIMPLEMENT_APP(appname)) and two "replacements" (wxIMPLEMENT_WX_THEME_SUPPORT and wxIMPLEMENT_APP_NO_THEMES(appname)).

How am I to understand this macro?

I tried looking online and in text books, searching under "macros", "pre-processor directives", "text replacement macros", "#define directive", and similar, but I could not find any examples with explanation that look like the one I have here.


Solution

  • This preprocessor macro has a single replacement split across multiple lines. The \ at the end of the line lets you write a single "logical" line on multiple lines of text.

    Everything that follows wxIMPLEMENT_APP(appname) will be placed in the text of the program when wxIMPLEMENT_APP(appname) pattern is matched; presumably, both these definitions will be further processed by the preprocessor, because they look like references to other macro definitions.