다음은 this answer에서 직접 복사 한 switch
문 예입니다.
#include <stdio.h>
int main(){
int expr = 1;
switch (expr)
{
int i = 4;
f(i);
case 0:
i = 17;
/* falls through into default code */
default:
printf("%d\n", i);
}
}
여기는 goto
으로 작성된 동일한 코드 샘플입니다. expr
가 1
에 초기화 될 때
#include <stdio.h>
int main(){
int expr = 1;
if (expr == 0) goto label0;
else goto label1;
int i = 4;
f(i);
label0:
i = 17;
label1:
printf("%d\n", i);
}
가, 두 경우 모두, 그 관찰, 초기화 문
int i = 4
그래서
i
가 초기화되지 않습니다,을 실행하지
입니다. 그러나 질문의 인용문에 언급 된 것처럼 i
이 정의됩니다. 스위치를 if(1 == x)
goto LABEL_A;
else if(2 == x)
goto LABEL_B;
else if(10 == x)
goto LABEL_C;
else
goto LABEL_D;
LABEL_A:
/* Do A */;
goto BREAK;
LABEL_B:
/* Do B */;
goto BREAK;
LABEL_C:
/* Do C */;
goto BREAK;
LABEL_D:
/* Do D */;
goto BREAK;
BREAK:
: 스위치 없음
특히 당신이 링크에서 당신이 게시 어려움을 겪고? 귀하가 강조한 진술과 함께 수락 된 대답은 충분히 명확하게 보입니다. –
사용 방법에 대한 설명을 찾으십니까? 내부적으로 구현되는 방법에 대한 설명은? goto 문과의 유사성에 대한 철학적 인 반박은? – ruakh
이 특정 링크가 해당 문제에 어떻게 대답하는지 이해할 수 없습니다. –