On 7/2/20 12:03 PM, Rodney Radford via TriEmbed wrote:
Technically, you are not supposed to declare a new variable inside a case without using braces to create a new stack frame.

Most compilers won't allow it.  GCC doesn't:

Given this code:
int main(void) {
  int q = 1;
  switch(q) {
    case 0:
      int a = 5;
      break;

    case 1:
      q = 0;
      break;
  }
  return 0;
}

GCC emits this error:
bad_case.cpp: In function ‘int main()’:
bad_case.cpp:8:8: error: jump to case label [-fpermissive]
   case 1:
        ^
bad_case.cpp:5:8: note:   crosses initialization of ‘int a’
    int a = 5;
        ^

MSVC does something similar.

-B

_______________________________________________
Triangle, NC Embedded Computing mailing list

To post message: [email protected]
List info: http://mail.triembed.org/mailman/listinfo/triembed_triembed.org
TriEmbed web site: http://TriEmbed.org
To unsubscribe, click link and send a blank message: 
mailto:[email protected]?subject=unsubscribe

Reply via email to