c - __FILE__ In .h what does it resolve to -


is there specification on how __file__ macro expanded if in .h?

if define in foo.h

#define myfile __file__ 

and include in foo.c

#include "foo.h"  int main(){   printf("%s",myfile);   .... } 

does output foo.h or foo.c? (yes realize stupid example)

sorry should simple question. documentation on web seems conflicting. worth vs2008 comes foo.c expect....i think. trying confirm if defined behavior.

the advice given in yan's answer 'generally correct'. is, value of __file__ name of current source file when macro used, not when macro defined. however, not absolutely correct - , here counter-example:

$ cat x.h static void helper(void) {     printf("%s:%d helper\n", __file__, __line__); } $ cat x.c #include <stdio.h> #include "x.h"  int main(void) {     helper();     printf("%s:%d\n", __file__, __line__);     return 0; }  $ make x cc -wall -wextra -std=c99 -g x.c -o x $ ./x x.h:3 helper x.c:7 $ 

this contrived example; in c, seldom put actual code header did here — unless using inline functions. output shows there circumstances name of header can correct name __file__ expands to.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -