Any integer number is always 32 bits

N

Nephi Immortal

If C++ Compiler for 32 bits and 64 bits are same, why do integer
numbers are set to 32 bits in C++ Compiler for 64 bits?

The documentation from MSDN says that the int type is always 32 bits
on 32 bit machine and 64 bit machine.

What happen when you place integer number in the function parameter?
The C++ Compiler always treats any integer number to int type instead
of long in 32 bits or long long in 64 bits.

I will hate to place (long long) before integer number in function
parameter manually.


void Xx( char x ) {}
void Xx( short x ) {}
void Xx( long x ) {}
void Xx( long long x ) {}
void Xx( int x ) {}

void Xx( unsigned char x ) {}
void Xx( unsigned short x ) {}
void Xx( unsigned long x ) {}
void Xx( unsigned long long x ) {}
void Xx( unsigned int x ) {}


int main()
{
Xx( 2 ); // Invoke Xx( int x )
Xx( 2L ); // Invoke Xx( long x )
Xx( 2U ); // Invoke Xx( unsigned int x )
Xx( 2UL ); // Invoke Xx( unsigned long x )

Xx( (long long) 2 ); // Invoke Xx( long long x )

return 0;
}
 
K

Kevin McCarty

        If C++ Compiler for 32 bits and 64 bits are same, why do integer
numbers are set to 32 bits in C++ Compiler for 64 bits?

        The documentation from MSDN says that the int type is always 32 bits
on 32 bit machine and 64 bit machine.

Yes, this is known as either the "LP64" or "LLP64" model on 64-bit
architectures (depending on whether the size of 'long' is 64 or 32
bits, respectively -- GCC on 64-bit Linux uses the former, and Visual C
++ the latter).

A good rationale for compilers using LP64 or LLP64 is that if one
instead used the ILP64 model (where 'int' is also 64 bits), then there
would not be enough different standard integer types to ensure the
existence of standard types having a size of 16 bits.

Consider that a compiler defining 'int' as 64 bits would presumably
keep 'char' at 8 bits... then the compiler writers would have to
choose between having a 'short' type of either 16 or 32 bits, without
having any standardized name for the other size. (I suppose that in
C99 or C++11 it could just be called (u)int32_t or (u)int16_t,
respectively, but I don't think those names were available when the
first 64-bit compilers were being written.)

        What happen when you place integer number in the functionparameter?
The C++ Compiler always treats any integer number to int type instead
of long in 32 bits or long long in 64 bits.

        I will hate to place (long long) before integer number infunction
parameter manually.
        Xx( (long long) 2 ); // Invoke Xx( long long x )


On a compiler with support for (unsigned) long long types, you can use
one of

Xx(2LL); // Xx(long long x)
Xx(2ULL); // Xx(unsigned long long x)

- Kevin B. McCarty
 
I

Ian Collins

If C++ Compiler for 32 bits and 64 bits are same, why do integer
numbers are set to 32 bits in C++ Compiler for 64 bits?

Because that's what the platform ABI specifies.
The documentation from MSDN says that the int type is always 32 bits
on 32 bit machine and 64 bit machine.

What happen when you place integer number in the function parameter?
The C++ Compiler always treats any integer number to int type instead
of long in 32 bits or long long in 64 bits.
Correct.

I will hate to place (long long) before integer number in function
parameter manually.

if the parameter is a long long, the value will be promoted.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top