typedef and #ifdef

Discussion in 'C++' started by F. Edward Boas, Aug 11, 2003.

  1. 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
    #endif

    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?
     
    F. Edward Boas, Aug 11, 2003
    #1
    1. Advertising

  2. On 11 Aug 2003 10:26:51 -0700, (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.
     
    Alf P. Steinbach, Aug 11, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Torek

    Re: defined(name) vs #ifdef AND #ifndef

    Chris Torek, Jul 2, 2003, in forum: C Programming
    Replies:
    0
    Views:
    807
    Chris Torek
    Jul 2, 2003
  2. Keith Thompson

    Re: defined(name) vs #ifdef AND #ifndef

    Keith Thompson, Jul 2, 2003, in forum: C Programming
    Replies:
    0
    Views:
    4,405
    Keith Thompson
    Jul 2, 2003
  3. Kenneth Porter

    scpp and expanding ifdef's

    Kenneth Porter, Oct 11, 2003, in forum: C Programming
    Replies:
    3
    Views:
    1,046
    Alan Balmer
    Oct 13, 2003
  4. baumann@pan
    Replies:
    1
    Views:
    746
    Richard Bos
    Apr 15, 2005
  5. oor
    Replies:
    0
    Views:
    1,357
Loading...

Share This Page