gcc 매크로의 가변 인자 사용하기

Posted at 2008/04/06 14:57 // in Programming // by Daniel

춮처 : http://developer.apple.com/documentation/DeveloperTools/gcc-4.0.1/cpp/Variadic-Macros.html

#define DEBUG
#ifdef DEBUG
#define DBG(...)    fprintf(stderr, __VA_ARGS__)
#else
#define DBG(...)    do{}while(0)
#endif

이런식으로 사용합니다.

C99 표준이라고 돼 있고 gcc 4.0부터는 확실히 이렇게 쓰는 것 같습니다.

gcc가 이전부터 사용하는 것과 맞추려면(C99표준은 아닌 것 같습니다)

#define eprintf(format, args...) fprintf (stderr, format , ##args)

이런식으로 쓰라는군요

## args 전에는 콤마(,)와 빈칸이 꼭 있어야 한답니다.

크리에이티브 커먼즈 라이센스
Creative Commons License

이 글에는 트랙백을 보낼 수 없습니다