I am writing code for the project today and find that I want to use the switch statement, which is a bit confusing.
The general switch is like this.
Swith (constant)
{
Case 1: Statement; break;
Case 2: Statement; break;
...
Default: break;
}
Each case is a tag, and so is the Assembly layer.
... Since I have a little understanding of assembly, I have become more "think more.
I want to use switch nesting in the project, and their case will have overlapping areas. Is it feasible? I am sleepy. If the label of the case is the same, it is the same label in the Assembly layer. Will GCC not let it go? (Do not know if I have clearly stated it ...)
For example, can you directly determine whether the following code is 0 warning or 0 wrongs?
#include <stdio.h>#define A (0)#define B (1)int main(){int tmp = 0;while(!scanf("%d",&tmp)){getchar();printf("error! input again!\n");}switch(tmp){case A:switch(tmp){case A: printf("A A\n");break;case B: printf("A B\n");break;}break;case B:switch(tmp){case A: printf("B A\n");break;case B: printf("B B\n");break;}break;default:;}return 0;}
The case of the two-layer switches that I intentionally set is the same. It is confusing whether the switch jumps at the Assembly level to see ambiguity, so that it cannot be compiled.
The truth is no, and there will be no ambiguity. The case label here is given in the form of the function offset, so there will be no ambiguity.
For example, here, the switch function is the main function, and the label gives the index in the form of <main + Offset>.
About the switch statement "think too much"