473,396 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2513
On 2007-11-14 13:56:21 -0500, Eric Lilja <mi********@gmail.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(expression).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...@comAcast.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(expression).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...@versatilecoding.comwrote:
On 2007-11-14 13:56:21 -0500, Eric Lilja <mindcoo...@gmail.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...@comAcast.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(expression).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 objektorientierter Datenverarbeitung
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...@comAcast.netwrote:
>You could try using 'typeid(expression).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...@comAcast.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
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...
3
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: ----...
4
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
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...
2
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....
1
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: ...
1
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...
2
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
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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
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...

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.