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
",m);
}

$ cpp -DSOMETHING ack.c

[ ... ]

typedef int blah;

int main(void) {

int m = 5;

printf("%d
",m);
}

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

This article was posted by Matty on 2005-04-13 22:18:00 -0400 -0400