In C it’s possible to write code before the first case label. Are there any cases for which it is useful to do this or is it just a ‘dead block of code’ ?
E.g.:
switch (...) {
{
int a = 0x2a;
printf("%d\n", a);
}
case 0:
...
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It can be useful to declare variables that have a scope limited to the
switchblock (but be aware that any initialisers for those variables will be skipped):In theory, you could also put code there that you get to using
goto.