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. Advertisements

  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. Advertisements

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. Replies:
    0
    Views:
    696
  2. Keith Thompson

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

    Keith Thompson, Jul 2, 2003, in forum: C Programming
    Replies:
    0
    Views:
    4,664
    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,195
    Alan Balmer
    Oct 13, 2003
  4. baumann@pan
    Replies:
    1
    Views:
    982
    Richard Bos
    Apr 15, 2005
  5. ClownPleco

    putenv for AIX and ifdef for AIX

    ClownPleco, Aug 22, 2007, in forum: C Programming
    Replies:
    5
    Views:
    1,462
    Thomas Dickey
    Aug 24, 2007
  6. oor
    Replies:
    0
    Views:
    1,677
  7. Mug
    Replies:
    10
    Views:
    2,318
    James Kanze
    Aug 25, 2009
  8. Fren Zeee
    Replies:
    4
    Views:
    820
    Emmy Noether
    Aug 5, 2010
Loading...