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