c++c++98vxworks

Variadic Function Pointer definition is unclear for VxWorks spyLib


I'm using VxWorks 6.9 and am trying to use some spyLib.h functions but I'm having issues finding what signature to expect given that the type is variadic.

in vxTypesOld.h I find my type: typedef int (*FUNCPTR) (...);

and in spyLib.h i have my function call : extern void spyReportCommon (FUNCPTR printRtn);

But what function parameters are expected for printRtn ? I guess a c-style string is one but I don't know if each line of the table is a string or if its an array of strings, or even one large string.

I can't start writing the function to parse data from the outputted data until I know in what form that data is passed into the function.

All I know for certain is that it returns an int (e.g. int parsePrint( ???? );)

Here is my attempt at reporting:

#include <vxworks.h>
#include <spyLib.h>
#include <usrLib.h>

int ParseSpy(const char * spyOutput); // this is a guess

void Startup()
{
    //startup logic

    // the compiler said and int param is expected but the .h had void
    spyLibInit(1); 

    spyCommon(1,50, (FUNCPTR) &ParseSpy);
}

int ParseSpy(const char * spyOutput){} // this is a guess

I'm getting an unexpected compiler error: 'spyCommon' was not declared in scope but as you can see spyLib.h was included so I'm a bit confused by this.


Solution

  • That looks like a bad design. The print function cannot print if it does not know what the parameters are. At least one parameter is needed to specify what the rest of the parameters are.

    Looking at the source and searching for "printRtn" I see that all calls to the print function are expecting a printf like function where the first parameter is a format string. Your function should better be written as

    int ParseSpy(const char * spyOutput, ...);
    

    Regarding the missing spyCommon you could try to let VxWorks write the preprocessor output to a file to check what the compiler sees. Maybe you are getting the wrong spylib.h file or something it that file is hidden by #if.