I'm working on a project where I'm trying to compile a VxWorks END in C++. I don't think I'll be able to change working in C++, and I definitely can't change VxWorks too much.
This has gone mostly fine, save for one issue. VxWorks requires all drivers to register their methods with in a net_funcs struct, which has the following fields (among others):
#ifdef __cplusplus
extern "C" {
#endif
...
typedef struct net_funcs
{
...
STATUS (*pollSend) (END_OBJ*, M_BLK_ID); /* Driver's polling send func. */
STATUS (*pollRcv) (END_OBJ*, M_BLK_ID); /* Driver's polling recv func. */
/*
* The minimum required arguments for (*formAddress)() are:
* (*formAddress)(M_BLK_ID, M_BLK_ID, M_BLK_ID, BOOL)
*/
M_BLK_ID (*formAddress) (); /* Driver's addr formation func. */
/*
* The minimum required arguments for (*packetDataGet)() are:
* (*packetDataGet)(M_BLK_ID, LL_HDR_INFO *)
*/
STATUS (*packetDataGet) (); /* Driver's addr formation func. */
...
} NET_FUNCS
...
#ifdef __cplusplus
}
#endif
Note the C-style empty parameter list. In C, this means that this field could be a functor that accepts any argument; however, when compiling in C++, it views these arguments as (void), then throws an error when I attempt to instantiate a struct. If I try to change the arguments to ( first arg, ...), passing in the default lib file calls (endEtherAddressForm and endEtherPacketDataGet, both called from lib file as recommended by the software manual) causes an error because those functors require four specific arguments and don't accept variable numbers of args.
I might be able to just hardcode it to the argument list of the default functions and hope for the best, but before I do, is there any way to make this code work with a variable argument list in both C and C++? Or is there something I have to do to make an extern "C" struct work across two files?
UPDATE:
When instantiating the struct, I use the following code:
LOCAL NET_FUNCS MBbufferNetFuncs =
{
...
MyCode::EndPollSend,
MyCode::EndPollRcv,
endEtherAddressForm, /* Library function from endLib.lib; declaration
M_BLK_ID endEtherAddressForm(M_BLK_ID, M_BLK_ID, M_BLK_ID, BOOL)*/
endEtherPacketDataGet /* Library function from endLib.lib; declaration
STATUS endEtherAddressForm(M_BLK_ID, LL_HDR_INFO *)*/
}
The error states that:
"A value of type "M_BLK_ID (*)(M_BLK_ID, M_BLK_ID, M_BLK_ID, BOOL)" cannot be used to initialize an entry of type "M_BLK_ID (*)()""
Normally, one would think that the extern "C" declaration at the start of the net_func declaration would prevent empty parameter list problems, but this is not the case. I do not know if I need to add special code when I declare my personal copy of the struct, but it does not appear to work.