utils/macros.3: Document `CLANG_WARNING'.
[mLib] / utils / macros.3
CommitLineData
14d7100d 1.\" -*-nroff-*-
2.TH macros 3 "13 December 2003" "Straylight/Edgeware" "mLib utilities library"
3.SH NAME
4macros \- useful macros
5.\" @N
3832000d
MW
6.\" @STR
7.\" @GLUE
8.\" @DISCARD
9.\" @IGNORE
10.\" @DEPRECATED
11.\" @EXECL_LIKE
12.\" @IGNORABLE
13.\" @NORETURN
14.\" @PRINTF_LIKE
15.\" @SCANF_LIKE
16.\" @MUFFLE_WARNINGS_DECL
17.\" @MUFFLE_WARNINGS_EXPR
18.\" @MUFFLE_WARNINGS_STMT
19.\" @GCC_VERSION_P
20.\" @GCC_WARNING
14d7100d 21.SH SYNOPSIS
22.nf
23.B "#include <mLib/macros.h>"
24
25.BI "size_t N(" array ");"
3832000d
MW
26.BI "STR(" tokens\fR... ")"
27.BI "GLUE(" tokens\fR... ", " tokens\fR... ")"
28
29.BI "void DISCARD(" scalar ");"
30.BI "void IGNORE(" variable ");"
31
32.BI "DEPRECATED(" msg ")"
33.BI "EXECL_LIKE(" ntrail ")"
34.BI "IGNORABLE"
35.BI "NORETURN"
36.BI "PRINTF_LIKE(" fmt-index ", " arg-index ")"
37.BI "SCANF_LIKE(" fmt-index ", " arg-index ")"
38
39.BI "MUFFLE_WARNINGS_DECL(" warns ", " decls ")"
40.BI "MUFFLE_WARNINGS_EXPR(" warns ", " expr ")"
41.BI "MUFFLE_WARNINGS_STMT(" warns ", " stmt ")"
42
43.BI "int GCC_VERSION_P(" maj ", " min ");"
44.BI "GCC_WARNING(" option ")"
c418910f 45.BI "CLANG_WARNING(" option ")"
14d7100d 46.fi
47.SH DESCRIPTION
3832000d 48.SS Utilities
14d7100d 49The
50.B N
51macro returns the number of elements in the named
52.IR array .
3832000d
MW
53.PP
54The
55.B STR
56macro expands to a string literal containing the result of expanding its
57argument
58.IR tokens .
59.PP
60The
61.B GLUE
62macro expands to a single token, which is the result of gluing together
63the tokens resulting from expanding its argument token lists. Each of
64the argument token lists must expand to a single preprocessing token,
65and the result of gluing these tokens together must be valid
66preprocessing token.
67.PP
68The
69.B DISCARD
70macro discards its argument, which must be of some scalar type. This
71can be useful in muffling warnings about ignoring return codes in cases
72where you really don't care.
73.PP
74The
75.B IGNORE
76macro ignores its argument, which may be an expression of any type.
77This can be useful in muffling warnings about unused variables.
78.SS Annotations
79The following annotations can be attached to function declarations and
80definitions, as part of the declaration specifiers. (Other positions
81may also work, depending on your compiler, but don't bet on it.) They
82might not have any effect, depending on your specific compiler.
83Currently only GCC is well supported, but exactly which features are
84available depend on the compiler version.
85.PP
86Using a function or variable marked as
87.B DEPRECATED
88may provoke a compiler warning; this warning may (depending on your
89compiler version) include the given
90.IR msg .
91.PP
92A variadic function marked as
93.B EXECL_LIKE
94must be called with a null pointer (i.e., an integer constant
95expression with value 0, cast to
96.BR "void *")
97in the variadic part of its argument list, followed by
98.I ntrail
99further arguments. Typically,
100.I ntrail
101is zero. Compilers may warn about misuse of such functions.
102.PP
103A function or variable marked as
104.B IGNORABLE
105need not be used. This may muffle warnings about leaving the marked
106definition unused.
107.PP
108A function marked as
109.B NORETURN
110must not return. It must have return type
111.BR void .
112This may be useful in muffling warnings about uninitialized variables,
113for example.
114.PP
115A variadic function marked as
116.B PRINTF_LIKE
117takes a
118.BR printf (3)-style
119format argument (in position
120.IR fmt-index ,
121counting from 1) and a variable-length list of arguments to be formatted
122(starting from position
123.IR arg-index ).
124Compilers may warn about misuse of such functions.
125.PP
126A variadic function marked as
127.B SCANF_LIKE
128takes a
129.BR scanf (3)-style
130format argument (in position
131.IR fmt-index ,
132counting from 1) and a variable-length list of arguments to be formatted
133(starting from position
134.IR arg-index ).
135Compilers may warn about misuse of such functions.
136.SS Muffling warnings
137Some compilers allow you to muffle warnings in particular pieces of
138code. These macros provide a compiler-neutral interface to such
139facilities. Each macro takes an argument
140.IR warns ,
141which is a sequence of calls to
142.IB compiler _WARNING
143macros listing the warnings to be muffled. The list may contain
144warnings for several different compilers. The other argument is a
145.I body
146consisting of declarations (in the case of
147.BR MUFFLE_WARNINGS_DECL ),
148an expression (for
149.BR MUFFLE_WARNINGS_EXPR ),
150or a statement (for
151.BR MUFFLE_WARNINGS_STMT ).
152.SS GCC-specific features
153The
154.B GCC_VERSION_P
155macro returns a nonzero value if the compiler is at least version
156.IB maj . min
157of GCC, and zero otherwise. It's useful in preprocessor conditions.
158.PP
159The
160.B GCC_WARNING
161macro is intended to be used in
162.I warns
163lists (see above). It takes a string-literal argument
164.I option
165naming a GCC warning option, e.g.,
166.BR """\-Wdiv-by-zero""" .
c418910f
MW
167.PP
168The
169.B CLANG_WARNING
170is similar, except that it works with the Clang compiler.
14d7100d 171.SH "SEE ALSO"
172.BR mLib (3).
173.SH "AUTHOR"
9b5ac6ff 174Mark Wooding, <mdw@distorted.org.uk>