On May 13, 5:05*pm, Nephi Immortal <immortalne...@gmail.com> wrote:
> * * * * 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
|