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"
64 .\" @MUFFLE_WARNINGS_DECL
65 .\" @MUFFLE_WARNINGS_EXPR
66 .\" @MUFFLE_WARNINGS_STMT
70 .\"--------------------------------------------------------------------------
72 macros \- useful macros
74 .\"--------------------------------------------------------------------------
78 .B "#include <mLib/macros.h>"
80 .BI "size_t N(" array ");"
81 .BI "STR(" tokens\fR... ")"
82 .BI "GLUE(" tokens\fR... ", " tokens\fR... ")"
83 .BI "STATIC_ASSERT(" cond ", " msg ");"
85 .BI "ISALNUM(int " ch ");"
86 .BI "ISALPHA(int " ch ");"
87 .BI "ISASCII(int " ch ");"
88 .BI "ISBLANK(int " ch ");"
89 .BI "ISCNTRL(int " ch ");"
90 .BI "ISDIGIT(int " ch ");"
91 .BI "ISGRAPH(int " ch ");"
92 .BI "ISLOWER(int " ch ");"
93 .BI "ISPRINT(int " ch ");"
94 .BI "ISPUNCT(int " ch ");"
95 .BI "ISSPACE(int " ch ");"
96 .BI "ISUPPER(int " ch ");"
97 .BI "ISXDIGIT(int " ch ");"
98 .BI "TOASCII(int " ch ");"
99 .BI "TOLOWER(int " ch ");"
100 .BI "TOUPPER(int " ch ");"
102 .BI "MEMCMP(const void *" x ", " op ", const void *" y ", size_t " n ");"
103 .BI "STRCMP(const char *" x ", " op ", const char *" y ");"
104 .BI "STRNCMP(const char *" x ", " op ", const char *" y ", size_t " n ");"
106 .BI "void DISCARD(" scalar ");"
107 .BI "void IGNORE(" variable ");"
109 .BI "DEPRECATED(" msg ")"
110 .BI "EXECL_LIKE(" ntrail ")"
114 .BI "PRINTF_LIKE(" fmt-index ", " arg-index ")"
115 .BI "SCANF_LIKE(" fmt-index ", " arg-index ")"
117 .BI "MUFFLE_WARNINGS_DECL(" warns ", " decls ")"
118 .BI "MUFFLE_WARNINGS_EXPR(" warns ", " expr ")"
119 .BI "MUFFLE_WARNINGS_STMT(" warns ", " stmt ")"
121 .BI "GCC_WARNING(" option ")"
122 .BI "CLANG_WARNING(" option ")"
125 .\"--------------------------------------------------------------------------
131 macro returns the number of elements in the named
136 macro expands to a string literal containing the result of expanding its
142 macro expands to a single token, which is the result of gluing together
143 the tokens resulting from expanding its argument token lists. Each of
144 the argument token lists must expand to a single preprocessing token,
145 and the result of gluing these tokens together must be valid
150 causes compilation to fail if the integer constant expression
152 evaluates to zero. This macro uses the C11
154 declaration if available, and the
156 will be reported in the compiler's diagnostic messsage; otherwise, the macro
157 falls back to a somewhat ugly hack which currently ignores the
164 macros are wrappers around the corresponding standard
166 macros with the corresponding lowercase names. They take care of
167 forcing the character argument
170 .BR "unsigned char" :
171 this conversion is necessary on platforms with signed
173 to avoid passing negative values into the standard macros.
180 macros are wrappers around the standard
182 functions with the corresponding lowercase names. They take an
185 which is a equality or ordering operator (e.g.,
189 inserted between the two operands. The standard functions return a
190 false value if and only if the operands are equal, which is
191 counterintuitive and leads to mistakes; requiring an explicit relational
192 operator should reduce the number of such mistakes.
196 macro discards its argument, which must be of some scalar type. This
197 can be useful in muffling warnings about ignoring return codes in cases
198 where you really don't care.
202 macro ignores its argument, which may be an expression of any type.
203 This can be useful in muffling warnings about unused variables.
206 The following annotations can be attached to function declarations and
207 definitions, as part of the declaration specifiers. (Other positions
208 may also work, depending on your compiler, but don't bet on it.) They
209 might not have any effect, depending on your specific compiler.
210 Currently only GCC is well supported, but exactly which features are
211 available depend on the compiler version.
213 Using a function or variable marked as
215 may provoke a compiler warning; this warning may (depending on your
216 compiler version) include the given
219 A variadic function marked as
221 must be called with a null pointer (i.e., an integer constant
222 expression with value 0, cast to
224 in the variadic part of its argument list, followed by
226 further arguments. Typically,
228 is zero. Compilers may warn about misuse of such functions.
230 A function or variable marked as
232 need not be used. This may muffle warnings about leaving the marked
237 returns an important value: a warning may be issued if a caller
238 ignores the value. The return type must not be
243 must not return. It must have return type
245 This may be useful in muffling warnings about uninitialized variables,
248 A variadic function marked as
252 format argument (in position
254 counting from 1) and a variable-length list of arguments to be formatted
255 (starting from position
257 Compilers may warn about misuse of such functions.
259 A variadic function marked as
263 format argument (in position
265 counting from 1) and a variable-length list of arguments to be formatted
266 (starting from position
268 Compilers may warn about misuse of such functions.
270 .SS Muffling warnings
271 Some compilers allow you to muffle warnings in particular pieces of
272 code. These macros provide a compiler-neutral interface to such
273 facilities. Each macro takes an argument
275 which is a sequence of calls to
276 .IB compiler _WARNING
277 macros listing the warnings to be muffled. The list may contain
278 warnings for several different compilers. The other argument is a
280 consisting of declarations (in the case of
281 .BR MUFFLE_WARNINGS_DECL ),
283 .BR MUFFLE_WARNINGS_EXPR ),
285 .BR MUFFLE_WARNINGS_STMT ).
287 .SS GCC-specific features
290 macro is intended to be used in
292 lists (see above). It takes a string-literal argument
294 naming a GCC warning option, e.g.,
295 .BR """\-Wdiv-by-zero""" .
299 is similar, except that it works with the Clang compiler.
303 also defines the compiler-test macros in
304 .BR <mLib/compiler.h>;
308 .\"--------------------------------------------------------------------------
314 .\"--------------------------------------------------------------------------
317 Mark Wooding, <mdw@distorted.org.uk>
319 .\"----- That's all, folks --------------------------------------------------