__int64のサイズ

メモ

  • Intel Compiler、Visual C++ では __int64が定義されている。
  • GCC(少なくとも 4.6.3)では __int64は定義されていない。
icpc 12.1.0 32bit OS icpc 12.1.0 64 bit OS gcc 4.6.3 32bit OS gcc 4.4.6 64bit OS
__int64 8 byte 8 byte -- --
int 4 byte 8 byte 4 byte 8 byte
long 4 byte 8 byte 4 byte 8 byte
long long 8 byte 8 byte 8 byte 8 byte

追記

コメント欄でのご指摘があったので、上記の計測環境をご紹介。確かに、64bit OSかどうかは確かめていなかった。CPUが64bit対応なだけだった。

64bit OSと言っているのは、Intel(R) Xeon(R) CPU L5420 @ 2.50GHzのハードの話。インストールしているのはCentOS 6.3。

% uname -a
Linux HOSTNAME 2.6.32-279.14.1.el6.x86_64 #1 SMP Tue Nov 6 23:43:09 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

% more /etc/redhat-release 
CentOS release 6.3 (Final)

% gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
コンフィグオプション: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
スレッドモデル: posix
gcc version 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC) 

% which icpc 
/opt/intel/composer_xe_2011_sp1.7.256/bin/intel64/icpc

% icpc -v (64bit版
icpc バージョン 12.1.0 (gcc バージョン 4.4.6 互換)

32bit OSと言っているのは、VMWare上にインストールした Ubuntu 12.10。CPUは、Intel(R) Core(TM) i3 CPU 530 @ 2.93GHz。

% uname -a
Linux HOSTNAME 3.2.0-36-generic #57-Ubuntu SMP Tue Jan 8 21:41:24 UTC 2013 i686 i686 i386 GNU/Linux

% more /etc/debian_version 
wheezy/sid

% gcc -v
組み込み spec を使用しています。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
ターゲット: i686-linux-gnu
configure 設定: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
スレッドモデル: posix
gcc バージョン 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 

% which icpc
/opt/intel/composer_xe_2011_sp1.7.256/bin/ia32/icpc

% icpc -v
icpc バージョン 12.1.0 (gcc バージョン 4.6.0 互換)

上記の環境で以下のプログラムをg++とicpcでそれぞれコンパイルし、値をだした。

#include <iostream>

int main()
{
  std::cout << sizeof(int) <<' ' << sizeof(long) << ' ' << sizeof(long long) << 
std::endl;
  return 0;
}