471,584 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

typedef and #ifdef

How can you check to see if a type is built-in or typedef'ed? For
example, an 8-bit integer could be u_int8_t, uint8_t, or unsigned
__int8, depending on the OS/compiler. I'd like to write code like:

#if defined(u_int8_t)
typedef u_int8_t BYTE;
#elif defined (uint8_t)
typedef uint8_t BYTE;
#elif defined (__int8)
typedef unsigned __int8 BYTE

However, this does not work, because built-in and typedef'ed types are
not "defined" according to #ifdef. So two questions: Is there a
work-around? And why doesn't C++ allow the above code?
Jul 19 '05 #1
1 10484
On 11 Aug 2003 10:26:51 -0700, bo**@stanford.edu (F. Edward Boas) wrote:
How can you check to see if a type is built-in or typedef'ed?

You can check whether a type is built-in by checking for all
built-in types (this list is not necessarily limited to the
C types); use template classes for this.

You cannot check whether a C++ type is a typedef, because a
C++ typedef just introduces an alternate _name_ for a type.

A typedef behaves differently in the language D.
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Lorn | last post: by
6 posts views Thread by Martin Johansen | last post: by
30 posts views Thread by stephen henry | last post: by
15 posts views Thread by Merrill & Michele | last post: by
10 posts views Thread by Kenneth Brody | last post: by
134 posts views Thread by jacob navia | last post: by
12 posts views Thread by Thomas Carter | last post: by
15 posts views Thread by informativeguy | last post: by
reply views Thread by lumer26 | last post: by

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.