Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ensure documentation shows alternate #ifdef'd code

I'm developing a cross-platform library. Some pieces of code are platform dependent, so I have to separate them using #ifdef, checking the platform type. I split one class into two classes, each for their own platform. These classes have different names, but finally I need to typedef these classes to one type according to the platform:

#ifdef UNIX
/** some comment */
typedef Key_unix Key;
#elif WIN
/** another comment */
typedef Key_win Key;
#endif

The generated documentation is showing only the first typedef with both comments. How can I show both typedefs together, each with its own comment?

like image 367
uiii Avatar asked Aug 31 '25 18:08

uiii


1 Answers

From what I understand, doxygen has its own preprocessor that will evaluate #ifdefs. You can define macros using the PREDEFINED option.

# 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.

However, since you've got an #elif even if you set PREDEFINED = UNIX WIN it'll only evaluate the first #ifdef. As an alternative you could always try:

#ifdef UNIX
/** some comment */
typedef Key_unix Key;
#endif
#ifdef WIN
/** another comment */
typedef Key_win Key;
#endif

It's unlikely that you'll have both UNIX and WIN defined when you compile the code.

like image 135
AlmostSure Avatar answered Sep 02 '25 21:09

AlmostSure