error: redeclaration of

Hi I'm receiving the following error in my code:

/tmp/266590520/build/sketch/Radio.cpp: In member function 'void RadioContainer::radio_receive()':

/tmp/266590520/build/sketch/Radio.cpp:134:14: error: redeclaration of 'byte confirmation'

byte confirmation = BicycleComputer::status;

^

/tmp/266590520/build/sketch/Radio.cpp:129:14: note: 'byte confirmation' previously declared here

byte confirmation = BicycleComputer::status;

^

exit status 1

Here is the relevant code:

    switch (radio_data_rx[0])
    {
      case MSGID_PING:
        byte confirmation = BicycleComputer::status;
        radio.writeAckPayload(1, &confirmation, RADIO_COMMAND_BYTES);
        break;
        
      case MSGID_MSG:
        byte confirmation = BicycleComputer::status;
        radio.writeAckPayload(1, &confirmation, RADIO_COMMAND_BYTES);
        break;
        
      case MSGID_SPD_DST:
        alloc_spd_dst_data_tx();
        radio.writeAckPayload(1, &radio_data_tx, SIZEOF_SPD_DST_DATA);
        break;
    }

From what I know each switch statement branch has its own scope, in this case it's making it so that the scope is shared. Please any clarification on this topic would be greatly welcomed.

ningaman151:
From what I know each switch statement branch has its own scope

They don't. But you can make them have their own scope by wrapping the code of each case in braces.

ningaman151:
From what I know each switch statement branch has its own scope, in this case it's making it so that the scope is shared. Please any clarification on this topic would be greatly welcomed.

Depends, and this is a confusing part for some beginners. Normally, you would not need to worry about scope in a case statement, except for declaring and intilazing a variable. This is why many programmers, including myself just simply wrap the case it brackets.

pert:
They don't. But you can make them have their own scope by wrapping the code of each case in braces.

Except for when you attempt to declare and initialize a variable, then you must use the braces.