Why does C++ require breaks in switch statements? - Stack Overflow

PHOTO EMBED

Tue Nov 15 2022 00:57:55 GMT+0000 (Coordinated Universal Time)

Saved by @leawoliu #cpp

int i=1;
switch (i) {
case 1:
        i=5;
        break;
default:
        i=6;
}
return 0;



0x100000eeb:  movl   $0x1, -0x8(%rbp) ;int i=1;
0x100000ef2:  xorl   %eax, %eax
0x100000ef4:  movb   %al, %cl
0x100000ef6:  testb  %cl, %cl         ;switch(i)
0x100000ef8:  jne    0x100000f0f      ;i is not 1 go to default:
0x100000efe:  jmp    0x100000f03      ;i is 1 go to case 1:
0x100000f03:  movl   $0x5, -0x8(%rbp) ;case 1: i=5;
0x100000f0a:  jmp    0x100000f16      ;break;
0x100000f0f:  movl   $0x6, -0x8(%rbp) ;default: i=6;
0x100000f16:  movl   $0x0, %eax       ;first instruction after switch-case
content_copyCOPY

https://stackoverflow.com/questions/29915854/why-does-c-require-breaks-in-switch-statements