Does your favorite C++ compiler support 64-bit integer types?

Discussion in 'C++' started by Matt, Apr 13, 2004.

  1. Matt

    Matt Guest

    Please skip to the last paragraph if you are in a hurry.

    Some of the integer variables in my application will need to hold values
    bigger than 2^32-1.

    Others won't need to be that big. Time and space efficiencies on
    run-of-the-mill (read: 32 bit) microcomputers are important.

    I want to use some layer of abstraction comparable to C99's stdint.h so
    that my variable declarations specify the number of bits.

    My app is to run on general-purpose hardware on Linux, Mac, BSD, and
    Windows.

    I am more interested in practical portability than in ISO standards.
    Also it seems to be irrelevant whether the 64-bit type is long or long long.

    Which C++ compilers do and which do not have 64-bit integer types? And
    do they have something like stdint.h?
    Matt, Apr 13, 2004
    #1
    1. Advertising

  2. Matt

    David Harmon Guest

    On Tue, 13 Apr 2004 21:19:04 GMT in comp.lang.c++, Matt
    <> wrote,
    >Which C++ compilers do and which do not have 64-bit integer types? And
    >do they have something like stdint.h?


    Digital Mars C++ http://www.digitalmars.com
    has "long long" and stdint.h.
    David Harmon, Apr 13, 2004
    #2
    1. Advertising

  3. Matt

    John Carson Guest

    "Matt" <> wrote in message
    news:cPYec.1041$
    > Please skip to the last paragraph if you are in a hurry.
    >
    > Some of the integer variables in my application will need to hold
    > values bigger than 2^32-1.
    >
    > Others won't need to be that big. Time and space efficiencies on
    > run-of-the-mill (read: 32 bit) microcomputers are important.
    >
    > I want to use some layer of abstraction comparable to C99's stdint.h
    > so that my variable declarations specify the number of bits.
    >
    > My app is to run on general-purpose hardware on Linux, Mac, BSD, and
    > Windows.
    >
    > I am more interested in practical portability than in ISO standards.
    > Also it seems to be irrelevant whether the 64-bit type is long or
    > long long.
    >
    > Which C++ compilers do and which do not have 64-bit integer types?
    > And
    > do they have something like stdint.h?


    Microsofts has a 64 bit data type, though I think it is less efficient than
    the 32 bit integer type. The various types (besides the usual int etc.) are
    listed here.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/win64/win64/the_new_data_types.asp


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)
    John Carson, Apr 13, 2004
    #3
  4. Matt

    Matt Guest

    David Harmon wrote:
    > On Tue, 13 Apr 2004 21:19:04 GMT in comp.lang.c++, Matt
    > <> wrote,
    >
    >>Which C++ compilers do and which do not have 64-bit integer types? And
    >>do they have something like stdint.h?

    >
    >
    > Digital Mars C++ http://www.digitalmars.com
    > has "long long" and stdint.h.
    >


    And its long long is 64 bits?
    Matt, Apr 13, 2004
    #4
  5. "Matt" <> wrote in message
    news:cPYec.1041$...
    > Please skip to the last paragraph if you are in a hurry.
    >
    > Some of the integer variables in my application will need to hold values
    > bigger than 2^32-1.
    >
    > Others won't need to be that big. Time and space efficiencies on
    > run-of-the-mill (read: 32 bit) microcomputers are important.
    >
    > I want to use some layer of abstraction comparable to C99's stdint.h so
    > that my variable declarations specify the number of bits.



    You can easily define your own class. I also assume that there must be some
    third party free library out there provoding an 64-bit type.

    Or you can use a system-specific type like __int64 in .NET.


    > My app is to run on general-purpose hardware on Linux, Mac, BSD, and
    > Windows.
    >
    > I am more interested in practical portability than in ISO standards.
    > Also it seems to be irrelevant whether the 64-bit type is long or long

    long.


    There isn't long long in standard C++. Portability can be maintained by
    using a typedef for built in system-specific types. For example you could
    do:


    typedef __int 64 Int64

    // ...

    and change the typedef when you move to another system. The general rule is
    "isolate system dependencies in a small portion of the code". You can create
    a header file called
    system_dependencies.h or something.


    >
    > Which C++ compilers do and which do not have 64-bit integer types? And
    > do they have something like stdint.h?



    How many compilers exist out there? How many versions of them? The question
    is meaningless. You can basically tell us what OS you are using. For Windows
    a nice free port of GCC supporting Win32 API is mingw:

    http://www.mingw.org/

    If you want it integrated with an IDE you can download Dev-C++:
    http://www.bloodshed.net/devcpp.html






    Ioannis Vranos
    Ioannis Vranos, Apr 13, 2004
    #5
  6. In the Visual Studio 2005 tech preview Microsoft is giving out,
    long long is supported and is the same as __int64.
    Chuck McDevitt, Apr 13, 2004
    #6
  7. Matt

    David Harmon Guest

    On Tue, 13 Apr 2004 22:07:48 GMT in comp.lang.c++, Matt
    <> wrote,
    >David Harmon wrote:
    >> On Tue, 13 Apr 2004 21:19:04 GMT in comp.lang.c++, Matt
    >> <> wrote,
    >>
    >>>Which C++ compilers do and which do not have 64-bit integer types? And
    >>>do they have something like stdint.h?

    >>
    >>
    >> Digital Mars C++ http://www.digitalmars.com
    >> has "long long" and stdint.h.
    >>

    >
    >And its long long is 64 bits?


    Yes. I thought I implied that. It would certainly violate expectations
    if it was anything less.

    Using free command line DMC++ with accompanying stlport library.
    Program:

    #include <iostream>
    int main()
    {
    int j = 0;
    long long int i = 0;
    do {
    i = (i << 1) + 1;
    ++j;
    std::cout << j << " " << i << '\n';
    } while (i > 0);
    }

    Output:

    1 1
    2 3
    3 7
    4 15
    5 31
    6 63
    7 127
    8 255
    9 511
    10 1023
    11 2047
    12 4095
    13 8191
    14 16383
    15 32767
    16 65535
    17 131071
    18 262143
    19 524287
    20 1048575
    21 2097151
    22 4194303
    23 8388607
    24 16777215
    25 33554431
    26 67108863
    27 134217727
    28 268435455
    29 536870911
    30 1073741823
    31 2147483647
    32 4294967295
    33 8589934591
    34 17179869183
    35 34359738367
    36 68719476735
    37 137438953471
    38 274877906943
    39 549755813887
    40 1099511627775
    41 2199023255551
    42 4398046511103
    43 8796093022207
    44 17592186044415
    45 35184372088831
    46 70368744177663
    47 140737488355327
    48 281474976710655
    49 562949953421311
    50 1125899906842623
    51 2251799813685247
    52 4503599627370495
    53 9007199254740991
    54 18014398509481983
    55 36028797018963967
    56 72057594037927935
    57 144115188075855871
    58 288230376151711743
    59 576460752303423487
    60 1152921504606846975
    61 2305843009213693951
    62 4611686018427387903
    63 9223372036854775807
    64 -1
    David Harmon, Apr 13, 2004
    #7
  8. Matt

    David Harmon Guest

    Here is a brain teaser for anyone who might be interested.
    The following numbers (in the second column) all end with the digit
    1, 3, 5, or 7. It's obvious why they are all odd. Why can the last
    digit never be 9, even if you extended the sequence?


    On Tue, 13 Apr 2004 22:57:45 GMT in comp.lang.c++, David Harmon
    <> wrote,
    >Program:
    >
    >#include <iostream>
    >int main()
    >{
    > int j = 0;
    > long long int i = 0;
    > do {
    > i = (i << 1) + 1;
    > ++j;
    > std::cout << j << " " << i << '\n';
    > } while (i > 0);
    >}
    >
    >Output:
    >
    >1 1
    >2 3
    >3 7
    >4 15
    >5 31
    >6 63
    >7 127
    >8 255
    >9 511
    >10 1023
    >11 2047
    >12 4095
    >13 8191
    >14 16383
    >15 32767
    >16 65535
    >17 131071
    >18 262143
    >19 524287
    >20 1048575
    >21 2097151
    >22 4194303
    >23 8388607
    >24 16777215
    >25 33554431
    >26 67108863
    >27 134217727
    >28 268435455
    >29 536870911
    >30 1073741823
    >31 2147483647
    >32 4294967295
    >33 8589934591
    >34 17179869183
    >35 34359738367
    >36 68719476735
    >37 137438953471
    >38 274877906943
    >39 549755813887
    >40 1099511627775
    >41 2199023255551
    >42 4398046511103
    >43 8796093022207
    >44 17592186044415
    >45 35184372088831
    >46 70368744177663
    >47 140737488355327
    >48 281474976710655
    >49 562949953421311
    >50 1125899906842623
    >51 2251799813685247
    >52 4503599627370495
    >53 9007199254740991
    >54 18014398509481983
    >55 36028797018963967
    >56 72057594037927935
    >57 144115188075855871
    >58 288230376151711743
    >59 576460752303423487
    >60 1152921504606846975
    >61 2305843009213693951
    >62 4611686018427387903
    >63 9223372036854775807
    >64 -1
    David Harmon, Apr 14, 2004
    #8
  9. Matt

    John Carson Guest

    "David Harmon" <> wrote in message
    news:
    > Here is a brain teaser for anyone who might be interested.
    > The following numbers (in the second column) all end with the digit
    > 1, 3, 5, or 7. It's obvious why they are all odd. Why can the last
    > digit never be 9, even if you extended the sequence?


    i = (i << 1) + 1;

    translates to

    i = i*2 +1;

    This is a first order difference equation with solution (given the initial
    condition)

    i_n = 2^n - 1

    where i_n is the nth term in the sequence and ^ denotes exponent.
    (Alternatively, you are forming each successive number by left-shifting and
    adding 1, which means that you have a binary number consisting solely of 1s.
    Such numbers are of the form 2^n - 1.)

    For a number to end in 9, we would need:

    2^n - 1 == K*10 + 9

    for some integers n and K. Adding 1 to both sides

    2^n == K*10 + 10

    or

    2^n == (K+1)*10

    Dividing both sides by 2:

    2^(n-1) == (K+1)*5

    We see that the left hand side has 2 as its only prime factor, whereas the
    right hand side has 5 as a prime factor. By the unique prime factorisation
    theorem, this is impossible if the left and right hand sides are equal. This
    shows the equality is impossible. QED.


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)
    John Carson, Apr 14, 2004
    #9
  10. Matt

    Matt Guest

    David Harmon wrote:
    > Here is a brain teaser for anyone who might be interested.
    > The following numbers (in the second column) all end with the digit
    > 1, 3, 5, or 7. It's obvious why they are all odd. Why can the last
    > digit never be 9, even if you extended the sequence?


    It would imply that some power of two is divisible by five.
    Matt, Apr 14, 2004
    #10
  11. Matt

    David Harmon Guest

    On Wed, 14 Apr 2004 11:04:03 +1000 in comp.lang.c++, "John Carson"
    <> wrote,
    ....
    >By the unique prime factorisation theorem, this is
    >impossible if the left and right hand sides are equal.
    >This shows the equality is impossible. QED.


    Yep.
    David Harmon, Apr 14, 2004
    #11
  12. "Matt" <> wrote in message
    news:cPYec.1041$...
    > Please skip to the last paragraph if you are in a hurry.
    >
    > Some of the integer variables in my application will need to hold values
    > bigger than 2^32-1.
    >
    > Others won't need to be that big. Time and space efficiencies on
    > run-of-the-mill (read: 32 bit) microcomputers are important.
    >
    > I want to use some layer of abstraction comparable to C99's stdint.h so
    > that my variable declarations specify the number of bits.
    >
    > My app is to run on general-purpose hardware on Linux, Mac, BSD, and
    > Windows.
    >
    > I am more interested in practical portability than in ISO standards.
    > Also it seems to be irrelevant whether the 64-bit type is long or long

    long.
    >
    > Which C++ compilers do and which do not have 64-bit integer types? And
    > do they have something like stdint.h?
    >


    It is not a question of compilers.
    If the platform does not have 64 bit operations the compiler for it will not
    have 64 bit types even if it supports long long. (ie long long will be less
    than 64 bits).
    If it does have 64 bit operations then the type will almost certainly be
    long.
    I would only expect long long to differ from long if the machine has either:
    1. support for 32, 64 and 128 bit
    2. A 'natural' int size of 16 + support for 32 and 64 bit
    I don't know of any common processor that fits either of these
    descriptions - in the first case long would be enough for you anyway and I
    doubt that the second ever existed.

    In summary: the question is:
    Does anyone know of any platform where long < 64 bits and long long >= 64
    bits?
    Nick Hounsome, Apr 14, 2004
    #12
  13. Matt

    John Carson Guest

    "Nick Hounsome" <> wrote in message
    news:vT5fc.124$
    > It is not a question of compilers.


    Actually, it is since compilers can extend (or restrict) what is available
    on a given system.

    > If the platform does not have 64 bit operations the compiler for it
    > will not have 64 bit types even if it supports long long. (ie long
    > long will be less than 64 bits).
    > If it does have 64 bit operations then the type will almost certainly
    > be long.
    > I would only expect long long to differ from long if the machine has
    > either:
    > 1. support for 32, 64 and 128 bit
    > 2. A 'natural' int size of 16 + support for 32 and 64 bit
    > I don't know of any common processor that fits either of these
    > descriptions - in the first case long would be enough for you anyway
    > and I doubt that the second ever existed.
    >
    > In summary: the question is:
    > Does anyone know of any platform where long < 64 bits and long long
    > >= 64 bits?



    On VC++ for standard Intel Pentium (or 486) processors running Windows, long
    is 32 bits and long long is 64 bits.

    http://msdn.microsoft.com/library/d...-us/vclang/html/_langref_data_type_ranges.asp


    --
    John Carson
    1. To reply to email address, remove donald
    2. Don't reply to email address (post here instead)
    John Carson, Apr 14, 2004
    #13
  14. On Tue, 13 Apr 2004 21:19:04 +0000, Matt wrote:

    > I am more interested in practical portability than in ISO standards.
    > Also it seems to be irrelevant whether the 64-bit type is long or long long.
    >
    > Which C++ compilers do and which do not have 64-bit integer types? And
    > do they have something like stdint.h?


    Something like this may work if you really want it portable:

    #if <some magic to detect 64bit long>
    typedef long my64bit_t;
    #elif <some magic to detect 64 bit long long>
    typedef long long my64bit_t;
    #elif <some magic to detect 64 bit int>
    typedef int my64bit_t;
    #else
    class my64bit_t {
    public:
    my64bit_t();
    my64bit_t(long x);
    my64bit_t(unsigned char* bytes);
    ...

    my64bit_t operator +(my64bit_t a, my64bit_t b);

    ...
    my64bit_t operator << (my64bit_t a, int n);
    ...
    private:
    unsigned char data[8]; /* assuming 8 bit bytes */
    };

    /* or perhaps just #include <bigintlibrary.h> and then a single
    typedef */
    #endif

    --
    NPV

    "the large print giveth, and the small print taketh away"
    Tom Waits - Step right up
    Nils Petter Vaskinn, Apr 14, 2004
    #14
  15. > Which C++ compilers do and which do not have 64-bit integer types?

    The Borland and Microsoft C++ compilers have the __int64 type and if I
    remember correctly GCC has the long long type.

    --
    Peter van Merkerk
    peter.van.merkerk(at)dse.nl
    Peter van Merkerk, Apr 14, 2004
    #15
  16. Matt

    Matt Guest

    Nick Hounsome wrote:
    > "Matt" <> wrote in message
    > news:cPYec.1041$...
    >
    >>Please skip to the last paragraph if you are in a hurry.
    >>
    >>Some of the integer variables in my application will need to hold values
    >>bigger than 2^32-1.
    >>
    >>Others won't need to be that big. Time and space efficiencies on
    >>run-of-the-mill (read: 32 bit) microcomputers are important.
    >>
    >>I want to use some layer of abstraction comparable to C99's stdint.h so
    >>that my variable declarations specify the number of bits.
    >>
    >>My app is to run on general-purpose hardware on Linux, Mac, BSD, and
    >>Windows.
    >>
    >>I am more interested in practical portability than in ISO standards.
    >>Also it seems to be irrelevant whether the 64-bit type is long or long

    >
    > long.
    >
    >>Which C++ compilers do and which do not have 64-bit integer types? And
    >>do they have something like stdint.h?
    >>

    >
    >
    > It is not a question of compilers.
    > If the platform does not have 64 bit operations the compiler for it will not
    > have 64 bit types even if it supports long long. (ie long long will be less
    > than 64 bits).
    > If it does have 64 bit operations then the type will almost certainly be
    > long.
    > I would only expect long long to differ from long if the machine has either:
    > 1. support for 32, 64 and 128 bit
    > 2. A 'natural' int size of 16 + support for 32 and 64 bit
    > I don't know of any common processor that fits either of these
    > descriptions - in the first case long would be enough for you anyway and I
    > doubt that the second ever existed.
    >
    > In summary: the question is:
    > Does anyone know of any platform where long < 64 bits and long long >= 64
    > bits?


    A person is lucky when he has a real expert to help him ask the right
    question.
    Matt, Apr 14, 2004
    #16
  17. "Nick Hounsome" <> wrote in message
    news:vT5fc.124$...
    >
    > In summary: the question is:
    > Does anyone know of any platform where long < 64 bits and long long >= 64
    > bits?


    GCC.


    For Windows a nice free port of GCC supporting Win32 API is mingw:
    http://www.mingw.org/


    If you want it integrated with an IDE you can download Dev-C++:
    http://www.bloodshed.net/devcpp.html






    Ioannis Vranos
    Ioannis Vranos, Apr 14, 2004
    #17
  18. "Ioannis Vranos" <> wrote in message
    news:c5jm0f$b8f$...
    > "Nick Hounsome" <> wrote in message
    > news:vT5fc.124$...
    > >
    > > In summary: the question is:
    > > Does anyone know of any platform where long < 64 bits and long long >=

    64
    > > bits?

    >
    > GCC.


    gcc isn't a platform - it's just a compiler.
    The size of long and long long varies with the target processor.
    Nick Hounsome, Apr 14, 2004
    #18
  19. Matt

    Bill Seurer Guest

    Ioannis Vranos wrote:

    > "Nick Hounsome" <> wrote in message
    > news:vT5fc.124$...
    >
    >>In summary: the question is:
    >>Does anyone know of any platform where long < 64 bits and long long >= 64
    >>bits?

    >
    > GCC.


    The native compilers on AIX and iSeries.
    Bill Seurer, Apr 14, 2004
    #19
  20. Matt

    Matt Guest

    Nick Hounsome wrote:

    > gcc isn't a platform - it's just a compiler.
    > The size of long and long long varies with the target processor.


    Define 'platform'.
    Matt, Apr 14, 2004
    #20
    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. clintonG

    Your Favorite RegEx Library?

    clintonG, Oct 8, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    374
    Frankie
    Oct 8, 2005
  2. clintonG
    Replies:
    8
    Views:
    500
    =?Utf-8?B?TWFyZHk=?=
    Jan 11, 2006
  3. pembed2003

    Your favorite C++ books?

    pembed2003, Jun 12, 2004, in forum: C++
    Replies:
    2
    Views:
    416
    Prateek R Karandikar
    Jun 12, 2004
  4. Samuel Barber
    Replies:
    382
    Views:
    5,006
    Brian Inglis
    Aug 25, 2004
  5. Carl Lerche

    Your favorite bit of ruby code?

    Carl Lerche, Feb 8, 2007, in forum: Ruby
    Replies:
    32
    Views:
    312
    John Carter
    Feb 10, 2007
Loading...

Share This Page