tags:

views:

33

answers:

1

I prefer to define certain macros inside of my struct definitions, so it's easy to see possible values for a given member. For example:

typedef struct foo_t {
    uint16_t flags;
        #define FOO_FLAG_BELL       0x0001
        #define FOO_FLAG_BOOK       0x0002
        #define FOO_FLAG_CANDLE     0x0004
        #define FOO_FLAG_LANTERN    0x0008
}

Doxygen wants to list those macros at the top, with all of the other macros. I've make use of the grouping tags (//@{ and //@}) to group these macros together, and named the group with foo_t.flags, but I'd like to find a way to more-closely associate the values with the structure. Should I use \link and \endlink to somehow link to that group name?

+4  A: 

Use enums.

typedef struct foo_t {
  enum flag_define { 
    FOO_FLAG_BELL    =  0x0001,    /**< The flag for the bell or whatever. */
    FOO_FLAG_BOOK    =  0x0002,
    FOO_FLAG_CANDLE  =  0x0004,
    FOO_FLAG_LANTERN =  0x0008,
  } flags:16;                      /**< My flag thing */
}  foo_t;
tristopia
+1: that could work for some situations. In other cases, I need to define a name as a combination of other names, or two names to be the same value, or the enum values are for an 8-bit field in a frame header. Best answer so far though...
tomlogic
you can have enums with the same value, there's no restriction there. And you can by combining with the preprocessor concatenation operator ##. You can also reuse a value to define another: `enum { val1=1, val2=2, combined=val1|val2, };` should work.
tristopia