473,503 Members | 8,959 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

__FILE__,__LINE__,__FUNCTION__ macros

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
9 9400
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
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
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

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

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

"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

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

Similar topics

1
6874
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...
9
25244
by: qazmlp | last post by:
How exactly __FILE__ and __LINE__ macros are defined? Or, Is the definition of these macros implementation dependent ? I am wondering how easily they can get the file name and line number...
5
2686
by: baumann.Pan | last post by:
where are these macros defined? can I use it a release ver code?
18
29244
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...
7
2658
by: Kenneth Brody | last post by:
Am I correct that using __FILE__ and __LINE__ within a macro will expand to the filename and line in which the macro is invoked, rather than where it is defined? For example, in a header file: ...
5
3352
by: Neo | last post by:
Hie, Can I put __FILE__ and __LINE__ macros inside the class function which may not be inline. And void function() { classobject::LogInfo(...); } Internally LogInfo should log file name...
0
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7361
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...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.