Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Any integer number is always 32 bits

Reply
Thread Tools

Any integer number is always 32 bits

 
 
Nephi Immortal
Guest
Posts: n/a
 
      05-14-2012
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;
}
 
Reply With Quote
 
 
 
 
Kevin McCarty
Guest
Posts: n/a
 
      05-14-2012
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
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      05-14-2012
On 05/14/12 12:05 PM, Nephi Immortal 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?


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.

--
Ian Collins
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding number of bits of integer Richard Heathfield C Programming 29 10-25-2007 01:14 PM
501 PIX "deny any any" "allow any any" Any Anybody? Networking Student Cisco 4 11-16-2006 10:40 PM
what about unsigned and signed 8 bits number, 16 bits, etc?? sarmin kho Python 2 06-15-2004 06:40 PM
Re: what about unsigned and signed 8 bits number, 16 bits, etc?? Miki Tebeka Python 1 06-14-2004 03:19 PM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57