blob: 048abb3c495d5760bf388c73e6539ba45b164b5a [file] [log] [blame]
Alexei Frolovc10c8122019-11-01 16:31:19 -07001.. _chapter-preprocessor:
2
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
16Dependencies
17============
18This module has no dependencies.
19
20Headers
21=======
22The preprocessor module provides several headers.
23
24pw_preprocessor/boolean.h
25-------------------------
26Defines macros for boolean logic on literal 1s and 0s. This is useful for
27situations when a literal is needed to build the name of a function or macro.
28
29pw_preprocessor/compiler.h
30--------------------------
31Macros for compiler-specific features, such as attributes or builtins.
32
33pw_preprocessor/concat.h
34------------------------
35Defines the ``PW_CONCAT(...)`` macro, which expands its arguments if they are
36macros and token pastes the results. This can be used for building names of
37classes, variables, macros, etc.
38
39pw_preprocessor/macro_arg_count.h
40---------------------------------
41Defines the ``PW_ARG_COUNT(...)`` macro, which counts the number of arguments it
42was passed. It can be invoked directly or with ``__VA_ARGS__`` in another macro.
43``PW_ARG_COUNT(...)`` evaluates to a literal of the number of arguments which
44can be used directly or concatenated to build other names. Unlike many common
45implementations, this macro correctly evaluates to ``0`` when it is invoked
46without arguments.
47
48This header also defines ``PW_HAS_ARGS(...)`` and ``PW_HAS_NO_ARGS(...)``,
49which evaluate to ``1`` or ``0`` depending on whether they are invoked with
50arguments.
51
52pw_preprocessor/util.h
53----------------------
54General purpose, useful macros.
55
56* ``PW_ARRAY_SIZE(array)`` -- calculates the size of a C array
57* ``PW_UNUSED(value)`` -- silences "unused variable" compiler warnings
58* ``PW_STRINGIFY(...)`` -- expands its arguments as macros and converts them to
59 a string literal
60* ``PW_EXTERN_C`` -- declares a name to be ``extern "C"`` in C++; expands to
61 nothing in C
62* ``PW_EXTERN_C_START`` / ``PW_EXTERN_C_END`` -- declares an ``extern "C" { }``
63 block in C++; expands to nothing in C