C++ 函数指针作为 Doxygen 中的参数

C++ function pointer as parameter in Doxygen

我有一种情况需要在 Doxygen 中记录 bsearch() 签名。该签名看起来像这样:

void * __cdecl bsearch (
    const void *key,
    const void *base,
    size_t num,
    size_t width,
    int(__cdecl *compare)(const void *, const void *)
    )

我遇到的问题是如何为指针 *compare 编写 @param 命令,因为 Doxygen 抱怨“argument 'compare' of command @param is not found in the argument list of bsearch" 在我扔给它的所有东西上。

这是一个独立的实现,因此它不依赖于库签名,但是我在想如果我这样做了:

typedef int(__cdecl *pcompare)(const void *, const void *);

将签名更改为 pcompare 比较使用标准签名的调用方会出现类型问题。

我对任何允许我在没有 Doxygen 警告的情况下记录这一点的解决方案持开放态度。

however I am thinking if I did:

typedef int(__cdecl *pcompare)(const void *, const void *);

changing the signature to pcompare compare that callers using the standard signature would have a type problem.

你应该在放弃之前尝试过。 typedef 没有定义新类型,它只是为复杂类型创建了一个新标识符。生成的签名是相同的。

不过要小心,因为显示的两种形式都不是正确的签名。要声明像 bsearch 这样的 C 运行时库函数,您需要 extern "C"。 (函数指针 typedef 也是如此——语言链接是函数类型的一部分)

综上所述,只需在您的 doxygen 配置中将 __cdecl 设置为预定义的宏可能就足以让它解析所有这些变体,包括那些具有一组复杂的标记的变体,这些标记指定参数类型。

typedef没有问题。
无论如何你都应该使用它——它更容易阅读。