#include 에서 매크로 확장시 C 표준

체스맨의 이미지

다음과 같은 경우는 표준에서 정의하는 것으로 판단이 됩니다.

#define MYHEADER "myheader.h"
#include MYHEADER

그렇다면 다음과 같은 경우는 허용될까요? 실제로 gcc 와 msvc 6.0 모두에서 컴파일 됩니다.

#define BASEPATH <base
#include BASEPATH/myheader.h>

다음과 같은 경우는 gcc에서는 되고 msvc 6.0 에서는 안됩니다.

#define BASEPATH <base
#define MYHEADER myheader.h>
#include BASEPATH/MYHEADER

어디까지 표준이 허용하는 것으로 보면 될까요?

cppig1995의 이미지

ISO/IEC 9899:1999 wrote:
6.10.2 Source file inclusion
4 A preprocessing directive ofthe form #include pp-tokens new-line (that does not match one of the twoprevious forms) is permitted. The preprocessing tokens after include in the directive are processed just as in normal text. (Each identifier currently defined as a macro name is replaced by its replacement list of preprocessing tokens.) Thedirective resulting after all replacements shall match one of the two previous forms.143) The method by which a sequence of preprocessing tokens between a < and a > preprocessing token pair or a pair of " characters is combined into a single header name preprocessing token is implementation-defined.

표준에 정해진 제한은 없고(일반적인 전처리의 제약과 같고), VC++ 6.0 전처리기의 한계로 보입니다.

> What is the difference between software and hard water?
} Bugs drown in hard water, but live forever in software.

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.