Hi!
I'm trying to define an array of structures. These structures contain a field that is a pointer to a function. I want to initialize this array at its definition.
When I compile, I got compiler errors for some fields.
Here is my code:
////////// include file /////////////////
struct SCRIPTCOMMAND
{
char * command;
void (* functionpointer)(); // Pointer on the function (no parameters specified, depends on the function)
};
/* Function declarations */
void Message(char * title, char * message);
void SetResistor(unsigned short supplynr, double res);
void SetOutputState(unsigned short supplynr, enum STATE outstate);
void SetVoltage(unsigned short supplynr, double voltage);
void SetCurrent(unsigned short supplynr, double current);
void MeasureVolt(unsigned short supplynr, char * measurename, unsigned int interval_ms, unsigned long nbtimes);
void MeasureCurr(unsigned short supplynr, char * measurename, unsigned int interval_ms, unsigned long nbtimes);
void StartMeasureVolt(unsigned short supplynr, char * measurename, unsigned int interval_ms);
void StartMeasureCurr(unsigned short supplynr, char * measurename, unsigned int interval_ms);
void StopMeasureVolt(unsigned short supplynr);
void StopMeasureCurr(unsigned short supplynr);
void WriteReport(char * measurename, enum MEASUREPART measpart);
void CreateMeasure(char * measurename, enum MeasureType meastype);
/////////// C file ///////////////////////
struct SCRIPTCOMMAND ScriptCMDList[] =
{
"Message", Message,
"SetResistor", SetResistor,
"SetOutputState", SetOutputState,
"SetVoltage", SetVoltage,
"SetCurrent", SetCurrent,
"MeasureVolt", MeasureVolt,
"MeasureCurr", MeasureCurr,
"StartMeasureVolt", StartMeasureVolt,
"StartMeasureCurr", StartMeasureCurr,
"StopMeasureVolt", StopMeasureVolt,
"StopMeasureCurr", StopMeasureCurr,
"WriteReport", WriteReport,
"CreateMeasure", CreateMeasure
};
For the Message, WriteReport and CreateMeasure structures, the compilator doesn't report any error, but for the other structures, it says:
37, 40 Invalid initialization type; found 'pointer to void function(unsigned
short,double)' expected 'pointer to void function'.
Anyone has an idea about this error and why it doesn't report it for each structure?
Thank you very much!
Jean-Michel