Sunday, August 2, 2009

How compiler works in c?

When we press alt+f9 .obj file execute.But how it properly works.Plese give me answer.

How compiler works in c?
There are a couple of steps in compiling a C program.





1. In the first step, the program is preprocessed. This means, for example, when files are included (#include %26lt;unistd.h%26gt;) up top, the text of these files is incorporated into the text of the program. Where macros are defined, the definition of each macro is substituted for the invocation of it in your program. #if and #ifndef issues are also dealt with. Comments are removed and some tokens are assigned.





2. After that comes optimization.





3. The next step in compilation is when the code is analyzed and translated into assembly language. At least in GCC, which is the compiler I use exclusively, these days, it is assembly language and not machine language. Here is where the compiler usually issues the most readable warnings and error messages.





4. This is then translated into machine code by the assembler.





5. Finally, the code is linked. This is where you get all those cryptic errors with Hexadecimal numbers for the address and no real indication of what routines are causing trouble. These usually mean that code for a given routine wasn't included, as for example when your header files call on code in a nonstandard library you forgot to tell the compiler to link to. An example on a Unix system would be an "#include %26lt;curses.h%26gt;" in the program would require you to type "cc yourprogramhere.c -o yourprogramhere -lcurses" at the shell prompt. Your compiler and your IDE have ways of doing this too, so read your documentation about it.





That, based on old Unix documentation, is how a compiler works.
Reply:Here's how I think of it:





First C takes your code and translates it into raw assembly


language. Assembly language then translates directly into Machine code (1's %26amp; 0's) which is executed by the processor.





hth.
Reply:When u press alt+F9 actually your file is not executed it is


only detecting by computer ,is there any error when it run


it is virtually run in computer and if there is any error if error occur then it send to you.


After this u run program


If u directly run the program then the two processes r executing simutaniosly first compilation second Running


when compilation is successfully completed and no errors are found then Running process is started


COMPILER NOT EXECUTE YOUR PROGRAM IT ONLY DETECT ERROR.


THANK U


No comments:

Post a Comment