Before you mark as duplicate, I have read the post here and cannot figure out how this relates to my code.
I am getting some compilation errors:
controller.cc: In member function ‘void Controller::start()’:
controller.cc:50:9: error: jump to case label [-fpermissive]
controller.cc:44:17: error: crosses initialization of ‘uint32_t c’
Here is my code:
void Controller::start(){
int curPosX = view->getWidth() / 2;
int curPosY = view->getHeight() / 2;
uint32_t color = 0xFFFFFF;
DeviceHandler player = DeviceHandler("/dev/input/js0", false);
player.flush();
while(1){
button_event_t press;
bool ret = player.poll(&press);
if(ret && press.type == PRESS){
switch(press.name){
case DPAD_UP:
curPosY += 1;
break;
case DPAD_DOWN:
curPosY -= 1;
break;
case DPAD_RIGHT:
curPosX += 1;
break;
case DPAD_LEFT:
curPosX -= 1;
break;
case BUTTON_LB:
view->clear();
break;
case BUTTON_RB:
uint32_t c = rand() & 0xff;
c |= (rand() & 0xff) << 8;
c |= (rand() & 0xff) << 16;
c |= (rand() & 0xff) << 24;
color = c;
break;
case BUTTON_A:
color = 0x000000;
break;
}
}
//color = 0x000000;
view->drawPixel(curPosY,curPosX, color);
usleep(500);
}
}
Now the problem lies in case BUTTON_RB:
and case BUTTON_A:
statements. When I remove case BUTTON_A:
it compiles fine. The post I linked above has stated that this error only occurs when you use an initialized variable in another case statement other than where it was defined. This is not the case here.
The only variable I define is uint32_t c
which I do not use elsewhere. I have tried turning these statements into explicit blocks as suggested in other post and it compiles but does not seem to catch correctly.