您的位置:首页 > 编程语言 > C语言/C++

[C/C++]_[判断程序是32位还是64位]

2016-03-28 12:54 489 查看
http://blog.csdn.net/infoworld/article/details/10958583

场景:

1.编译器没有显式的指定。

2.需要根据32,64做不同的处理.

方法1:

[cpp] view
plain copy

#include "stdio.h"  

  

int main(int argc,char * argv[])  

{  

    void* number =  0;  

    printf("%d\n",sizeof(&number));  

}  

输出8就是64位的,4就是32位的。根据逻辑地址判断。

方法2:

可以用file命令判断(如果安装了msys的话,linux下应该自带)

file msys-expat-1.dll

[plain] view
plain copy

msys-expat-1.dll: PE executable for MS Windows (DLL) (console) Intel 80386 32-bi  

t  

方法3:

[plain] view
plain copy

If you have a hex editor program, just open your file with it and shortly after the standard header intro stuff (like  

 "This program cannot be run in DOS mode...") you will see either  

"PE..L" (hex code: 504500004C) = 32 bit  

or  

"PE..d†" (hex code: 504500006486) = 64 bit  

  

随手UE打开了两个exe,果然有效。但是这个50450000????的位置不确定,大致在00000100h附近。  

  

另 exe 文件头的典型提示字串未必统一。如一个是This program cannot be run in DOS mode,另一个是  

This program must be run under Win32  

  原文

方法4:

vs的工具dumpbin,参数/HEADERS

64 bit

[plain] view
plain copy

E:\software\TDM-GCC-64\bin>dumpbin /HEADERS libgcc_s_seh_64-1.dll  

Microsoft (R) COFF/PE Dumper Version 10.00.40219.01  

Copyright (C) Microsoft Corporation.  All rights reserved.  

  

  

Dump of file libgcc_s_seh_64-1.dll  

  

PE signature found  

  

File Type: DLL  

  

FILE HEADER VALUES  

            8664 machine (x64)  

32 bit

[plain] view
plain copy

E:\software\TDM-GCC-64\bin>dumpbin /HEADERS g++.exe  

Microsoft (R) COFF/PE Dumper Version 10.00.40219.01  

Copyright (C) Microsoft Corporation.  All rights reserved.  

  

  

Dump of file g++.exe  

  

PE signature found  

  

File Type: EXECUTABLE IMAGE  

  

FILE HEADER VALUES  

             14C machine (x86)  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: