简体   繁体   English

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

[英]C++ function pointer as parameter in Doxygen

I have a situation where I need to document the bsearch() signature in Doxygen. 我有一种情况需要在Doxygen中记录bsearch()签名。 That signature looks like this: 签名看起来像这样:

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

The problem I am having is how to compose the @param command for the pointer *compare since Doxygen complains " argument 'compare' of command @param is not found in the argument list of bsearch " at everything I throw at it. 我遇到的问题是如何为指针*比较组成@param命令,因为Doxygen抱怨“ 命令@param的参数'比较'在bsearch的参数列表中找不到 ”我投入的所有内容。

This is a standalone implementation, so it is not dependent on a library signature, 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. 将签名更改为pcompare比较使用标准签名的调用者会出现类型问题。

I am open to ANY solution that allows me to document this without alarm from Doxygen. 我对任何解决方案持开放态度,允许我在没有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. 将签名更改为pcompare compare使用标准签名的调用者会出现类型问题。

You should have tried it before giving up. 你应该在放弃之前尝试过。 typedef does not define a new type, it just creates a new identifier for a complex type. typedef没有定义新类型,它只是为复杂类型创建一个新标识符。 The resulting signatures are identical. 结果签名是相同的。

Be careful though, because neither of the forms shown are the correct signature. 但要小心,因为所显示的形式都不是正确的签名。 To declare AC runtime library function like bsearch you need extern "C" . 要像bsearch一样声明AC运行时库函数,你需要extern "C" (and so would the function pointer typedef -- language linkage is part of the function type) (函数指针typedef也是如此 - 语言链接是函数类型的一部分)

All of that said, just setting __cdecl as a predefined macro in your doxygen config would probably be sufficient to allow it to parse all of these variations, including the ones with a complex set of tokens specifying the parameter type. 所有这些都说,只需将__cdecl设置为doxygen配置中的预定义宏可能足以允许它解析所有这些变体,包括具有指定参数类型的复杂令牌集的那些变体。

There's no problem with the typedef. typedef没有问题。
You should use it anyways --- it's clearer to read. 无论如何你都应该使用它 - 它更清晰易读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM