02 |
#include <STDIO.H> |
03 |
#define EMPTY |
04 |
|
05 |
#define CHECK1(x, ...) if (!(x)) { printf(__VA_ARGS__); } |
06 |
#define CHECK2(x, ...) if ((x)) { printf(__VA_ARGS__); } |
07 |
#define CHECK3(...) { printf(__VA_ARGS__); } |
08 |
#define MACRO(s, ...) printf(s, __VA_ARGS__) |
09 |
|
10 |
int main() { |
11 |
CHECK1(0, "here %s %s %s" , "are" , "some" , "varargs1(1)\n" ); |
12 |
CHECK1(1, "here %s %s %s" , "are" , "some" , "varargs1(2)\n" ); // won't print |
13 |
|
14 |
CHECK2(0, "here %s %s %s" , "are" , "some" , "varargs2(3)\n" ); // won't print |
15 |
CHECK2(1, "here %s %s %s" , "are" , "some" , "varargs2(4)\n" ); |
16 |
|
17 |
// always invokes printf in the macro |
18 |
CHECK3( "here %s %s %s" , "are" , "some" , "varargs3(5)\n" ); |
19 |
|
20 |
MACRO( "hello, world\n" ); |
21 |
// MACRO("error\n", EMPTY); would cause C2059 |
22 |
} |
'소프트웨어 > C/VC++' 카테고리의 다른 글
윈속 멀티스레드 서버 (Winsock) (0) | 2012.05.14 |
---|---|
#pragma - once, pack, warning, comment, link (0) | 2012.05.14 |
CString ->int -> CString (0) | 2010.07.21 |
CTreeCtrl 검색하기 (0) | 2009.11.11 |
Visual Basic 에서 C/C++로 만든 DLL 불러쓰기 (0) | 2009.06.16 |