Chris Nelson
Chris Nelson

Reputation: 3707

How can I keep doxygen from documenting #defines in a C file?

I have #define values in headers that I certainly want Doxygen to document but I have others in C files that I treat as static constants and I don't want Doxygen to document them. Something as simple and stupid as

#define NUMBER_OF(a) (sizeof((a))/sizeof((a)[0]))
#define MSTR(e) #e

How can I keep Doxygen from putting those #defines in the documentation it creates? I've tried marking it with @internal but that didn't seem to help.

A somewhat-related question on Doxygen and #define, how can I get:

#define SOME_CONSTANT 1234 /**< An explanation */

to put "SOME_CONSTANT" and "An explanation" but not "1234" in the output?

Upvotes: 10

Views: 15971

Answers (7)

ericbn
ericbn

Reputation: 10998

You only want to document what is declared in the .h files. I'm assuming you declare all static functions and variables as static in your .c files. All the remaining are declared in .h corresponding files also. These are your "public" members.

What I like to do in this case, and I believe doxygen was more designed to be used this way is:

This will index only what is contained in your .h files. You can still add the directory containing your .c files to INPUT at your Doxyfile, and they will be scanned for additional documentation for your "public" members...

Upvotes: 2

dominik liebaug
dominik liebaug

Reputation: 1

Sometimes you may have a define which you want to document, but want doxygen to treat it differently (or even ignore it completely to avoid parsing errors). For this you can define the #define in doxygen differently than in your sourcecode.

Example: Some compilers allow variable linkage to specific segments, i.e.:

const int myvar @ "segment_of_myvar_in_memory"=123;

=> doxygen would parse the "segment_of_myvar_in_memory" part as variable name which is not desired. We could use a define for it:

#define __link_to_segment(name) @ name
const int myvar __link_to_segment("segment_of_myvar_in_memory")=123;

If Preprocessing is active, Doxygen interprets our variable now as a function because of the function-like define using brackets.. But if we redefine our define within the Doxyfile, behaviour changes:

PREDEFINED = __link_to_segment(a)=

now the variable is parsed correctly as variable - also all types or keywords in front are correctly shown as keywords.

A nice side effekt: In case you use 2 different IDEs with your code (one IDE for compiling&debugging, one for editing), you will also discover that some IDEs (i.e. Eclipse) have problems parsing variables with @"segment name". Using the approach above, you can redefine the __link_to_segment(name) there too:

#define __link_to_segment(name)

i.e. Eclipse will then show and parse the variable correctly, whereas the "compiling&debugging" IDE can still link the variable to its segment name.

Upvotes: 0

Be Kind To New Users
Be Kind To New Users

Reputation: 10073

I solved this problem by moving my documentation from the .c file to the .h file. Then run doxygen only on the .h file.

Then the items that I want to document (the 'public' items) are intrinsically what doxygen picks up.

Because I have been previously careful to put 'public' items in the .h file and 'private' items in the .c file this works very well.

This technique came to mind when I noticed that doxygen was pulling in the includes. It struck me that if I were to also move the subset of includes that the calling module would need to use my module, then that list would be documented as well.

This technique has an additional benefit: I can put the documentation in one terminal window and the source in a different terminal window while updating the documentation.

Upvotes: 0

bszente
bszente

Reputation: 121

There is no need to use the \cond and \endcond commands. You can hide the initializer by simply using the \hideinitializer command:

#define SOME_CONSTANT 1234 /**< An explanation @hideinitializer */

Regarding the first question, you may set HIDE_UNDOC_MEMBERS = YES and only the macros having a Doxygen documentation block will be shown in the output.

Upvotes: 12

emp
emp

Reputation: 51

You can set MAX_INITIALIZER_LINES = 0 in your doxyfile to hide the values of your defines.

Upvotes: 5

Ben Hocking
Ben Hocking

Reputation: 8102

It will no doubt still seem noisy and unnatural, but to address your other question, try:

/** An explanation */
#define SOME_CONSTANT /** @cond */ 1234 /** @endcond */

Upvotes: 1

mouviciel
mouviciel

Reputation: 67889

You can exclude any part of code from Doxygen parsing with \cond ... \endcond tags.

edit: Some related questions:

Upvotes: 3

Related Questions