.net C# 为 32/64 位编译还是为任何 cpu 编译?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5229768/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# compiling for 32/64 bit, or for any cpu?
提问by helloworld922
Possible Duplicate:
Visual Studio “Any CPU” target
可能的重复:
Visual Studio“Any CPU”目标
I've noticed that when compiling C# code in VS, there's typically options for compiling for 32/64 bit systems, and there's also one for compiling for any cpu.
我注意到在 VS 中编译 C# 代码时,通常有针对 32/64 位系统编译的选项,也有针对任何 cpu 编译的选项。
What's the difference between the two options? Does choosing any CPU only compile down to an intermediate byte code while the first option compiles down to machine code (this sounds unlikely to me)? Or something else?
这两个选项有什么区别?选择任何 CPU 是否只编译为中间字节码,而第一个选项编译为机器码(这听起来不太可能)?或者是其他东西?
回答by Jaroslav Jandek
On a 32-bitmachine:
在32 位机器上:
Any CPU: runs as a 32-bit process, can load Any CPUand x86assemblies, will get
BadImageFormatExceptionif it tries to load an x64assembly.x86: same as Any CPU.
x64:
BadImageFormatExceptionalways.
任何 CPU:作为 32 位进程运行,可以加载任何 CPU和x86程序集,
BadImageFormatException如果它尝试加载x64程序集,就会得到。x86:与任何 CPU相同。
x64:
BadImageFormatException总是。
On a 64-bitmachine:
在64 位机器上:
Any CPU: runs as a 64-bit process, can load Any CPUand x64assemblies, will get
BadImageFormatExceptionif it tries to load an x86assembly.x86: runs as a 32-bit process, can load Any CPUand x86assemblies, will get
BadImageFormatExceptionif it tries to load an x64assembly.x64: same as Any CPU.
任何 CPU:作为 64 位进程运行,可以加载任何 CPU和x64程序集,
BadImageFormatException如果它尝试加载x86程序集,就会得到。x86:作为 32 位进程运行,可以加载任何 CPU和x86程序集,
BadImageFormatException如果它尝试加载x64程序集,则会得到。x64:与任何 CPU相同。
It is the JIT compilerthat generates an assembly code that's compatible with the requested target based on this flag.
正是JIT 编译器根据此标志生成与请求的目标兼容的汇编代码。
回答by Gilad
x86 - Your software will always run in 32bit mode, both on 32bit systems and 64bit systems.
x86 - 您的软件将始终以 32 位模式运行,无论是在 32 位系统还是 64 位系统上。
x64 - Your software will always run in 64bit mode, will run on 64bit system but won't run on 32bit system.
x64 - 您的软件将始终以 64 位模式运行,将在 64 位系统上运行但不会在 32 位系统上运行。
Any CPU - Your software will run according to your OS. if you have a 32bit OS you code will run in 32bit mode, if you have a 64bit OS your code will run in 64bit mode.
任何 CPU - 您的软件将根据您的操作系统运行。如果您使用的是 32 位操作系统,您的代码将以 32 位模式运行,如果您使用的是 64 位操作系统,您的代码将以 64 位模式运行。

