combine __FILE__, __LINE__, __PRETTY_FUNCTION__

P

PengYu.UT

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
 
V

Victor Bazarov

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
 
B

BobR

Victor Bazarov wrote in message
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;
 
J

Jacek Dziedzic

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

Pete Becker

BobR said:
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.
 
B

BobR

Pete Becker wrote in message ...
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";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,833
Latest member
BettyeMacf

Latest Threads

Top