3 .\" Manual for miscellaneous macros
5 .\" (c) 2003, 2005, 2009, 2013, 2018, 2019, 2022, 2024 Straylight/Edgeware
8 .\"----- Licensing notice ---------------------------------------------------
10 .\" This file is part of the mLib utilities library.
12 .\" mLib is free software: you can redistribute it and/or modify it under
13 .\" the terms of the GNU Library General Public License as published by
14 .\" the Free Software Foundation; either version 2 of the License, or (at
15 .\" your option) any later version.
17 .\" mLib is distributed in the hope that it will be useful, but WITHOUT
18 .\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 .\" License for more details.
22 .\" You should have received a copy of the GNU Library General Public
23 .\" License along with mLib. If not, write to the Free Software
24 .\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 .\"--------------------------------------------------------------------------
28 .so ../defs.man \" @@@PRE@@@
30 .\"--------------------------------------------------------------------------
31 .TH macros 3mLib "13 December 2003" "Straylight/Edgeware" "mLib utilities library"
37 .\" @CONVERT_CAREFULLY
77 .\" @MUFFLE_WARNINGS_DECL
78 .\" @MUFFLE_WARNINGS_EXPR
79 .\" @MUFFLE_WARNINGS_STMT
83 .\"--------------------------------------------------------------------------
85 macros \- useful macros
87 .\"--------------------------------------------------------------------------
91 .B "#include <mLib/macros.h>"
93 .BI "size_t N(" type " " array "[]);"
94 .BI "STR(" tokens\fR... ")"
95 .BI "GLUE(" tokens\fR... ", " tokens\fR... ")"
96 .BI "STATIC_ASSERT(" cond ", " msg ");"
97 .BI "int CHECK_TYPE(" expty ", " expty " " x );
98 .IB newty " CONVERT_CAREFULLY(" newty ", " expty ", " expty " " x );
99 .IB type " *UNCONST(" type ", const " type " *" p );
100 .IB type " *UNVOLATILE(" type ", volatile " type " *" p );
101 .IB type " *UNQUALIFY(" type ", const volatile " type " *" p );
104 .BI "ISALNUM(int " ch ");"
105 .BI "ISALPHA(int " ch ");"
106 .BI "ISASCII(int " ch ");"
107 .BI "ISBLANK(int " ch ");"
108 .BI "ISCNTRL(int " ch ");"
109 .BI "ISDIGIT(int " ch ");"
110 .BI "ISGRAPH(int " ch ");"
111 .BI "ISLOWER(int " ch ");"
112 .BI "ISPRINT(int " ch ");"
113 .BI "ISPUNCT(int " ch ");"
114 .BI "ISSPACE(int " ch ");"
115 .BI "ISUPPER(int " ch ");"
116 .BI "ISXDIGIT(int " ch ");"
117 .BI "TOASCII(int " ch ");"
118 .BI "TOLOWER(int " ch ");"
119 .BI "TOUPPER(int " ch ");"
121 .BI "MEMCMP(const void *" x ", " op ", const void *" y ", size_t " n ");"
122 .BI "STRCMP(const char *" x ", " op ", const char *" y ");"
123 .BI "STRNCMP(const char *" x ", " op ", const char *" y ", size_t " n ");"
125 .BI "void DISCARD(" scalar ");"
126 .BI "void IGNORE(" variable ");"
128 .BI "DEPRECATED(" msg ")"
129 .BI "EXECL_LIKE(" ntrail ")"
133 .BI "PRINTF_LIKE(" fmt-index ", " arg-index ")"
134 .BI "SCANF_LIKE(" fmt-index ", " arg-index ")"
136 .BI "MUFFLE_WARNINGS_DECL(" warns ", " decls ")"
137 .BI "MUFFLE_WARNINGS_EXPR(" warns ", " expr ")"
138 .BI "MUFFLE_WARNINGS_STMT(" warns ", " stmt ")"
140 .BI "GCC_WARNING(" option ")"
141 .BI "CLANG_WARNING(" option ")"
144 .\"--------------------------------------------------------------------------
150 macro returns the number of elements in the named
155 macro expands to a string literal containing the result of expanding its
161 macro expands to a single token, which is the result of gluing together
162 the tokens resulting from expanding its argument token lists. Each of
163 the argument token lists must expand to a single preprocessing token,
164 and the result of gluing these tokens together must be valid
169 macro causes compilation to fail if the integer constant expression
171 evaluates to zero. This macro uses the C11
173 declaration if available, and the
175 will be reported in the compiler's diagnostic messsage; otherwise, the macro
176 falls back to a somewhat ugly hack which currently ignores the
181 macro checks at compile-time that
183 has (or, at least, is assignment-compatible with) type
185 If so, the result is the integer zero.
188 macro similarly checks at compile-time that
192 and if so, the result is
199 macro checks at compile-time that
201 has (or, at least, is assignment-compatible with) type
202 .BI "const " type "\ *" \fR.
209 qualification from the type that
214 macro is similar, except that it removes any
228 macro expands to a comma
230 which is useful for smuggling commas into macro arguments
231 if they can't be protected by parentheses.
237 macros are wrappers around the corresponding standard
239 macros with the corresponding lowercase names. They take care of
240 forcing the character argument
243 .BR "unsigned char" :
244 this conversion is necessary on platforms with signed
246 to avoid passing negative values into the standard macros.
253 macros are wrappers around the standard
255 functions with the corresponding lowercase names. They take an
258 which is a equality or ordering operator (e.g.,
262 inserted between the two operands. The standard functions return a
263 false value if and only if the operands are equal, which is
264 counterintuitive and leads to mistakes; requiring an explicit relational
265 operator should reduce the number of such mistakes.
269 macro discards its argument, which must be of some scalar type. This
270 can be useful in muffling warnings about ignoring return codes in cases
271 where you really don't care.
275 macro ignores its argument, which may be an expression of any type.
276 This can be useful in muffling warnings about unused variables.
280 macro tries to confuse a compiler so that it `forgets' what it knows
281 about a particular value. This is most useful in benchmarking or
282 similar applications.
286 macro tries do nothing, but in a way that a compiler won't optimize
290 The following annotations can be attached to function declarations and
291 definitions, as part of the declaration specifiers. (Other positions
292 may also work, depending on your compiler, but don't bet on it.) They
293 might not have any effect, depending on your specific compiler.
294 Currently only GCC is well supported, but exactly which features are
295 available depend on the compiler version.
297 Using a function or variable marked as
299 may provoke a compiler warning; this warning may (depending on your
300 compiler version) include the given
303 A variadic function marked as
305 must be called with a null pointer (i.e., an integer constant
306 expression with value 0, cast to
308 in the variadic part of its argument list, followed by
310 further arguments. Typically,
312 is zero. Compilers may warn about misuse of such functions.
314 A function or variable marked as
316 need not be used. This may muffle warnings about leaving the marked
321 returns an important value: a warning may be issued if a caller
322 ignores the value. The return type must not be
327 must not return. It must have return type
329 This may be useful in muffling warnings about uninitialized variables,
332 A variadic function marked as
336 format argument (in position
338 counting from 1) and a variable-length list of arguments to be formatted
339 (starting from position
341 Compilers may warn about misuse of such functions.
343 A variadic function marked as
347 format argument (in position
349 counting from 1) and a variable-length list of arguments to be formatted
350 (starting from position
352 Compilers may warn about misuse of such functions.
354 .SS Muffling warnings
355 Some compilers allow you to muffle warnings in particular pieces of
356 code. These macros provide a compiler-neutral interface to such
357 facilities. Each macro takes an argument
359 which is a sequence of calls to
360 .IB compiler _WARNING
361 macros listing the warnings to be muffled. The list may contain
362 warnings for several different compilers. The other argument is a
364 consisting of declarations (in the case of
365 .BR MUFFLE_WARNINGS_DECL ),
367 .BR MUFFLE_WARNINGS_EXPR ),
369 .BR MUFFLE_WARNINGS_STMT ).
371 .SS GCC-specific features
374 macro is intended to be used in
376 lists (see above). It takes a string-literal argument
378 naming a GCC warning option, e.g.,
379 .BR """\-Wdiv-by-zero""" .
383 is similar, except that it works with the Clang compiler.
387 also defines the compiler-test macros in
388 .BR <mLib/compiler.h>;
392 .\"--------------------------------------------------------------------------
398 .\"--------------------------------------------------------------------------
401 Mark Wooding, <mdw@distorted.org.uk>
403 .\"----- That's all, folks --------------------------------------------------