Thursday, April 12, 2012

This isn't your father's AnyCPU... VS11/.Net 4.5 introduces AnyCPU32BitPreferred. (32 | 64 bit) + Windows OS = x86 machine code. ARM OS = ARM Machine code

InfoQ - Microsoft Redefines AnyCPU for Visual Studio 11 and .NET 4.5

"Since the introduction of 64-bit computing, developers have had to manage the differences between 64-bit and 32-bit platforms. Microsoft provides C# developers on Visual Studio with the AnyCPU compiler setting. This setting allows developers to specify which common language runtime platform should be targeted, and the change will support the ARM architecture by default.


Now Microsoft is making changes and with VS 11 and .NET 4.5 the available options are:

  • x86
  • Itanium
  • x64
  • anycpu
  • anycpu32bitpreferred (default)

AnyCPU, 32 Bit is the new default under VS11. As developer and Microsoft MVP Sasha Goldshtein has noted, this is contrary to what VS11 displays on the project's properties screen (which shows AnyCPU as the default and does not allow AnyCPU, 32-bit to be selected).


DZone - What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11

"The 32-bit and 64-bit development story on Windows seemingly never stops causing problems for developers. It’s been a decade since 64-bit processors have started popping up in the Windows consumer environment, but we just can’t get it right. If you forget some of the gory details, here are a couple of reminders:

  • On a 64-bit Windows system, both the 32-bit and 64-bit versions of system DLLs are stored. The 64-bit DLLs are in C:\Windows\System32, and the 32-bit DLLs are in C:\Windows\SysWOW64.
  • When a 32-bit process opens a file in C:\Program Files, it actually reads/writes to C:\Program Files (x86).
  • There are separate views of (most of) the registry for 32-bit and 64-bit applications. You can change the 64-bit registry location and it wouldn’t be visible to 32-bit applications.

These differences are hardly elegant as they are, but they allow 32-bit applications to run successfully on a 64-bit Windows system. While unmanaged applications always had to choose the native target—x86, x64, or ia64 in the Visual Studio case—managed code has the additional choice of 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 that flavor of AnyCPU, the semantics are the following:

  • If the process runs on a 32-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.
  • If the process runs on a 64-bit Windows system, it runs as a 32-bit process. IL is compiled to x86 machine code.
  • If the process runs on an ARM Windows system, it runs as a 32-bit process. IL is compiled to ARM machine code.


A default AnyCPU that looks like it will just work...

No comments: