1 /*============================================================================= 2 Boost.Wave: A Standard compliant C++ preprocessor library 3 http://www.boost.org/ 4 5 Copyright (c) 2001-2012 Hartmut Kaiser. Distributed under the Boost 6 Software License, Version 1.0. (See accompanying file 7 LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 =============================================================================*/ 9 10 // This sample is taken from the C++ standard 16.3.5.6 [cpp.scope] and was 11 // slightly modified (removed the '#include' directive) 12 13 #define str(s) # s 14 #define xstr(s) str(s) 15 #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \ 16 x ## s, x ## t) 17 #define INCFILE(n) vers ## n /* from previous #include example */ 18 #define glue(a, b) a ## b 19 #define xglue(a, b) glue(a, b) 20 #define HIGHLOW "hello" 21 #define LOW LOW ", world" 22 debug(1, 2); 23 fputs(str(strncmp("abc\0d?", "abc", '\4', "\u1234") /* this goes away */ 24 == 0) str(: @\n), s); 25 /*#include*/ xstr(INCFILE(2).hpp) 26 glue(HIGH, LOW); 27 xglue(HIGH, LOW) 28 29 // should expand to 30 //R #line 22 "t_1_013.cpp" 31 //R printf("x" "1" "= %d, x" "2" "= %s", x1, x2); 32 //R fputs("strncmp(\"abc\\0d\?\", \"abc\", '\\4', \"\\u1234\") == 0" ": @\n", s); 33 //R 34 //R "vers2.hpp" 35 //R "hello"; 36 //R "hello" ", world" 37 38 //H 10: t_1_013.cpp(13): #define 39 //H 08: t_1_013.cpp(13): str(s)=# s 40 //H 10: t_1_013.cpp(14): #define 41 //H 08: t_1_013.cpp(14): xstr(s)=str(s) 42 //H 10: t_1_013.cpp(15): #define 43 //H 08: t_1_013.cpp(15): debug(s, t)=printf("x" # s "= %d, x" # t "= %s", x ## s, x ## t) 44 //H 10: t_1_013.cpp(17): #define 45 //H 08: t_1_013.cpp(17): INCFILE(n)=vers ## n 46 //H 10: t_1_013.cpp(18): #define 47 //H 08: t_1_013.cpp(18): glue(a, b)=a ## b 48 //H 10: t_1_013.cpp(19): #define 49 //H 08: t_1_013.cpp(19): xglue(a, b)=glue(a, b) 50 //H 10: t_1_013.cpp(20): #define 51 //H 08: t_1_013.cpp(20): HIGHLOW="hello" 52 //H 10: t_1_013.cpp(21): #define 53 //H 08: t_1_013.cpp(21): LOW=LOW ", world" 54 //H 00: t_1_013.cpp(22): debug(1, 2), [t_1_013.cpp(15): debug(s, t)=printf("x" # s "= %d, x" # t "= %s", x ## s, x ## t)] 55 //H 02: printf("x" "1" "= %d, x" "2" "= %s", x1, x2) 56 //H 03: printf("x" "1" "= %d, x" "2" "= %s", x1, x2) 57 //H 00: t_1_013.cpp(23): str(strncmp("abc\0d?", "abc", '\4', "\u1234") == 0), [t_1_013.cpp(13): str(s)=# s] 58 //H 02: "strncmp(\"abc\\0d\?\", \"abc\", '\\4', \"\\u1234\") == 0" 59 //H 03: "strncmp(\"abc\\0d\?\", \"abc\", '\\4', \"\\u1234\") == 0" 60 //H 00: t_1_013.cpp(24): str(: @\n), [t_1_013.cpp(13): str(s)=# s] 61 //H 02: ": @\n" 62 //H 03: ": @\n" 63 //H 00: t_1_013.cpp(25): xstr(INCFILE(2).hpp), [t_1_013.cpp(14): xstr(s)=str(s)] 64 //H 00: t_1_013.cpp(25): INCFILE(2), [t_1_013.cpp(17): INCFILE(n)=vers ## n] 65 //H 02: vers2 66 //H 03: vers2 67 //H 02: str(vers2.hpp) 68 //H 00: t_1_013.cpp(14): str(vers2.hpp), [t_1_013.cpp(13): str(s)=# s] 69 //H 02: "vers2.hpp" 70 //H 03: "vers2.hpp" 71 //H 03: "vers2.hpp" 72 //H 00: t_1_013.cpp(26): glue(HIGH, LOW), [t_1_013.cpp(18): glue(a, b)=a ## b] 73 //H 02: HIGHLOW 74 //H 01: t_1_013.cpp(20): HIGHLOW 75 //H 02: "hello" 76 //H 03: "hello" 77 //H 03: "hello" 78 //H 00: t_1_013.cpp(27): xglue(HIGH, LOW), [t_1_013.cpp(19): xglue(a, b)=glue(a, b)] 79 //H 01: t_1_013.cpp(21): LOW 80 //H 02: LOW ", world" 81 //H 03: LOW ", world" 82 //H 02: glue(HIGH, LOW ", world") 83 //H 00: t_1_013.cpp(19): glue(HIGH, LOW ", world"), [t_1_013.cpp(18): glue(a, b)=a ## b] 84 //H 02: HIGHLOW ", world" 85 //H 01: t_1_013.cpp(20): HIGHLOW 86 //H 02: "hello" 87 //H 03: "hello" 88 //H 03: "hello" ", world" 89 //H 03: "hello" ", world" 90