Doxygen - Document a struct variable but not the struct

19,261

I've found a way to do it. Using proprocessor predefines as @RBE suggested lets you create code only for doxygen which won't compile anyway. So just do this (and make DOXYGEN a predefined macro):

typedef struct Hidden Hidden;

#ifdef DOXYGEN

struct
{
    int foo; ///< Number of particals in the universe.
    int bar; ///< Number of socks in the drawer.
} visible; ///< Nameless struct variable!

#endif

struct Hidden
{
    int foo;
    int bar;
};

Hidden visible;

It's hacky, but it works.

Share:
19,261
Avidan Borisov
Author by

Avidan Borisov

Updated on September 24, 2022

Comments

  • Avidan Borisov
    Avidan Borisov almost 2 years

    Let's say I have this struct type:

    typedef struct Hidden Hidden;
    struct Hidden
    {
        int foo;
        int bar;
    };
    

    and then I have a global variable

    Hidden visible;
    

    Hidden should never be used and visible should be the only declaration of type Hidden. I don't want to generate documentation for Hidden as I don't want it to be used, but instead generate documentation for visible with all the information about it and about its fields.

    The closest thing I've found is that when you document a struct with no tag like:

    struct
    {
        int foo; ///< Number of particals in the universe.
        int bar; ///< Number of socks in the drawer.
    } Baz; ///< Nameless struct variable.
    

    Doxygen will generate

    struct {
       int foo
           Number of particals in the universe. 
       int bar
           Number of socks in the drawer. 
    } Baz
      Nameless struct variable. 
    

    This is the sort of thing I'm trying to achieve, but I can't use nameless structs.

    Is such thing possible?

  • Avidan Borisov
    Avidan Borisov over 11 years
    You misunderstood me. I don't want to just change the name of the structure from HIDDEN to VISIBLE. I want to generate documentation just to a single struct variable instead of documentation for the struct type itself.
  • rbaleksandar
    rbaleksandar over 7 years
    Just a note here - it is strongly recommended not to leave undocumented parts of your API especially if the contents of the undocumented functions/enums/structs/etc. are actually documented.