#define macros for "static" 用于不同的上下文

#define macros for "static" for different contexts

我想在不同的上下文中区分“static”关键字。这样做可能有什么缺点

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

从技术和语义的角度。

如果您使用这种方法,那么如果有人不知道这意味着什么,就会真的迷失方向。 如果你真的想使用宏(阅读:https://google.github.io/styleguide/cppguide.html#Preprocessor_Macros),我建议你使用 UPPER_CASE:

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

如果你只使用大写字母,那么看到你的代码的人就会知道,这是宏。 Google C++ 风格指南 (https://google.github.io/styleguide/cppguide.html#Macro_Names) 鼓励这种风格。

从技术角度来看,我认为没有区别,因为 C++ 编译器看不出区别,因为预处理器用 static 替换了 commonintern