uii*_*iii 3 documentation typedef doxygen conditional-compilation
我正在开发一个跨平台的库.有些代码是依赖于平台的,因此我必须使用它们来#ifdef检查平台类型.我将一个类分成两个类,每个类都用于自己的平台.这些类有不同的名称,但最后我需要typedef根据平台将这些类转换为一种类型:
#ifdef UNIX
/** some comment */
typedef Key_unix Key;
#elif WIN
/** another comment */
typedef Key_win Key;
#endif
Run Code Online (Sandbox Code Playgroud)
生成的文档仅显示typedef包含两个注释的第一个文档.如何将两者展示typedef在一起,每个都有自己的评论?
小智 8
根据我的理解,doxygen有自己的预处理器来评估#ifdefs.您可以使用该PREDEFINED选项定义宏.
# The PREDEFINED tag can be used to specify one or more macro names that
# are defined before the preprocessor is started (similar to the -D option of
# gcc). The argument of the tag is a list of macros of the form: name
# or name=definition (no spaces). If the definition and the = are
# omitted =1 is assumed. To prevent a macro definition from being
# undefined via #undef or recursively expanded use the := operator
# instead of the = operator.
Run Code Online (Sandbox Code Playgroud)
但是,既然你已经设置了#elif,那么PREDEFINED = UNIX WIN它只会评估第一个#ifdef.作为替代方案,您可以尝试:
#ifdef UNIX
/** some comment */
typedef Key_unix Key;
#endif
#ifdef WIN
/** another comment */
typedef Key_win Key;
#endif
Run Code Online (Sandbox Code Playgroud)
在编译代码时,您不太可能同时定义UNIX和WIN.