Integer Literal Question

N

Nephi Immortal

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;
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top