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

combine __FILE__, __LINE__, __PRETTY_FUNCTION__

P: n/a
Hi,

I want to print out error message from all the three macros __FILE__,
__LINE__, __PRETTY_FUNCTION__. I'm wondering if there is one macro
which serves equivalently as the combinations of the three.

Thanks,
Peng

Nov 3 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Pe*******@gmail.com wrote:
I want to print out error message from all the three macros __FILE__,
__LINE__, __PRETTY_FUNCTION__. I'm wondering if there is one macro
which serves equivalently as the combinations of the three.
Since __PRETTY_FUNCTION__ is non-standard the question has no
affirmative answer in Standard C++.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 3 '06 #2

P: n/a

Victor Bazarov wrote in message
<27******************************@comcast.com>.. .
>Pe*******@gmail.com wrote:
>I want to print out error message from all the three macros __FILE__,
__LINE__, __PRETTY_FUNCTION__. I'm wondering if there is one macro
which serves equivalently as the combinations of the three.

Since __PRETTY_FUNCTION__ is non-standard the question has no
affirmative answer in Standard C++.
My GCC docs stated that there is a '__func__' var. in standard, but, I've not
confirmed it.

// "By this definition, __func__ is a variable, not a string literal.
// In particular, __func__ does not catenate with other string literals".
std::cout<<" __func__ ="<<__func__<<std::endl;
std::string FuncName( __func__ );
std::cout<<" string FuncName ="<<FuncName<<std::endl;

--
Bob R
POVrookie
Nov 3 '06 #3

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

I want to print out error message from all the three macros __FILE__,
__LINE__, __PRETTY_FUNCTION__. I'm wondering if there is one macro
which serves equivalently as the combinations of the three.
Why not write your own?

#define combo \
cerr << "File: " << __FILE__ << ", line: " << __LINE__ \
<< ", function: " << __PRETTY_FUNCTION__ << endl;

HTH,
- J.
Nov 3 '06 #4

P: n/a
BobR wrote:
>
My GCC docs stated that there is a '__func__' var. in standard, but, I've not
confirmed it.
There is no __func__ macro, variable, or whatever else in standard C++.

--

-- Pete

Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." For more information about this book, see
www.petebecker.com/tr1book.
Nov 3 '06 #5

P: n/a

Pete Becker wrote in message ...
>BobR wrote:
>>
My GCC docs stated that there is a '__func__' var. in standard, but, I've
not
>confirmed it.

There is no __func__ macro, variable, or whatever else in standard C++.
Ah, I see, it's C.

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

--
Bob R
POVrookie
Nov 11 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.