third_party.pigweed.src/pw_preprocessor/docs.rst
Alexei Frolov c10c81201d Add preprocessor and unit_test modules
This change adds two Pigweed modules: pw_preprocessor and pw_unit_test.
The preprocessor module contains header files providing helpful macros
for the C preprocessor. The unit test module contains a starter
implementation of a unit testing framework for Pigweed.

Change-Id: I46e1a4cae1fd8ce36d7840a2e92f8013fb489cde
2019-11-04 16:07:34 -08:00

64 lines
2.0 KiB
ReStructuredText

.. _chapter-preprocessor:
.. default-domain:: cpp
.. highlight:: sh
------------
Preprocessor
------------
The preprocessor module provides various helpful preprocessor macros.
Compatibility
=============
C and C++
Dependencies
============
This module has no dependencies.
Headers
=======
The preprocessor module provides several headers.
pw_preprocessor/boolean.h
-------------------------
Defines macros for boolean logic on literal 1s and 0s. This is useful for
situations when a literal is needed to build the name of a function or macro.
pw_preprocessor/compiler.h
--------------------------
Macros for compiler-specific features, such as attributes or builtins.
pw_preprocessor/concat.h
------------------------
Defines the ``PW_CONCAT(...)`` macro, which expands its arguments if they are
macros and token pastes the results. This can be used for building names of
classes, variables, macros, etc.
pw_preprocessor/macro_arg_count.h
---------------------------------
Defines the ``PW_ARG_COUNT(...)`` macro, which counts the number of arguments it
was passed. It can be invoked directly or with ``__VA_ARGS__`` in another macro.
``PW_ARG_COUNT(...)`` evaluates to a literal of the number of arguments which
can be used directly or concatenated to build other names. Unlike many common
implementations, this macro correctly evaluates to ``0`` when it is invoked
without arguments.
This header also defines ``PW_HAS_ARGS(...)`` and ``PW_HAS_NO_ARGS(...)``,
which evaluate to ``1`` or ``0`` depending on whether they are invoked with
arguments.
pw_preprocessor/util.h
----------------------
General purpose, useful macros.
* ``PW_ARRAY_SIZE(array)`` -- calculates the size of a C array
* ``PW_UNUSED(value)`` -- silences "unused variable" compiler warnings
* ``PW_STRINGIFY(...)`` -- expands its arguments as macros and converts them to
a string literal
* ``PW_EXTERN_C`` -- declares a name to be ``extern "C"`` in C++; expands to
nothing in C
* ``PW_EXTERN_C_START`` / ``PW_EXTERN_C_END`` -- declares an ``extern "C" { }``
block in C++; expands to nothing in C