answersLogoWhite

0


Best Answer

It's actually 3 stages: preprocessing, compilation and linking.

Preprocessing deals with all the preprocessor directives (all lines beginning with #). So a line such as #include<stdio.h> will effectively copy/paste the contents of the stdio.h header in place of the directive. The header itself may also contain preprocessor directives and these must be processed prior to insertion. Macros are also processed at this stage and all comments are stripped out. The end result is a translation unit that contains pure C code with absolutely no macros, no directives and no comments whatsoever. The translation unit is usually stored in working memory, however your IDE may include a switch that allows you to examine the contents of the translation unit.

The compiler processes each translation unit in isolation. Since the compiler cannot see any other translation units, only names with internal linkage can be resolved at compile time. The compiler produces an object file from the translation unit. The object file contains machine code along with a table of any names that couldn't be resolved by the compiler (those with external linkage).

Once all translation units have been compiled, the linker can examine the object files and resolve the outstanding external linkage problems, essentially linking all the object files into a single executable.

Problems can occur at any stage. For instance, preprocessing could result in a macro expansion that generates code that cannot be compiled. The compiler cannot resolve these problems because the compiler never saw the macro, it only saw the code that was generated by the preprocessor. So although it can identify the problem in the translation unit, it cannot identify where that problem originated. This is why macros are so difficult to debug: the compiler cannot help you.

Aside from macro problems, the compiler can identify and help you resolve a wide range of problems in your code thus it pays to make use of it as much as possible. The compiler can also statically assert your assumptions, perform compile-time computations and optimise your code through inline expansion, thus ensuring your code is error free and operates at peak performance.

Link-time errors are more difficult to deal with, but usually mean you've violated the one-definition rule (ODR) in some way, either by providing two different definitions for the same name or by not providing any definition of a name.

Even if no errors occur and linking is successful, it does not mean your executable is error free. The computer will only do exactly what you've told it to do, but it cannot account for logic errors at runtime. Many of these can be caught at compile time by making prudent use of static assertions, however this isn't always possible so you should also provide "sanity" checks wherever necessary and include appropriate error handling wherever runtime logic cannot be guaranteed to hold.

User Avatar

Wiki User

8y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which stage of building a fully executable program form C source code combine multiple files into an executable program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

The binary sequence that instructs the CPU to run the programming code is called a?

executable program


Is Excel an executable file?

The main Excel program file (excel.exe) is an executable file, but the workbooks it creates are not executable files.


What are extensions for an executable program?

.exe


What the different between non-executable files to executable files?

Executable means that the file has a series of instructions used to execute a program. Non-executable files are ones that do not have these instructions.


How is process different from a program?

Process is the program in the running state and program is a set of code un-executed, saved in a file. 1 program can produce 1 or many processes


What can cause an executable program or file not to open?

There are several possible reasons, but the most common is that the computer operating system doesn't recognise the file is an executable program.


How a c program execute?

Compile and link it into an executable.


A program that combines object code files into an executable program is called?

linker or binder


Where and how can I run a program?

You can run a program in any OS. For example an executable program can be run in windows by .exe file extension.


Does alg exe represent an executable file?

Putting '.exe' after a file name means that it is an executable file. This means that it is a program that can run by its self. So, yes, exe does represent an executable file.


What is ininupdateclientserviceexe?

It is an executable file, most likely an update for a program you have on your computer.


What is the extension of the executable version of a c program?

It is 'EXE' on some platforms.