“首选 32 位"的目的是什么?在 Visual Studio 中设置,它实际上是如何工作的? [英] What is the purpose of the "Prefer 32-bit" setting in Visual Studio and how does it actually work?

查看:34
本文介绍了“首选 32 位"的目的是什么?在 Visual Studio 中设置,它实际上是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不清楚编译器如何在需要时自动知道编译为 64 位.它如何知道何时可以自信地瞄准 32 位?

It is unclear to me how the compiler will automatically know to compile for 64-bit when it needs to. How does it know when it can confidently target 32-bit?

我主要好奇编译器在编译时如何知道要针对哪个架构.它会分析代码并根据发现的内容做出决定吗?

I am mainly curious about how the compiler knows which architecture to target when compiling. Does it analyze the code and make a decision based on what it finds?

推荐答案

微软有一个博客条目 .NET 4.5 和 Visual Studio 11 中 AnyCPU 的真正含义:

Microsoft has a blog entry What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11:

在 .NET 4.5 和 Visual Studio 11 中,奶酪已被移动.这大多数 .NET 项目的默认值仍然是 AnyCPU,但有超过现在对 AnyCPU 的一种意义.AnyCPU还有一个额外的子类型,任何 CPU 32 位首选",这是新的默认设置(总体而言,有现在是/platform C# 编译器开关的五个选项:x86,Itanium、x64、anycpu 和 anycpu32bit 优先).使用首选 32 位"时AnyCPU的味道,语义如下:

In .NET 4.5 and Visual Studio 11 the cheese has been moved. The default for most .NET projects is again AnyCPU, but there is more than one meaning to AnyCPU now. There is an additional sub-type of AnyCPU, "Any CPU 32-bit preferred", which is the new default (overall, there are now five options for the /platform C# compiler switch: x86, Itanium, x64, anycpu, and anycpu32bitpreferred). When using the "Prefer 32-Bit" flavor of AnyCPU, the semantics are as follows:

  • 如果进程在 32 位 Windows 系统上运行,它将作为 32 位进程运行.IL 被编译成 x86 机器码.
  • 如果进程在 64 位 Windows 系统上运行,它将作为 32 位进程运行.IL 被编译成 x86 机器码.
  • 如果进程在 ARM Windows 系统上运行,它将作为 32 位进程运行.IL 被编译为 ARM 机器代码.

那么,任何 CPU 32 位首选"和x86"之间的区别是只有这样:编译为 x86 的 .NET 应用程序将无法在ARM Windows 系统,但任何 CPU 32 位首选"应用程序将运行成功.

这篇关于“首选 32 位"的目的是什么?在 Visual Studio 中设置,它实际上是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆