function pointer handling in Doxygen in C

2019-05-26 08:50发布

问题:

In my code, a vtable containts several function pointer. Doxygen is unable to follow them.

I'd like to force it to recognize the possible paths, to produce a complete Call Graph, since now this part is missing.

example:

typedef Bool(*SPECIAL_FUNC)(KEY key);

typedef struct{
  int a;
  int b;
  SPECIAL_FUNC;
}OBJ;

Bool add(KEY key); //code...
Bool sub(KEY key); //code...

回答1:

While this will likely not affect the call graph in doxygen, you can document the functions as related to the structure, and provide links to them in the documentation for SPECIAL_FUNC. Something like:

typedef Bool(*SPECIAL_FUNC)(KEY key);

/**
 * struct description
 */
typedef struct{
  int a;
  int b;

  /**
   * Function pointer to one of the following:
   * - add()
   * - sub()
   */
  SPECIAL_FUNC;
}OBJ;

/**
 * @relates OBJ
 * add function.
 */
Bool add(KEY key); //code...

/**
 * @relates OBJ
 * sub function.
 */
Bool sub(KEY key); //code...

With this, OBJ will be documented as a class, add and sub will appear as related members of OBJ, and the documentation for SPECIAL_FUNC will contain links to add and sub.



回答2:

I don't think you can do this but one way of faking this could be to have special define just for this and only set it on for Doxygen (with PREDEFINED).

E.g.

#ifdef MY_DOXYGEN_FAKE
  KEY key;
  add(key);
  sub(key);
#endif

In functions where you use that function pointer. Of course it's more work since you have to make sure to only add calls to functions that you really use from that function. But then again you should know how that function pointer is used in any case.