@@ -49,9 +49,9 @@ pragma(ident) // influence block of statements
49
49
-----------------
50
50
51
51
$(P The kind of pragma it is determined by the $(I Identifier).
52
- $(I ExpressionList ) is a comma-separated list of
52
+ $(GLINK2 expression, ArgumentList ) is a comma-separated list of
53
53
$(ASSIGNEXPRESSION)s. The $(ASSIGNEXPRESSION)s must be
54
- parsable as expressions, but what they mean semantically
54
+ parsable as expressions, but their meaning
55
55
is up to the individual pragma semantics.
56
56
)
57
57
67
67
$(LI $(LINK2 #startaddress, pragma startaddress))
68
68
)
69
69
70
- $(DL
70
+ $(IMPLEMENTATION_DEFINED An implementation may ignore these pragmas.)
71
71
72
- $(DT $(LNAME2 inline, $(D inline)))
73
- $(DD $(P Affects whether functions are inlined or not. If at the declaration level, it
72
+ $(H3 $(LNAME2 inline, $(D pragma inline)))
73
+
74
+ $(P Affects whether functions are inlined or not. If at the declaration level, it
74
75
affects the functions declared in the block it controls. If inside a function, it
75
- affects the function it is enclosed by. If there are multiple pragma inlines in a function,
76
- the lexically last one takes effect.)
76
+ affects the function it is enclosed by.)
77
77
78
78
$(P It takes three forms:)
79
79
$(OL
80
80
$(LI
81
81
---
82
82
pragma(inline)
83
83
---
84
- Sets the behavior to match the default behavior set by the compiler switch
85
- $(DDSUBLINK dmd, switch-inline, $(TT -inline)).
84
+ Sets the behavior to match the implementation's default behavior.
86
85
)
87
86
$(LI
88
87
---
@@ -94,12 +93,16 @@ pragma(inline, false)
94
93
---
95
94
pragma(inline, true)
96
95
---
97
- If a function cannot be inlined with the $(DDSUBLINK dmd, switch-inline, $(TT -inline))
98
- switch, an error message is issued. This is expected to be improved in the future to causing
99
- functions to always be inlined regardless of compiler switch settings. Whether a compiler can
100
- inline a particular function or not is implementation defined.
96
+ Always inline the functions.
101
97
)
102
98
)
99
+
100
+ $(P There can be only zero or one $(I AssignExpression)s. If one is there, it must
101
+ be `true`, `false`, or an integer value. An integer value is implicitly converted
102
+ to a bool.)
103
+
104
+ $(P If there are multiple pragma inlines in a function,
105
+ the lexically last one takes effect.)
103
106
---
104
107
pragma(inline):
105
108
int foo(int x) // foo() is never inlined
@@ -110,52 +113,77 @@ int foo(int x) // foo() is never inlined
110
113
return x + 3;
111
114
}
112
115
---
113
- )
114
116
117
+ $(IMPLEMENTATION_DEFINED
118
+ $(OL
119
+ $(LI The default inline behavior is typically selectable with a compiler switch
120
+ such as $(DDSUBLINK dmd, switch-inline, $(TT -inline).))
121
+ $(LI Whether a particular function can be inlined or not is implementation defined.)
122
+ $(LI What happens for `pragma(inline, true)` if the function cannot be inlined.
123
+ An error message is typical.)
124
+ ))
125
+
126
+ $(H3 $(LNAME2 lib, $(D pragma lib)))
115
127
116
- $(DT $(LNAME2 lib, $(D lib)))
117
- $(DD Inserts a directive in the object file to link in the library
118
- specified by the $(ASSIGNEXPRESSION).
119
- The $(ASSIGNEXPRESSION)s must be a string literal:
128
+ $(P There must be one $(ASSIGNEXPRESSION) and it must evaluate at compile time to a string literal.
129
+ )
120
130
-----------------
121
131
pragma(lib, "foo.lib");
122
132
-----------------
133
+
134
+ $(IMPLEMENTATION_DEFINED
135
+ Typically, the string literal specifies the file name of a library file. This name
136
+ is inserted into the generated object file, or otherwise is passed to the linker,
137
+ so the linker automatically links in that library.
123
138
)
124
139
140
+ $(H3 $(LNAME2 mangle, $(D pragma mangle)))
125
141
126
- $(DT $(LNAME2 mangle, $(D mangle)))
127
- $(DD Overrides the default mangling for a symbol. It's only effective
142
+ $(P Overrides the default mangling for a symbol.)
143
+
144
+ $(P There must be one $(ASSIGNEXPRESSION) and it must evaluate at compile time to a string literal.
145
+ )
146
+
147
+ $(IMPLEMENTATION_DEFINED It's only effective
128
148
when the symbol is a function declaration or a variable declaration.
129
149
For example this allows linking to a symbol which is a D keyword, which would normally
130
150
be disallowed as a symbol name:
151
+ )
131
152
-----------------
132
153
pragma(mangle, "body")
133
154
extern(C) void body_func();
134
155
-----------------
135
- )
136
156
137
157
138
- $(DT $(LNAME2 msg, $(D msg)))
139
- $(DD Constructs a message from the arguments and prints to the standard error stream while compiling:
158
+ $(H3 $(LNAME2 msg, $(D pragma msg)))
159
+
160
+ $(P Constructs a message from the $(I ArgumentList).)
161
+
140
162
-----------------
141
163
pragma(msg, "compiling...", 1, 1.0);
142
164
-----------------
143
- )
144
165
166
+ $(IMPLEMENTATION_DEFINED The arguments are typically presented to the user during compilation,
167
+ such as by printing them to the standard error stream.)
168
+
169
+
170
+ $(H3 $(LNAME2 startaddress, $(D pragma startaddress)))
171
+
172
+ $(P There must be one $(ASSIGNEXPRESSION) and it must evaluate at compile time to a function symbol.)
173
+
174
+ $(IMPLEMENTATION_DEFINED The function symbol specifies the start address for the program.
175
+ The symbol is inserted into the object file or is otherwise presented to the linker to
176
+ set the start address.
177
+ This is not normally used for application level programming,
178
+ but is for specialized systems work.
179
+ For applications code, the start address is taken care of
180
+ by the runtime library.
145
181
146
- $(DT $(LNAME2 startaddress, $(D startaddress)))
147
- $(DD Puts a directive into the object file saying that the
148
- function specified in the first argument will be the
149
- start address for the program:
150
182
-----------------
151
183
void foo() { ... }
152
184
pragma(startaddress, foo);
153
185
-----------------
154
- This is not normally used for application level programming,
155
- but is for specialized systems work.
156
- For applications code, the start address is taken care of
157
- by the runtime library.
158
- )
186
+
159
187
)
160
188
161
189
$(H2 $(LNAME2 vendor_specific_pragmas, Vendor Specific Pragmas))
@@ -165,22 +193,28 @@ $(H2 $(LNAME2 vendor_specific_pragmas, Vendor Specific Pragmas))
165
193
to version identifiers:
166
194
)
167
195
168
- -------------- ---
169
- pragma(DigitalMars_funky_extension ) { ... }
170
- -------------- ---
196
+ ---
197
+ pragma(DigitalMars_extension ) { ... }
198
+ ---
171
199
172
- $(P Compilers must diagnose an error for unrecognized $(I Pragma)s,
173
- even if they are vendor specific ones. This implies that vendor
174
- specific pragmas should be wrapped in version statements:
175
- )
200
+ $(P Implementations must diagnose an error for unrecognized $(I Pragma)s,
201
+ even if they are vendor specific ones.
202
+ )
176
203
177
- -----------------
178
- version (DigitalMars)
179
- {
180
- pragma(DigitalMars_funky_extension)
181
- { ... }
182
- }
183
- -----------------
204
+ $(IMPLEMENTATION_DEFINED Vendor specific pragmas.)
205
+
206
+
207
+ $(BEST_PRACTICE vendor
208
+ specific pragmas should be wrapped in version statements
209
+
210
+ ---
211
+ version (DigitalMars)
212
+ {
213
+ pragma(DigitalMars_extension)
214
+ { ... }
215
+ }
216
+ ---
217
+ )
184
218
185
219
$(SPEC_SUBNAV_PREV_NEXT attribute, Attributes, expression, Expressions)
186
220
)
0 commit comments