#为""定义宏;静态";针对不同的上下文

#define macros for "static" for different contexts

本文关键字:quot 上下文 定义 静态      更新时间:2023-10-16

我想区分"静态";关键字。可能存在哪些缺点

#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

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

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