Friday, July 31, 2009

'source code' 2 'native code'---, C/C++ and C#. Plz read detail below?

I know .NET Languages compile to IL 1st, then JIT is used at runtime.....


1)Do the user of a .NET application will need to install JIT first 2 use this app. Is JIT accompanied with some version of windows??


2)In C, where codes of functions like printf() are located,


3)Is compilation of languages which are not .NET languages follow these steps





source code-%26gt;assembly(like IL)-%26gt;JIT(of C 4 example)-%26gt;RunTime of that language???

'source code' 2 'native code'---, C/C++ and C#. Plz read detail below?
1 is not correct. JIT isn't a 'thing' it's more of a concept, meaning 'just in time'. The .NET languages compile to MSIL (Microsoft Intermediate Language). The MSIL is then changed to machine code 'just in time' to run it. The machine code is transient, meaning it doesn't exist for any longer than it is needed. It must be created eventually because processors can't run anything but machine code, but there's no reason to store the program in machine code like we used to, because machine code is very processor-specific. This gives .NET programs the advantage of running on many different processors, including those that haven't been invented yet (pretty cool, huh). The .NET runtime is a special program that creates this machine code, and it is processor-specific, which is why there are different versions for 64-bit machines, and why .NET stuff can run on Linux and MAC in theory. Your MSIL is the same no matter what, and so is your source code. This is similar to the way Java works... Java source is compiled into "bytecode" which is analogous to MSIL code.





2. In C, functions like printf() are contained in libraries, and that's why you have to say #include "stdio.h" ... because you must "include" that library in your final (machine code) output.





3. Compilation of other languages takes many forms. Some languages are compiled all the way down to machine code, and some languages (like Javascript) are never compiled, just executed directly from the source code. Other languages like Java and .NET languages are compiled to "something in between" source code and machine code. Processors can not execute anything but machine code, so all languages are eventually converted to that, but the timing of that process varies widely from one language to the next.
Reply:1. The answer is above


2. the code is located in Run-time library. That is NOT why you have to say #include "stdio.h", however. #include is just the easiest way to inform compiler about the runtime functions format (function name, return type and parameters) but it is possible to modify any program that it will not have any includes at all but work exactly as it worked with includes. Actually, it is what is made by preprocessor before the compilation. Runtime can be linked with your program either statically (your program gets slightly bigger, but doesn't require any external dlls to run) or dynamically (smaller programs, but it becomes necessary to install apropriate dlls before programs can be started).


3. If you're talking about "native" languages (like C and C++), then AFAIK, no. There's no need in the second and the third steps in native compilation.


No comments:

Post a Comment