473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

__FILE__ marco

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
7 2726
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
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
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
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
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

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

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris Pomasl | last post by:
We picked up a helpdesk script from sourceforge, Mantis. This script uses the __FILE__ magic constant to ostensibly derive the path to the include directory from a script in the top level...
1
by: Chris Pomasl | last post by:
Does no one have any insight?......please? Chris -------- Original Message -------- Subject: Problem with __FILE__ magic constant Date: Tue, 06 Jan 2004 16:43:41 GMT From: Chris Pomasl...
6
by: Tom | last post by:
I'm trying to dynamically adjust the path for one of my scripts using this: $script_path = str_replace( $_SERVER, "", dirname(realpath(__FILE__)) ) . DIRECTORY_SEPARATOR; The problem: the...
1
by: Spry | last post by:
Hi, I wanted to write macros for finding the number of memory allocations and deallocations also wanted to find the locations. The code I have is a pretty big one. I have a wrapper on top of...
5
by: jake1138 | last post by:
I couldn't find an example of this anywhere so I post it in the hope that someone finds it useful. I believe this is compiler specific (I'm using gcc), as C99 defines __VA_ARGS__. Comments are...
5
by: baumann.Pan | last post by:
where are these macros defined? can I use it a release ver code?
2
by: fortepianissimo | last post by:
This is a question to all of you who use Komodo IDE for development: when I tried to debug my script which uses __file__ to get the absolute path to the file, Komodo complained that the variable is...
18
by: Lukas Ruf | last post by:
Dear all, for debugging purposes, I like the pre-compiler macros __FILE__, __FUNCTION__, __LINE__ I have been wondering if there is a short form of __FILE__ that provides only the filename...
4
by: 7stud | last post by:
Hi, I'm having trouble understanding what the definition of __file__ is. With this program: ------ #data.py: def show(): print __file__
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.