Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does setting the platform when compiling a c# application make any difference?

In VS2012 (and previous versions...), you can specify the target platform when building a project. My understanding, though, is that C# gets "compiled" to CIL and is then JIT compiled when running on the host system.

Does this mean that the only reasons for specifying a target platform are to deliberately restrict users from running the software on certain architectures or to force the application to run as 32 bit on a 64 bit machine? I can't see that it would be to do with optimization, as I guess that happens at the CIL-->Native stage, which happens Just-In-Time on the host architecture?

This MS Link does not seem to offer any alternative explanation and I can find no suggestion of the fact that you should, for example, release separate 32 / 64 bit versions of the same application - it would seem logical that something compiled for "anycpu" should run just as well and, again, optimizations will be applied at the JIT stage.

like image 824
AJ. Avatar asked Oct 08 '12 19:10

AJ.


People also ask

What happens when you compile ac file?

The file first. c is called the source file which keeps the code of the program. Now, when we compile the file, the C compiler looks for errors. If the C compiler reports no error, then it stores the file as a .

Can C be run on any platform?

No.... there are C and C++ compilers for many many many platforms, but different compilers have their own quirks, and the libraries they link to are completely different on various platforms.

What are the four stages in order of compiling ac program?

Compiling a C program is a multi-stage process. At an overview level, the process can be split into four separate stages: Preprocessing, compilation, assembly, and linking.

Which C compiler is used in window platform?

Mingw GCC. Mingw is "Minimalist GNU for Windows" tool chains under Windows. MinGW (Minimalist GNU for Windows), formerly mingw32, is a free and open source software development environment to create Microsoft Windows applications.


1 Answers

Does this mean that the only reasons for specifying a target platform are to deliberately restrict users from running the software on certain architectures or to force the application to run as 32 bit on a 64 bit machine?

Yes, and this is critical if you're using native code mixed with your managed code. It does not change what gets optimized at runtime, however.

If your code is 100% managed, then AnyCPU (or the new AnyCPU Prefer 32-Bit) is likely fine. The compiler optimizations will be the same, and the JIT will optimize at runtime based on the current executing platform.

I can find no suggestion of the fact that you should, for example, release separate 32 / 64 bit versions of the same application

There is no reason to do this unless you're performing interop with non-managed code, in which case, that will require separate 32 and 64 bit DLLs.

like image 91
Reed Copsey Avatar answered Oct 13 '22 11:10

Reed Copsey