Skip to main content

Posts

Showing posts with the label abi

C++ of the Day #17 - expression? statement?

뉴스그룹에 다음과 같은 질문이 올라왔네요. (( c.l.c.m:The for-init-statement in a for statement )) Question for ( for-init-statement condition opt ; expression opt ) statement C++98 문서에 보면 for expression은 위와 같이 정의되어 있는데 for-init-statement 부분을 보면 optional이 아닙니다. 그렇다면 for (;;) 와 같은 문장은 standard compliant가 아닌가요? 그리고 for-init-statement 부분을 보면 semi-colon이 빠져 있는데 표준 문서의 오류인가요? Answer 먼저 결론부터 말하자면 위의 두 질문의 답은 모두 NO 입니다. 먼저 for-init-statement가 무엇인지는 문서의 뒤쪽에 있는 Annex A Grammar summary 에서 찾을 수 있으며 다음과 같습니다. ((여기서 (opt)는 opt 입니다. code 태그안에서 sub 태그가 안되서... ;-))) for-init-statement: expression-statement simple-declaration expression-statement: expression(opt) ; simple-declaration: decl-specifier-seq(opt) init-declarator-list(opt) ; 보시는 바와 같이 for-init-statement는 expression-statement이거나 simple-declaration인데 둘다 semi-colon으로 끝나고 있습니다. 따라서 for 문을 정의할 때 for-init-statement뒤에 semi-colon이 없었던 것이죠. 그리고 위의 두 경우 모두 semi-colon 앞은 모두 optional임을 알 수 있습니다. 따라서 for-init-statement는 그냥 semi-colon만으로도 standard compliant한 문장...