sizeof(long) in 64-bit C++

前端 未结 6 1371
清歌不尽
清歌不尽 2020-12-05 18:21

I have downloaded MinGW-64, so I can now compile 64-bit programs for Windows 7, using g++ 4.7.0 (experimental). But the following line:

cout << sizeof(         


        
6条回答
  •  北海茫月
    2020-12-05 18:55

    On the microsoft windows OS you have LLP64 so the size of long is 32 bit. (see the table below)

    Quote from wikipedia:

    In 32-bit programs, pointers and data types such as integers generally have the same length; this is not necessarily true on 64-bit machines. Mixing data types in programming languages such as C and its descendants such as C++ and Objective-C may thus function on 32-bit implementations but not on 64-bit implementations. In many programming environments for C and C-derived languages on 64-bit machines, "int" variables are still 32 bits wide, but long integers and pointers are 64 bits wide. These are described as having an LP64 data model. Another alternative is the ILP64 data model in which all three data types are 64 bits wide, and even SILP64 where "short" integers are also 64 bits wide. However, in most cases the modifications required are relatively minor and straightforward, and many well-written programs can simply be recompiled for the new environment without changes. Another alternative is the LLP64 model, which maintains compatibility with 32-bit code by leaving both int and long as 32-bit. "LL" refers to the "long long integer" type, which is at least 64 bits on all platforms, including 32-bit environments.

    Type           ILP64   LP64   LLP64
    char              8      8       8
    short            16     16      16
    int              64     32      32
    long             64     64      32
    long long        64     64      64
    pointer          64     64      64
    

提交回复
热议问题