Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Since some people are posting macros (including some intentionally malicious ones), it is handy to know the -E compiler flag for debugging purposes. This will run only the preprocessor on the given files and print the result to stdout. (N.b. -E works at least on gcc and clang; the flag may be different elsewhere.)

Not really a C language trick, but useful nonetheless.



You can also call 'cpp' on the file. When doing heavy macrology (e.g. https://github.com/silentbicycle/kona/blob/master/scalar.h) I like to work in a file which is just

    #include "the_macro.h"

    THE_MACRO(example, args);
and call

    cpp macrotest.h | fmt -w72
(using fmt since multi-line macros will end up on one line otherwise).


The -E flag is specified by POSIX. Non-POSIX compilers sometimes support it, sometimes not.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: