cgcccallbackfunction-pointersnesc

C function pointers error storage class specified for parameter `type name'


I currently have a piece of code that I am working on using function pointers as callbacks. I am having trouble with an error from gcc stating "storage class specified for parameter `type name'" The relevant portion of code is:

error_t addCommand(uint8_t command, void  (*callback)(uint16_t,uint8_t)){

This is actually using the nesC language for TinyOS but it seems to be a C issue. In my research on the issue I have found suggestions mostly stemming from one of two issues:

  1. Something wrong in a header (missing semicolon)
  2. Passing a function pointer with a static or volatile value (i.e. void (*callback)(volatile int, uint8_t)

I have eliminated problem 1 as far as I can tell. Problem 2 is only an issue if uint16_t or uint8_t are static of volatile (I don't have much experience with these types). Any tips/answers on how to solve this issue are greatly appreciated.

Also, if anyone is familiar with nesC the exact code looks more like this:

command error_t CommandEngine.addCommand(uint8_t command,
                                         void  (*callback)(uint16_t,uint8_t)) {

It may be possible that what nesC is adding to the C language causes this error but I don't think this is the case.

EDIT: It was nesC, in a way. It turns out that I'm a moron and was using command as a variable name when command is used by nesC and converted to some block of C code before compilation. Thanks everyone for the idea of converting it to C code as this caused me to realize the issue. I really should have thought of this.


Solution

  • It's generally good to use typedefs for function pointers. It may solve your problem, and will surely be much more readable:

    typedef void (*callback_t)(uint16_t,uint8_t);
    error_t addCommand(uint8_t command, callback_t callback)){
    

    If it won't solve the problem, it will at least narrow it down - you'll see if the problem is with the typedef or the function.

    You should also try to figure out if it's nesC (which I know nothing about) or C. Try to remove nesC specific parts and compile with gcc, and see what happens.