1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
# 1 "scope.cppo"
(* This example shows that the definition of FOO that is nested inside
the (multi-line) definition of BAR affects only the body of the
definition of BAR. It does not affect the text that follows a call
to BAR. So, a multi-line macro definition acts as a scope delimiter. *)
# 11 "scope.cppo"
"definition of FOO at the top level"
# 11 "scope.cppo"
(* expands to "definition of FOO at the top level" *)
# 12 "scope.cppo"
"definition of FOO inside BAR" (* expands to "definition of FOO inside BAR" *)
# 13 "scope.cppo"
"definition of FOO at the top level"
# 13 "scope.cppo"
(* expands to "definition of FOO at the top level" *)
(* If one wishes to delimit a scope, without actually defining a macro,
one can use #scope ... #endscope. *)
# 20 "scope.cppo"
"first definition of HELLO"
# 20 "scope.cppo"
(* expands to "first definition of HELLO" *)
# 24 "scope.cppo"
"second definition of HELLO"
# 24 "scope.cppo"
(* expands to "second definition of HELLO" *)
HELLO (* this does not expand *)
(* The effect of #scope ... #endscope can be simulated by writing
#def DUMMY ... #enddef DUMMY #undef DUMMY
but this is a bit unnatural. *)
# 36 "scope.cppo"
"definition of HELLO inside the scope" (* expands to "definition of HELLO inside the scope" *)
# 38 "scope.cppo"
HELLO (* this does not expand *)
(* Another simple example. *)
# 44 "scope.cppo"
let x =
# 44 "scope.cppo"
"I am defined"
# 44 "scope.cppo"
(* expands to "I am defined" *)
# 47 "scope.cppo"
let y =
# 47 "scope.cppo"
42
# 47 "scope.cppo"
(* expands to 42 *)
(* Check that the effect of #undef is also local.
This example relies on the above definition of HI. *)
# 54 "scope.cppo"
let qwd = HI (* HI is not recognized as a macro and expands to itself *)
let z =
# 56 "scope.cppo"
42
# 56 "scope.cppo"
(* expands to 42 *)
(* Scopes can be nested. *)
# 61 "scope.cppo"
let x =
# 61 "scope.cppo"
0
# 61 "scope.cppo"
(* expands to 0 *)
# 65 "scope.cppo"
let y =
# 65 "scope.cppo"
1
# 65 "scope.cppo"
(* expands to 1 *)
# 69 "scope.cppo"
let z =
# 69 "scope.cppo"
2
# 69 "scope.cppo"
(* expands to 2 *)
let _ =
# 71 "scope.cppo"
1
# 71 "scope.cppo"
(* expands to 1 *)
let _ =
# 73 "scope.cppo"
0
# 73 "scope.cppo"
(* expands to 0 *)
(* Another example of nesting. *)
# 81 "scope.cppo"
let message1 =
# 81 "scope.cppo"
"Hello, "
# 81 "scope.cppo"
^
# 81 "scope.cppo"
"man"
# 83 "scope.cppo"
(* Here, MAN is no longer defined, but HELLO still is. *)
let message2 =
# 84 "scope.cppo"
"Hello, "
# 84 "scope.cppo"
^ "world"
|