Integer Literal Question

Discussion in 'C++' started by Nephi Immortal, Dec 28, 2012.

  1. I would like to ask a question about integer literal.

    Let's see my example below. I wonder if the suffix i(n) is the standard C++ Compiler and is compatible to portable ANSI or is it Microsoft extension?

    If the integer in the range 0 through 65535, then int type is chosen on 32 bit machine or long long type on 64 bit machine.

    void Do( char x ) {}
    void Do( signed char x ) {} // never used unless you declare (signed char) name
    void Do( unsigned char x ) {}

    void Do( wchar_t x ) {}

    void Do( signed short x ) {}
    void Do( unsigned short x ) {}

    void Do( signed int x ) {}
    void Do( unsigned int x ) {}

    void Do( signed long x ) {}
    void Do( unsigned long x ) {}

    void Do( signed long long x ) {}
    void Do( unsigned long long x ) {}

    int main()
    {
    Do( 'a' ); // call Do( char x )
    Do( L'a' ); // call Do( wchar_t x )

    Do( 0x7F ); // call Do( signed int x )
    Do( 0x7FFF ); // call Do( signed int x )
    Do( 0x7FFFFFFF ); // call Do( signed int x )
    Do( 0x80000000 ); // call Do( unsigned int x ) on 32-bit machine
    Do( 0x80000000 ); // call Do( signed long long x ) on 64-bit machine

    Do( 0x7FFFFFFFFFFFFFFF ); // call Do( signed long long x )

    Do( 0x80i8 ); // call Do( char x )
    Do( 0x8000i16 ); // call Do( signed short x )
    Do( 0x80000000i32 ); // call Do( signed int x )
    Do( 0x8000000000000000i64 ); // call Do( signed long long x )

    Do( 0x80ui8 ); // call Do( unsigned char x )
    Do( 0x8000ui16 ); // call Do( unsigned short x )
    Do( 0x80000000ui32 ); // call Do( unsigned int x )
    Do( 0x8000000000000000ui64 ); // call Do( unsigned long long x )

    Do( 0x7Fl ); // call Do( signed long x )
    Do( 0x7FFFl ); // call Do( signed long x )
    Do( 0x7FFFFFFFl ); // call Do( signed long x )

    Do( 0x7Fll ); // call Do( signed long long x )
    Do( 0x7FFFll ); // call Do( signed long long x )
    Do( 0x7FFFFFFFll ); // call Do( signed long long x )

    return 0;
    }
     
    Nephi Immortal, Dec 28, 2012
    #1
    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. =?Utf-8?B?Sm9l?=

    CType(x,Integer) vs. Integer.Parse(x)

    =?Utf-8?B?Sm9l?=, Feb 6, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,966
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Feb 7, 2006
  2. =?ISO-8859-1?Q?Thomas_Gagn=E9?=

    No Math.min(Integer, Integer)?

    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Jul 29, 2003, in forum: Java
    Replies:
    0
    Views:
    521
    =?ISO-8859-1?Q?Thomas_Gagn=E9?=
    Jul 29, 2003
  3. Zach
    Replies:
    3
    Views:
    5,561
    Mike Wahler
    Dec 12, 2004
  4. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    392
    Anonieko Ramos
    Sep 27, 2004
  5. John Reye
    Replies:
    14
    Views:
    799
    Tim Rentsch
    May 8, 2012
Loading...

Share This Page