c - Switch statement code without a label -


this question has answer here:

how come ansi c allows extraneous code before case labels within switch statement?

#include <stdio.h>  int main(void) {   const int foo = 1;    switch (foo) {       printf("wut\n"); /* no label, doesn't output */     case 1:       printf("1\n");       break;     default:       printf("other\n");       break;   }    return 0; } 

compiled with

$ gcc -pedantic -wall -werror -wextra -ansi test.c 

it compiles without warnings , executes fine - sans "wut".

it allowed put statements in switch without label. standard says that:

c11: 6.8.4.2 switch statement (p7):

in artificial program fragment

switch (expr) {     int = 4;     f(i);     case 0:         = 17;         /* falls through default code */     default:          printf("%d\n", i); } 

the object identifier i exists automatic storage duration (within block) never initialized, , if controlling expression has nonzero value, call printf function access indeterminate value. similarly, the call function f cannot reached.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -