Call back function, error: typedef 'cb' is initialized (use __typeof__ instead)

Hi,

i want to write a library with a call back function. This is what i have (just whats important).
RemotePedal.h:

#ifndef RemotePedal_h
#define RemotePedal_h

#include "Arduino.h"

extern "C" {
// callback function
    typedef void (*FunctionChangedCallback)(Function *func); // line 24
}

struct Function {
  int functionID;
  String name;
  byte value;
};

class RemotePedal
{
public:
    RemotePedal();
    void attachCB_FunctionChanged(FunctionChangedCallback newFunction); // line 46
private:
    FunctionChangedCallback cbFunction; // line 60
};

#endif

The errors i get:

C:\Program Files\arduino\libraries\RemotePedal/RemotePedal.h:24: error: typedef 'FunctionChangedCallback' is initialized (use typeof instead)
C:\Program Files\arduino\libraries\RemotePedal/RemotePedal.h:24: error: 'Function' was not declared in this scope
C:\Program Files\arduino\libraries\RemotePedal/RemotePedal.h:24: error: 'func' was not declared in this scope
C:\Program Files\arduino\libraries\RemotePedal/RemotePedal.h:46: error: 'FunctionChangedCallback' has not been declared
C:\Program Files\arduino\libraries\RemotePedal/RemotePedal.h:60: error: 'FunctionChangedCallback' does not name a type

I want a call back function which takes a pointer to a "Function" struct as an argument.
I have absolutely no idea what's wrong or how to correct it. Can someone help me?

Thanks in advance, dusti

  1. The struct definition should be inside the "C"
  2. The struct definition must be before the function typedef
  3. The function typedef is incomplete: the keyword "struct" is missing before "Function"

Oliver

Thank you, you solved my problems :slight_smile: