Showing the C preprocessor output
It can be useful to see what your source code looks like after the preprocessor
expands all the macros (#define
) and includes or removes code based on
#ifdef/#ifndef ... #endif
blocks. The following gives a relatively clean
output:
cpp [-I include/path] -P [-C] [-H] file.c 2>&1 | less
For QRetail:
cpp -DOS_LINUX -Iinc -Ilinux/include -P [-C] [-H] src/file.c 2>&1 | less
Switches cannot be grouped; they must be passed as individual switches.
The -C
switch includes comments that the pre-processor usually removes. Note
that including it has the unexpected effect of showing the comments from all
the included system header files, so you’ll see the comments from files such as
<features.h>, <stdlib.h>
and <stdio.h>
.
Another useful switch is -H
to show the names of all the header files as
they’re included.