Compiler error
hello
i've got problem think related scope issue. i'm blank , have tried lot of different stuff rid of compiler error. here code of simple state machine:
this results in compiler error:
statemachine:1: error: variable or field 'sm_update' declared void
statemachine:1: error: 'smtype' not declared in scope
statemachine:1: error: 'p' not declared in scope
the compiler complaining on void sm_update(smtype *p)
function.
hope can give me clue what's wrong in code.
cheers
i've got problem think related scope issue. i'm blank , have tried lot of different stuff rid of compiler error. here code of simple state machine:
code: [select]
/* statemachine */
enum {ms_idle,ms_start,ms_stop};
typedef struct{
int state,oldstate;
int time;
}smtype;
void sm_update(smtype *p);
smtype mission;
void setup(){
serial.begin(9600);
mission.state=ms_idle;
}
void loop(){
sm_update(&mission);
switch(mission.state){
case ms_idle:
serial.print("state idle");
delay(5000);
mission.state=ms_start;
break;
case ms_start:
serial.print("state start");
delay(5000);
mission.state=ms_stop;
break;
case ms_stop:
serial.print("state stop");
delay(5000);
break;
}
}
void sm_update(smtype *p){
if (p->state!=p->oldstate){
p->time=0;
p->oldstate=p->state;
}
else {
p->time++;
}
} this results in compiler error:
statemachine:1: error: variable or field 'sm_update' declared void
statemachine:1: error: 'smtype' not declared in scope
statemachine:1: error: 'p' not declared in scope
the compiler complaining on void sm_update(smtype *p)
function.
hope can give me clue what's wrong in code.
cheers
i think you're right scope problem. if add scope resolution operator 2 function headers, code compiles fine:
i don't know enough arduino ide explain why, though. maybe free function gets wrapped in namespace?
code: [select]
void sm_update(::smtype *p)i don't know enough arduino ide explain why, though. maybe free function gets wrapped in namespace?
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Compiler error
arduino
Comments
Post a Comment