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

__FILE__,__LINE__,__FUNCTION__ macros

P: n/a
Neo
Hi Friends,
I am planning to use "__FILE__,__LINE__,__FUNCTION__ " for a logging
component in my class.
In debug build I gets all information. I tried with release mode also
and it works. But I want to verify that will I able to get this
information at any kind of build with all possible optimizations?

Regards
Vikram S

Dec 21 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Neo wrote:
Hi Friends,
I am planning to use "__FILE__,__LINE__,__FUNCTION__ " for a logging
component in my class.
In debug build I gets all information. I tried with release mode also
and it works. But I want to verify that will I able to get this
information at any kind of build with all possible optimizations?
Sounds like a tool issue rather than a C++ one, try a group dedicated to
your compiler.

--
Ian Collins.
Dec 21 '06 #2

P: n/a
Neo wrote:
Hi Friends,
I am planning to use "__FILE__,__LINE__,__FUNCTION__ " for a logging
component in my class.
In debug build I gets all information. I tried with release mode also
and it works. But I want to verify that will I able to get this
information at any kind of build with all possible optimizations?
__FILE__ and __LINE__ are always valid, and their meanings are specified
by the C++ standard. If a compiler switch disables them, the compiler
doesn't conform to the language definition when that switch is used.

__FUNCTION__ is not specified by the standard. You'll have to look at
your compiler's documentation to figure out what it does and when it
does it.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 21 '06 #3

P: n/a
On Dec 21, 11:05 am, "Neo" <vikram.su...@gmail.comwrote:
Hi Friends,
I am planning to use "__FILE__,__LINE__,__FUNCTION__ " for a logging
component in my class.
In debug build I gets all information. I tried with release mode also
and it works. But I want to verify that will I able to get this
information at any kind of build with all possible optimizations?
__FUNCTION__ is not part of the C++ standard, but __LINE__ and __FILE__
are. Notice however that the value of __FILE__ can be either the
relative path (name of file) or the absolute path to the file at
compile time, or perhaps something in between.

--
Erik Wikström

Dec 21 '06 #4

P: n/a

Pete Becker wrote in message ...
>Neo wrote:
>Hi Friends,
I am planning to use "__FILE__,__LINE__,__FUNCTION__ " for a logging
component in my class.
In debug build I gets all information. I tried with release mode also
and it works. But I want to verify that will I able to get this
information at any kind of build with all possible optimizations?

__FILE__ and __LINE__ are always valid, and their meanings are specified
by the C++ standard. If a compiler switch disables them, the compiler
doesn't conform to the language definition when that switch is used.

__FUNCTION__ is not specified by the standard. You'll have to look at
your compiler's documentation to figure out what it does and when it
does it.
If the compiler is C99 complient, you can use '__func__' [1].

[1] - ref: GCC docs. (Some minor restrictions on concatenation.)
--
Bob R
POVrookie
Dec 21 '06 #5

P: n/a
BobR wrote:
>
If the compiler is C99 complient, you can use '__func__' [1].
--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 21 '06 #6

P: n/a
BobR wrote:
Pete Becker wrote in message ...
>>
__FUNCTION__ is not specified by the standard. You'll have to look at
your compiler's documentation to figure out what it does and when it
does it.

If the compiler is C99 complient, you can use '__func__' [1].
That's true if you're compiling C, but the C99 standard doesn't tell you
what __func__ does in a C++ member function, nor in a template function.

[1] - ref: GCC docs. (Some minor restrictions on concatenation.)
As I said: you'll have to look at your compiler's documentation. <g>

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 21 '06 #7

P: n/a

Pete Becker wrote in message ...
>BobR wrote:
>Pete Becker wrote in message ...
>>__FUNCTION__ is not specified by the standard. You'll have to look at
your compiler's documentation to figure out what it does and when it
does it.

If the compiler is C99 complient, you can use '__func__' [1].

That's true if you're compiling C, but the C99 standard doesn't tell you
what __func__ does in a C++ member function, nor in a template function.
>[1] - ref: GCC docs. (Some minor restrictions on concatenation.)

As I said: you'll have to look at your compiler's documentation. <g>
I just know it works in GCC g++ without turning on any special flags or
includes(yeah, some are 'automatic' <g>).

Maybe someone with a faster access than I can try this on Comeau?:

// ------------------------------------
#include <iostream // #include <ostream>
void Test( std::ostream &cout ){
cout<<"\n_____[ "<<__func__<<" ]_____"<<std::endl;
// ------------------------------------
cout<<"_____[ "<<__func__<<" ]__End\n"<<std::endl;
return;
}

int main(){
Test( std::cout );
return 0;
}
// ------------------------------------

Did it make Comeau puke?

Sure is a handy 'feature' for testing, error output, etc..

--
Bob R
POVrookie
Dec 21 '06 #8

P: n/a

"BobR" <Re***********@worldnet.att.netwrote in message
news:mN*********************@bgtnsc04-news.ops.worldnet.att.net...
>
Pete Becker wrote in message ...
>>Neo wrote:
>>Hi Friends,
I am planning to use "__FILE__,__LINE__,__FUNCTION__ " for a logging
component in my class.
In debug build I gets all information. I tried with release mode also
and it works. But I want to verify that will I able to get this
information at any kind of build with all possible optimizations?

__FILE__ and __LINE__ are always valid, and their meanings are specified
by the C++ standard. If a compiler switch disables them, the compiler
doesn't conform to the language definition when that switch is used.

__FUNCTION__ is not specified by the standard. You'll have to look at
your compiler's documentation to figure out what it does and when it
does it.

If the compiler is C99 complient, you can use '__func__' [1].

[1] - ref: GCC docs. (Some minor restrictions on concatenation.)
A problem with the __func__ and __FILE__ macros is that you can't
control the formatting. Sometimes you may want just a file name rather
than a full path, for example.

It's odd that the C99 __func__ macro is not __FUNC__, don't ya think?

Tony
Dec 22 '06 #9

P: n/a

Tony wrote in message ...
>
"BobR" wrote in message ...
>Pete Becker wrote in message ...
>>>__FILE__ and __LINE__ are always valid, and their meanings are specified
by the C++ standard. If a compiler switch disables them, the compiler
doesn't conform to the language definition when that switch is used.

__FUNCTION__ is not specified by the standard. You'll have to look at
your compiler's documentation to figure out what it does and when it
does it.

If the compiler is C99 complient, you can use '__func__' [1].

[1] - ref: GCC docs. (Some minor restrictions on concatenation.)

A problem with the __func__ and __FILE__ macros is that you can't
control the formatting. Sometimes you may want just a file name rather
than a full path, for example.
std::string FuncName(__func__);
// change 'FuncName' to what you want.
>
It's odd that the C99 __func__ macro is not __FUNC__, don't ya think?
Tony
If '__func__' was a macro, it might have an all uppercase name.

From GCC docs:

"
__func__ is defined by the ISO standard C99:
The identifier __func__ is implicitly declared by the translator
as if, immediately following the opening brace of each function
definition, the declaration
static const char __func__[] = "function-name";
appeared, where function-name is the name of the lexically-enclosing
function. This name is the unadorned name of the function.

By this definition, __func__ is a variable, not a string literal. In
particular,
__func__ does not catenate with other string literals.
In C++, __FUNCTION__ and __PRETTY_FUNCTION__ are variables,
declared in the same way as __func__.
"

--
Bob R
POVrookie
Dec 22 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.