gcc check if file is main (#if __BASE_FILE__ == __FILE__)
Posted
by
Marcin Raczkowski
on Stack Overflow
See other posts from Stack Overflow
or by Marcin Raczkowski
Published on 2011-01-02T13:23:09Z
Indexed on
2011/01/02
14:54 UTC
Read the original article
Hit count: 186
Hello.
In ruby there's very common idiom to check if current file is "main" file:
if __FILE__ == $0
# do something here (usually run unit tests)
end
I'd like to do something similar in C after reading gcc documentation I've figured that it should work like this:
#if __FILE__ == __BASE_FILE__
// Do stuff
#endif
the only problem is after I try this:
$ gcc src/bitmap_index.c -std=c99 -lm && ./a.out
src/bitmap_index.c:173:1: error: token ""src/bitmap_index.c"" is not valid in preprocessor expressions
Am I using #if wrong?
© Stack Overflow or respective owner