473,654 Members | 3,280 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Print name of typedef:ed type

Hello, in my c++ program I have the following "block":
#if defined __GNUC__ && defined NOT_PEDANTIC
typedef unsigned long long inttype;
#elif defined _MSC_VER
typedef unsigned __int64 inttype;
#else
typedef unsigned long inttype;
#endif

I'm wondering if there's a way, without resorting to the preprocessor,
to print the actual type (its name) of inttype when the program is
running? In the meantime I'm printing what
numeric_limits< inttype>::max() returns to give some hint.

- Eric

Nov 14 '07 #1
7 2524
On 2007-11-14 13:56:21 -0500, Eric Lilja <mi********@gma il.comsaid:
Hello, in my c++ program I have the following "block":
#if defined __GNUC__ && defined NOT_PEDANTIC
typedef unsigned long long inttype;
#elif defined _MSC_VER
typedef unsigned __int64 inttype;
#else
typedef unsigned long inttype;
#endif

I'm wondering if there's a way, without resorting to the preprocessor,
to print the actual type (its name) of inttype when the program is
running? In the meantime I'm printing what
numeric_limits< inttype>::max() returns to give some hint.
Since you're already relying on the preprocessor, why do you object to
using it? Just add a string literal to each branch of your if ladder.

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

Nov 14 '07 #2
Eric Lilja wrote:
Hello, in my c++ program I have the following "block":
#if defined __GNUC__ && defined NOT_PEDANTIC
typedef unsigned long long inttype;
#elif defined _MSC_VER
typedef unsigned __int64 inttype;
#else
typedef unsigned long inttype;
#endif

I'm wondering if there's a way, without resorting to the preprocessor,
to print the actual type (its name) of inttype when the program is
running? In the meantime I'm printing what
numeric_limits< inttype>::max() returns to give some hint.
First off, there is no "long long" (signed or not) in C++. There is
no __int64 in C++ either.

You could try using 'typeid(express ion).name()' to get the string
that contains the implementation' s best approximation to the type of
the expression. I tried it with VC++ v8, and it gives back the actual
type.

There is no clean way in C++ language itself, though, since the 'name'
member of 'std::typeinfo' is allowed to return an empty string.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 14 '07 #3
On 14 Nov, 20:03, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
>
First off, there is no "long long" (signed or not) in C++. There is
no __int64 in C++ either.
I know, that's why I'm using the preprocessor to activate compiler
extensions where available.
>
You could try using 'typeid(express ion).name()' to get the string
that contains the implementation' s best approximation to the type of
the expression. I tried it with VC++ v8, and it gives back the actual
type.

There is no clean way in C++ language itself, though, since the 'name'
member of 'std::typeinfo' is allowed to return an empty string.
I see, I will try it and see what happens on the other compilers I'm
targeting. VC++ v8 is one of them so at least I get the desired output
under that compiler it seems.

- Eric

Nov 14 '07 #4
On 14 Nov, 20:01, Pete Becker <p...@versatile coding.comwrote :
On 2007-11-14 13:56:21 -0500, Eric Lilja <mindcoo...@gma il.comsaid:
Hello, in my c++ program I have the following "block":
#if defined __GNUC__ && defined NOT_PEDANTIC
typedef unsigned long long inttype;
#elif defined _MSC_VER
typedef unsigned __int64 inttype;
#else
typedef unsigned long inttype;
#endif
I'm wondering if there's a way, without resorting to the preprocessor,
to print the actual type (its name) of inttype when the program is
running? In the meantime I'm printing what
numeric_limits< inttype>::max() returns to give some hint.

Since you're already relying on the preprocessor, why do you object to
using it? Just add a string literal to each branch of your if ladder.

--
Pete
Ah, good idea, I didn't think of that. I was trying to avoid using the
preprocessor again around the cout-statements and with your solution I
will avoid having to do just that. But I will try Victor's suggestion
as well just to see what happens. Thanks for your help and your quick
replies!

- Eric
Nov 14 '07 #5
On Nov 14, 8:03 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Eric Lilja wrote:
Hello, in my c++ program I have the following "block":
#if defined __GNUC__ && defined NOT_PEDANTIC
typedef unsigned long long inttype;
#elif defined _MSC_VER
typedef unsigned __int64 inttype;
#else
typedef unsigned long inttype;
#endif
I'm wondering if there's a way, without resorting to the
preprocessor, to print the actual type (its name) of inttype
when the program is running? In the meantime I'm printing
what numeric_limits< inttype>::max() returns to give some
hint.
First off, there is no "long long" (signed or not) in C++.
There is no __int64 in C++ either.
There's neither of them in *standard* C++, but since long long
is part of C90, and will be part of the next version of C++,
it's pretty much universal today, and can be considered "C++"
(but you'll need -Wno-long-long to get it with g++).
You could try using 'typeid(express ion).name()' to get the
string that contains the implementation' s best approximation
to the type of the expression. I tried it with VC++ v8, and
it gives back the actual type.
VC++ tries to do something useful with it. So does Sun CC.
G++, on the other hand, returns the string it uses when mangling
names, which is usually pretty useless. (For a long long, I get
"x".)
There is no clean way in C++ language itself, though, since
the 'name' member of 'std::typeinfo' is allowed to return an
empty string.
Or gibberish. Some compilers have decided that gibberish is the
way to go.

--
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
Nov 15 '07 #6
James Kanze wrote:
On Nov 14, 8:03 pm, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
>You could try using 'typeid(express ion).name()' to get the
string that contains the implementation' s best approximation
to the type of the expression. I tried it with VC++ v8, and
it gives back the actual type.

VC++ tries to do something useful with it. So does Sun CC.
G++, on the other hand, returns the string it uses when mangling
names, which is usually pretty useless. (For a long long, I get
"x".)
>There is no clean way in C++ language itself, though, since
the 'name' member of 'std::typeinfo' is allowed to return an
empty string.

Or gibberish. Some compilers have decided that gibberish is the
way to go.
I believe the point is that it's the same gibberish every time for
the same type. Furthermore, if it's "x" for 'long long', then it
is going to be "x" for a typedefed synonym of 'long long'. That's
*relatively* useful.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 15 '07 #7
On Wed, 14 Nov 2007 11:23:28 -0800, Eric Lilja wrote:
On 14 Nov, 20:03, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
>>
First off, there is no "long long" (signed or not) in C++. There is
no __int64 in C++ either.

I know, that's why I'm using the preprocessor to activate compiler
extensions where available.
You could use int_least64_t and/or int_fast64_t from cstdint.

--
Joel Yliluoma - http://iki.fi/bisqwit/
Nov 23 '07 #8

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

Similar topics

7
1602
by: mrstephengross | last post by:
Hi folks! I'm trying to do something that I'm pretty sure you can't do in C++. But what the heck! Maybe it can work... I want to figure out how to use macros and templates to turn the following code snippet: void SomeClass::someFunction() { /* ... */ } Into:
3
1661
by: Andreas Leitner | last post by:
Hi, I got a code snipset that gcc refuses to compile. I am note sure however whether this is a bug in gcc, or the snipset is just invalid C code. This is the source code in question: ---- typedef int foo; void bar1 (foo* foo)
4
1375
by: Cc | last post by:
hi , how do I get menber of a structure on runtime? for eample Structure Person <VBFixedString(10)> Public ID As String <VBFixedString(15)> Public Name As String End Structure
1
1435
by: Softwaremaker | last post by:
Hiya Fellows, I know that there are a few implementations out there that actually writes pure interface WSDL files. Therefore, the Service name is NOT mandatory for such an implementation. Such a modification can be easily made: simply remove the deployment information from the WSDL file by deleting the Service Element. By doing that, one now has a pure Web service interface description. My question is if I do the above, will it...
2
14740
by: paul.dunstone | last post by:
HI all I am using msbuild to compile my web application project. After building the solution I get the following error message: Server Error in '/Community' Application. -------------------------------------------------------------------------------- Value cannot be null.
1
1176
by: =?iso-8859-1?b?VG9t4XMg0yBoyWlsaWRoZQ==?= | last post by:
I'm writing some cross-platform code and I invite the developer to pick their own integer types in places. However, the integer type must be unsigned. So far, I make sure this is so with: typedef int SegIMustBeUnsigned; Yes, this does the trick, but I'm just wondering if anyone here has a better way of doing it. --
1
2013
by: Achim Domma | last post by:
Hi, in my data contract I have a member like this: public List<BaseClassItems { get { ... } } The property is serialized as a list of <BaseClasstags with an i:type attribute. It would be better for me to have <DerivedClass> tags for the different subclasses. Is there a way to enforce that?
2
3060
by: Alex Snast | last post by:
Hello guys, I can't seem to be able to get accsess to a type i declared within a template class i.e. template <typename T> class Array { public: typedef std::size_t size_type;
16
2766
by: mdh | last post by:
A quick ? :-) question about Typedefs. There is a very brief discussion about this in K&R ( p146). Googling this group, there is a surprising dearth of questions about these. From one of the threads, there is sound advice ( to me at any rate) not to hide pointers behind typedefs. So, may I ask the group when the use of typedefs really makes sense? Sorry if this is somewhat general, but there are no exercises ( not that I am asking for...
0
8290
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8815
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
8708
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
8489
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,...
1
6161
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4149
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...
0
4294
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2716
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
1
1916
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.