Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any CPU - Prefer 32 bit

What does the Any CPU - Prefer 32 bit option do?

While I am aware that WinRT can not handle exe and can only run Windows Store apps, there are several questions exist on StackOverflow that ask the same question and both reference this blog that says:

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.

However, after purchasing my Surface RT, I created a Hello World program, set it to Any CPU, checked the Prefer 32 Bit flag, compiled and copied it to my Surface. When I ran the program the OS told me that it could not run the program and that I should look to the marketplace as it would for any x86/x64 exe. The exact message displayed was: "This app can't run on your PC. To find apps for this PC, open the Windows Store."

So what does this actually do and is it possible to compile an Any CPU application for Window RT on ARM?

like image 977
Dragonseer Avatar asked Oct 31 '12 01:10

Dragonseer


People also ask

What is Visual Studio prefer 32-bit?

When using the "Prefer 32-Bit" flavor of AnyCPU, the semantics are as follows: 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.

What is WOW64 mode?

WOW64 is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows. This allows for 32-bit (x86) Windows applications to run seamlessly in 64-bit (x64) Windows, as well as for 32-bit (x86) and 32-bit (ARM) Windows applications to run seamlessly in 64-bit (ARM64) Windows.


2 Answers

Based solely on the quote you specified, it suggests that it means the following:

  • If the CPU supports 32-bit processing, then the final machine code will be 32-bit (ARM or x86, doesn't matter).

  • If not, then the machine code will be 64-bit.

In the days of old, AnyCPU meant "I am platform agnostic." This typically meant that you would get 64-bit on 64-bit platforms, and 32-bit otherwise.

However, there are reasons why you may want 32-bit even on a 64-bit CPU: Pointers are half the size, so you use less memory; code is smaller, so more fits into the cache, etc. But, there was no way to force the CLR to use 32-bit, and still retain 64-bit in the cases it was necessary.

Now, with AnyCPU - 32 bit preferred, you can have your cake (64-bit support when necessary) and eat it too (32-bit support when possible)

Note: If I am not mistaken, Itanium would be a platform that only supports 64-bit, not 32-bit code. There may or may not be others.

Disclaimer: I am not an expert, this is just from various blog posts that I've read over the last 6 months or so

like image 199
Mike Caron Avatar answered Oct 19 '22 20:10

Mike Caron


Windows RT requires exe files to be signed for it to run. But if you jailbreak your RT then it can run any exe file as long as it is supported on Windows on ARM (.NET or native ARM) apps

More on this option on What AnyCPU Really Means As Of .NET 4.5 and Visual Studio 11

like image 39
phuclv Avatar answered Oct 19 '22 19:10

phuclv