473,731 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a class name macro?

Hi,

__PRETTY_FUNCTI ON__ is a macro that gives function name, etc. I'm
wondering if there is a macro to get the class name inside a member
function.

Thanks,
Peng
Sep 16 '08 #1
33 15327
Peng Yu wrote:
Hi,

__PRETTY_FUNCTI ON__ is a macro that gives function name, etc.
Is it?
I'm
wondering if there is a macro to get the class name inside a member
function.
Not in standard C++.

--
Ian Collins.
Sep 16 '08 #2
On Sep 15, 8:24 pm, Ian Collins <ian-n...@hotmail.co mwrote:
Peng Yu wrote:
Hi,
__PRETTY_FUNCTI ON__ is a macro that gives function name, etc.

Is it?
I'm
wondering if there is a macro to get the class name inside a member
function.

Not in standard C++.
I know __PRETTY_FUNCTI ON__ is not in the standard. But the standard
has something similar to it, I just do remember what it is. But my
questions was on the class name.

Thanks,
Peng

Sep 16 '08 #3
Peng Yu wrote:
On Sep 15, 8:24 pm, Ian Collins <ian-n...@hotmail.co mwrote:
>Peng Yu wrote:
Hi,
__PRETTY_FUNCTI ON__ is a macro that gives function name, etc.

Is it?
I'm
wondering if there is a macro to get the class name inside a member
function.

Not in standard C++.

I know __PRETTY_FUNCTI ON__ is not in the standard. But the standard
has something similar to it, I just do remember what it is.
The standard has the following predefined macros [16.8]:

__LINE__
__FILE__
__DATE__
__TIME__
__STDC__
__cplusplus__

Everything else is implementation specific.

But my questions was on the class name.
And your question has been answered: "not in standard C++".
Best

Kai-Uwe Bux
Sep 16 '08 #4
use __func__, it is standard C, should be taken by any/most c++
compilers.

And your question has been answered: "not in standard C++".
Kai-Uwe Bux
:D

Sep 16 '08 #5
On Mon, 15 Sep 2008 19:53:15 -0700 (PDT), cu*****@spam.la wrote in
comp.lang.c++:
use __func__, it is standard C, should be taken by any/most c++
compilers.
It is standard C as of 1999, which is not yet a part of standard C++.

But in the part of the original post that you skipped:
__PRETTY_FUNCTI ON__ is a macro that gives function name, etc. I'm
wondering if there is a macro to get the class name inside a member
function.
....the __func__ macro, if/when it becomes part of C++, or is available
in a C++ compiler as an extension, still yields the function name, and
has nothing at all to do with the name of a class.
And your question has been answered: "not in standard C++".
Kai-Uwe Bux
So the above is still perfectly true.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Sep 16 '08 #6
On Sep 16, 4:07 am, Kai-Uwe Bux <jkherci...@gmx .netwrote:
Peng Yu wrote:
On Sep 15, 8:24 pm, Ian Collins <ian-n...@hotmail.co mwrote:
Peng Yu wrote:
__PRETTY_FUNCTI ON__ is a macro that gives function name, etc.
Is it?
I'm wondering if there is a macro to get the class name
inside a member function.
Not in standard C++.
I know __PRETTY_FUNCTI ON__ is not in the standard. But the standard
has something similar to it, I just do remember what it is.
The standard has the following predefined macros [16.8]:
__LINE__
__FILE__
__DATE__
__TIME__
__STDC__
__cplusplus__
Everything else is implementation specific.
Not entirely. A certain number of standard headers are also
guaranteed to define specific macros. In addition, C99 adds
some important macros which will doubtlessly end up in the next
standard, and in practice, should certainly be implemented by
every compiler today. (__STDC_IEC_559 __ and __STDC_HOSTED__
come to mind.)

In C99, there is also a pre-defined identifier, __func__, which
contains the name of the function. C++0x will also have this,
but unlike C, given overloading, classes, namespaces and
templates, it's not clear what the string should contain.
(According to the current draft, it's implementation defined.)
But my questions was on the class name.
And your question has been answered: "not in standard C++".
And it won't be part of the next version of the standard,
either. (At least I don't think so.)

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 16 '08 #7
On Mon, 15 Sep 2008 22:10:35 -0500, Jack Klein <ja*******@spam cop.netwrote:
On Mon, 15 Sep 2008 19:53:15 -0700 (PDT), cu*****@spam.la wrote in
comp.lang.c++:
>use __func__, it is standard C, should be taken by any/most c++
compilers.

It is standard C as of 1999, which is not yet a part of standard C++.

But in the part of the original post that you skipped:
__PRETTY_FUNCTI ON__ is a macro that gives function name, etc. I'm
wondering if there is a macro to get the class name inside a member
function.

...the __func__ macro, if/when it becomes part of C++, or is available
in a C++ compiler as an extension, still yields the function name, and
has nothing at all to do with the name of a class.
"Nothing at all" is a bit strongly worded -- I'd expect it to work for
member functions, and the class name to be part of it. E.g. "Foo<int>"
in "Foo<int>::bar( const Baz&)".

I have used __func__ as a C++ extension in g++, but I forget exactly
how they chose to do it. It's in the documentation though.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se R'lyeh wgah'nagl fhtagn!
Sep 16 '08 #8
On Sep 16, 2:31 pm, Jorgen Grahn <grahn+n...@sni pabacken.sewrot e:
On Mon, 15 Sep 2008 22:10:35 -0500, Jack Klein <jackkl...@spam cop.netwrote:
...the __func__ macro,
Just a nit, but it's not a macro, but a pre-defined variable.
if/when it becomes part of C++, or is available in a C++
compiler as an extension, still yields the function name,
and has nothing at all to do with the name of a class.
"Nothing at all" is a bit strongly worded -- I'd expect it to
work for member functions, and the class name to be part of
it. E.g. "Foo<int>" in "Foo<int>::bar( const Baz&)".
It's already present in the draft. The text is "implementa tion
defined", and could be simply "" in every case.
I have used __func__ as a C++ extension in g++, but I forget
exactly how they chose to do it. It's in the documentation
though.
They just output the simple function name.

The real question is what it is to be used for. What you want
to output depends on that, more than anything else. If it is
for logging messages, I'm not sure what is best. To find the
actual function, you need the fully qualified name, and even
that causes problems for anything in anonymous namespaces, or
member functions of local classes. And what about static
functions.

If the goal of putting it in a log file is to be able to find
the place in the source code later, a better solution is to use
__FILE__, __LINE__ and the version number inserted by your
version control system.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 16 '08 #9
James Kanze wrote:
On Sep 16, 2:31 pm, Jorgen Grahn <grahn+n...@sni pabacken.sewrot e:
>On Mon, 15 Sep 2008 22:10:35 -0500, Jack Klein <jackkl...@spam cop.net>
wrote:
...the __func__ macro,

Just a nit, but it's not a macro, but a pre-defined variable.
if/when it becomes part of C++, or is available in a C++
compiler as an extension, still yields the function name,
and has nothing at all to do with the name of a class.
>"Nothing at all" is a bit strongly worded -- I'd expect it to
work for member functions, and the class name to be part of
it. E.g. "Foo<int>" in "Foo<int>::bar( const Baz&)".

It's already present in the draft. The text is "implementa tion
defined", and could be simply "" in every case.
>I have used __func__ as a C++ extension in g++, but I forget
exactly how they chose to do it. It's in the documentation
though.

They just output the simple function name.

The real question is what it is to be used for.
I'll probably use it in my trace utility. In most cases I put classes in
files with the name of the class, so using
__FILE__ __func__ and __LINE__ will put an entry in my trace file that
indicates (in the majority of cases) the class and the function. For the
cases where the class does not have the same name as the file, or cases
where a function is overloaded, the __LINE__ will resolve the ambiguity.

My code will be simpler, because instead of putting:-

TRACE(ClassName ::FunctionName) ;

at the start of each function, I'll just put:-

TRACE;

Thanks to the OP for drawing attention to this.

Chris Gordon-Smith
www.simsoup.info

Sep 16 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2960
by: stephan beal | last post by:
Good afternoon, C++ers, This weekend i came across a fairly project-neutral trick which can be used to map C++ class names to their human-readable equivalents (a-la QObject's className() method), without having to add methods to a client interface and without relying on (e.g.) typeid(T).name(). i understand that this may not be strictly a language-related post, but i think the solution is "template-enough" to be considered topical here.
4
1445
by: pixelbeast | last post by:
hi, In the following code, I would like not to have to declare the constructors in bar ( either the default or the (int a) constructor ). When I remove them, bar has no idea of construction with an int, so I get compile errors. I currently have to declare them for every class inheriting foo, and it would be much nicer just with the init. Is there a nice way of doing this? I am currently using a macro, like CONSTRUCTOR(bar) which feels a...
4
25524
by: Ced | last post by:
Hi, i'm not an expert in C but i try to compile BTNG software under linux kernel 2.4.2-2. I get these errors at the very first stage. Does someone could have a rapid look on this and tell me what's wrong regards I get this error:
12
2018
by: Sunny | last post by:
Hi All, I have a serious issue regarding classes scope and visibility. In my application, i have a class name "TextFile", and also a few other classes like "TotalWords", "TotalLines" and etc.., which are suppose to describe the structure of my main TextFile class. Also i have created some custom collection classes, which only take items of the types, they are designed for. Now the problem is that I want my element classes, like...
17
7093
by: sounak | last post by:
How could we get a macro name from a macro value such that in a header file #define a 100 #define b 200 now the source file will be such that the user gives 100 then the value is outputted as a the user gives 200 then the value is outputted as b
48
4758
by: mahurshi | last post by:
I am new to c++ classes. I defined this "cDie" class that would return a value between 1 and 6 (inclusive) It runs fine and gives no warnings during compilation. I was wondering if you guys can pick up any mistakes/"don't do"s from this code: #include <iostream> #include <cstdlib>
9
5502
by: silversurfer2025 | last post by:
Hello everyone, I am currently having problems with a C++ abstract class. I have a class FrameWork.h which defines some methods (of which some are abstract, i.e. virtual void method() = 0). In FrameWork.cpp I define some of the methods while I naturally leave the abstract methods undefined. Now I wrote a class FrameWork_GUI.h which inherits from the abstract FrameWork class and implements the missing (so far abstract) methods....
8
1905
by: nandakumar.raghu | last post by:
Hi, I am creating a #defined class like - #define BEGIN_TEST_MAP(testmapname) class testmapname\ {\ testmapname(){}\ testmapname(std::ofstream resultfile)\ {\ resultfile << "<Test name=\"" << #testmapname << "\"\n";
0
2948
by: forgedascendant | last post by:
Good day everyone, I am new to this site so please forgive me if this post isn't completly correct. For the past 2 weeks I have been beating my head against the wall trying to figure out what is wrong with the macro I created. The problem I am experiancing is that the range I am trying to put together does not seem to be working for some reason. My entire code is as follows: Sub Proto1() ' ' Proto1 Macro ' Macro recorded 8/30/2007...
0
8943
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9442
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9301
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9229
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9176
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8184
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4543
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3257
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 we have to send another system
3
2175
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.