C pre processor

I am knee deep in debugging another SEGFAULT issue, and was given a cool tip by my friend Clay this weekend. When you see lots of #ifdef, #ifndef, and #endif’s in a source file, you can see what the C pre-processor will produce by running the source through the C pre-processor command (cpp):

$ cat ack.c

#include

#ifdef SOMETHING
typedef int blah;
#endif

#ifdef SOMETHING_ELSE
typedef long foo
#endif

int main(void) {

int m = 5;

printf(“%d\n”,m);
}

$ cpp -DSOMETHING ack.c

[ … ]

typedef int blah;

int main(void) {

int m = 5;

printf(“%d\n”,m);
}

I removed all the standard includes to simplify the example. This is super useful!

Leave a Reply

Your email address will not be published. Required fields are marked *