blob: ae08b134246f27bae3395dc2b74061538c84d540 [file] [log] [blame]
Wyatt Hepleree3e02f2019-12-05 10:52:31 -08001.. _chapter-pw-preprocessor:
Alexei Frolovc10c8122019-11-01 16:31:19 -07002
3.. default-domain:: cpp
4
5.. highlight:: sh
6
Wyatt Heplerb82f9952019-11-25 13:56:31 -08007---------------
8pw_preprocessor
9---------------
Alexei Frolovc10c8122019-11-01 16:31:19 -070010The preprocessor module provides various helpful preprocessor macros.
11
12Compatibility
13=============
14C and C++
15
Alexei Frolovc10c8122019-11-01 16:31:19 -070016Headers
17=======
18The preprocessor module provides several headers.
19
20pw_preprocessor/boolean.h
21-------------------------
22Defines macros for boolean logic on literal 1s and 0s. This is useful for
23situations when a literal is needed to build the name of a function or macro.
24
25pw_preprocessor/compiler.h
26--------------------------
27Macros for compiler-specific features, such as attributes or builtins.
28
29pw_preprocessor/concat.h
30------------------------
31Defines the ``PW_CONCAT(...)`` macro, which expands its arguments if they are
32macros and token pastes the results. This can be used for building names of
33classes, variables, macros, etc.
34
35pw_preprocessor/macro_arg_count.h
36---------------------------------
37Defines the ``PW_ARG_COUNT(...)`` macro, which counts the number of arguments it
38was passed. It can be invoked directly or with ``__VA_ARGS__`` in another macro.
39``PW_ARG_COUNT(...)`` evaluates to a literal of the number of arguments which
40can be used directly or concatenated to build other names. Unlike many common
41implementations, this macro correctly evaluates to ``0`` when it is invoked
42without arguments.
43
44This header also defines ``PW_HAS_ARGS(...)`` and ``PW_HAS_NO_ARGS(...)``,
45which evaluate to ``1`` or ``0`` depending on whether they are invoked with
46arguments.
47
48pw_preprocessor/util.h
49----------------------
50General purpose, useful macros.
51
52* ``PW_ARRAY_SIZE(array)`` -- calculates the size of a C array
53* ``PW_UNUSED(value)`` -- silences "unused variable" compiler warnings
54* ``PW_STRINGIFY(...)`` -- expands its arguments as macros and converts them to
55 a string literal
56* ``PW_EXTERN_C`` -- declares a name to be ``extern "C"`` in C++; expands to
57 nothing in C
58* ``PW_EXTERN_C_START`` / ``PW_EXTERN_C_END`` -- declares an ``extern "C" { }``
59 block in C++; expands to nothing in C