By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

__FILE__ marco

P: n/a
Hi,

If I define a template wich uses the __FILE__ marco in a .h file
and I have class which creates/uses that template (in a .cpp file).
What will the __FILE__ marco expand to? the .h which defines the
template? or the .cpp file which uses the template?

Thank you.

Feb 24 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Pl********@gmail.com wrote:
Hi,

If I define a template wich uses the __FILE__ marco in a .h file
and I have class which creates/uses that template (in a .cpp file).
What will the __FILE__ marco expand to? the .h which defines the
template? or the .cpp file which uses the template?


It will expand to the .h file, where the __FILE__ resides.

Feb 24 '06 #2

P: n/a
Pl********@gmail.com wrote:
If I define a template wich uses the __FILE__ marco in a .h file
and I have class which creates/uses that template (in a .cpp file).
What will the __FILE__ marco expand to? the .h which defines the
template? or the .cpp file which uses the template?


You should try and see. AFAICT, some compiler can choose to expand it
into the name of the translation unit that starts the chain of include
directives, and some can expand it into the actual file (considering the
included files as well). The Standard (or the way I read it) does not
seem to specify it explicitly.

Oh, BTW, what __FILE__ expands into can be changed by '#line' directive.

V
--
Please remove capital As from my address when replying by mail
Feb 24 '06 #3

P: n/a
Pl********@gmail.com wrote:
Hi,

If I define a template wich uses the __FILE__ marco in a .h file
and I have class which creates/uses that template (in a .cpp file).
What will the __FILE__ marco expand to? the .h which defines the
template? or the .cpp file which uses the template?

__FILE__ and friends are expanded by the preprocessor, before the
compiler gets a look in. So it will expand to the current file name,
which will be the header in this case.

--
Ian Collins.
Feb 24 '06 #4

P: n/a
It depends on how the macro is used. If it is used in another macro, it
will expand to where that macro is used.

For instance:

#define PRINT_TRACE \
printf("%s:%i\n", __FILE__, __LINE__);

Feb 24 '06 #5

P: n/a
On Fri, 24 Feb 2006 12:23:29 -0800, Plissken.s wrote:
Hi,

If I define a template wich uses the __FILE__ marco in a .h file
and I have class which creates/uses that template (in a .cpp file).
What will the __FILE__ marco expand to? the .h which defines the
template? or the .cpp file which uses the template?

Thank you.


Taking a wild guess here, you might want to try this:
#define WhereMacro \
cerr << __FILE__ << ": line: " << __LINE__ << ": " << __FUNCTION__ <<endl
in some header file, then call

WhereMacro;

anywhere in your code, and it all will expand to what you expect.

This is one instance where you have to use a #define, rather than an
inline function.

Feb 24 '06 #6

P: n/a

Pl********@gmail.com wrote:
Hi,

If I define a template wich uses the __FILE__ marco in a .h file
and I have class which creates/uses that template (in a .cpp file).
What will the __FILE__ marco expand to? the .h which defines the
template? or the .cpp file which uses the template?


You might be intrested in gcc macro __BASE_FILE__ which expands to the
name of translation unit.
http://gcc.gnu.org/onlinedocs/gcc-4....defined-Macros

Feb 25 '06 #7

P: n/a

<Pl********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Hi,

If I define a template wich uses the __FILE__ marco in a .h file
and I have class which creates/uses that template (in a .cpp file).
What will the __FILE__ marco expand to? the .h which defines the
template? or the .cpp file which uses the template?

Thank you.


One test case is worth a thousand expert opinions, why don't you write a
piece
of code to see what the compiler does, or are you an armchair programmer?

dave
Feb 25 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.