… | |
… | |
163 | C<__x86_64> stands for, well, the x86-64 ABI, making these macros |
163 | C<__x86_64> stands for, well, the x86-64 ABI, making these macros |
164 | necessary. |
164 | necessary. |
165 | |
165 | |
166 | =back |
166 | =back |
167 | |
167 | |
168 | =head2 GCC ATTRIBUTES |
168 | =head2 ATTRIBUTES |
169 | |
169 | |
170 | A major part of libecb deals with GCC attributes. These are additional |
170 | A major part of libecb deals with additional attributes that can be |
171 | attributes that you can assign to functions, variables and sometimes even |
171 | assigned to functions, variables and sometimes even types - much like |
172 | types - much like C<const> or C<volatile> in C. |
172 | C<const> or C<volatile> in C. They are implemented using either GCC |
173 | |
173 | attributes or other compiler/language specific features. Attributes |
174 | While GCC allows declarations to show up in many surprising places, |
|
|
175 | but not in many expected places, the safest way is to put attribute |
|
|
176 | declarations before the whole declaration: |
174 | declarations must be put before the whole declaration: |
177 | |
175 | |
178 | ecb_const int mysqrt (int a); |
176 | ecb_const int mysqrt (int a); |
179 | ecb_unused int i; |
177 | ecb_unused int i; |
180 | |
178 | |
181 | For variables, it is often nicer to put the attribute after the name, and |
|
|
182 | avoid multiple declarations using commas: |
|
|
183 | |
|
|
184 | int i ecb_unused; |
|
|
185 | |
|
|
186 | =over 4 |
179 | =over 4 |
187 | |
|
|
188 | =item ecb_attribute ((attrs...)) |
|
|
189 | |
|
|
190 | A simple wrapper that expands to C<__attribute__((attrs))> on GCC 3.1+ and |
|
|
191 | Clang 2.8+, and to nothing on other compilers, so the effect is that only |
|
|
192 | GCC and Clang see these. |
|
|
193 | |
|
|
194 | Example: use the C<deprecated> attribute on a function. |
|
|
195 | |
|
|
196 | ecb_attribute((__deprecated__)) void |
|
|
197 | do_not_use_me_anymore (void); |
|
|
198 | |
180 | |
199 | =item ecb_unused |
181 | =item ecb_unused |
200 | |
182 | |
201 | Marks a function or a variable as "unused", which simply suppresses a |
183 | Marks a function or a variable as "unused", which simply suppresses a |
202 | warning by GCC when it detects it as unused. This is useful when you e.g. |
184 | warning by GCC when it detects it as unused. This is useful when you e.g. |
… | |
… | |
218 | Similar to C<ecb_unused>, but marks a function, variable or type as |
200 | Similar to C<ecb_unused>, but marks a function, variable or type as |
219 | deprecated. This makes some compilers warn when the type is used. |
201 | deprecated. This makes some compilers warn when the type is used. |
220 | |
202 | |
221 | =item ecb_inline |
203 | =item ecb_inline |
222 | |
204 | |
223 | This is not actually an attribute, but you use it like one. It expands |
|
|
224 | either to C<static inline> or to just C<static>, if inline isn't |
205 | Expands either to C<static inline> or to just C<static>, if inline |
225 | supported. It should be used to declare functions that should be inlined, |
206 | isn't supported. It should be used to declare functions that should be |
226 | for code size or speed reasons. |
207 | inlined, for code size or speed reasons. |
227 | |
208 | |
228 | Example: inline this function, it surely will reduce codesize. |
209 | Example: inline this function, it surely will reduce codesize. |
229 | |
210 | |
230 | ecb_inline int |
211 | ecb_inline int |
231 | negmul (int a, int b) |
212 | negmul (int a, int b) |