Search code examples
c++macroskeywordsemanticspreprocessor

#define macros for "static" for different contexts


I want to distinguish "static" keyword in the different contexts. What are possible drawbacks of doing

#define common static // class member
#define intern static // linkage

from technical and semantic perspectives.


Solution

  • If you use this approach, that if somebody, who has no idea what this means, will be really disoriented. If you really want to use macros (Read this: https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros), I'd advise you to use UPPER_CASE:

    #define COMMON static // class member
    #define INTERN static // linkage
    

    If you use only caps, a person, that sees your code will know, that this are macros. This style is encouraged by the Google C++ style guide (https://google.github.io/styleguide/cppguide.html#Macro_Names).

    From a technical perspective I would say there's no difference, as the C++ compiler won't see a difference, as the Preprocessor replaces your common and intern with static.