Any integer number is always 32 bits

Discussion in 'C++' started by Nephi Immortal, May 14, 2012.

  1. 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;
    }
    Nephi Immortal, May 14, 2012
    #1
    1. Advertising

  2. On May 13, 5: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?
    >
    >         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
    Kevin McCarty, May 14, 2012
    #2
    1. Advertising

  3. Nephi Immortal

    Ian Collins Guest

    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
    Ian Collins, May 14, 2012
    #3
    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. sarmin kho
    Replies:
    2
    Views:
    823
    A. Lloyd Flanagan
    Jun 15, 2004
  2. Miki Tebeka
    Replies:
    1
    Views:
    442
    Marcin 'Qrczak' Kowalczyk
    Jun 14, 2004
  3. Frank Buss
    Replies:
    3
    Views:
    4,060
    Mike Treseler
    Jul 31, 2006
  4. Mack

    Count number of bits set in a number

    Mack, Sep 27, 2007, in forum: C Programming
    Replies:
    12
    Views:
    809
    Mark Bluemel
    Sep 28, 2007
  5. Richard Heathfield

    Finding number of bits of integer

    Richard Heathfield, Oct 18, 2007, in forum: C Programming
    Replies:
    29
    Views:
    871
    Charlie Gordon
    Oct 25, 2007
Loading...

Share This Page