Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ function pointer as parameter in Doxygen

I have a situation where I need to document the bsearch() signature in Doxygen. 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.

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.

I am open to ANY solution that allows me to document this without alarm from Doxygen.

like image 691
Mike Morris - MBXSW Avatar asked Jun 23 '26 18:06

Mike Morris - MBXSW


1 Answers

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.

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. The resulting signatures are identical.

Be careful though, because neither of the forms shown are the correct signature. To declare A C runtime library function like bsearch you need extern "C". (and so would the function pointer typedef -- language linkage is part of the function type)

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.

like image 52
Ben Voigt Avatar answered Jun 25 '26 09:06

Ben Voigt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!