answersLogoWhite

0


Best Answer

A source file (*.c file) contains the source code for (part of) a computer program written in a high-level language. All the user-defined types used by the source file must be forward declared before the first point of usage. If the source file uses types that also need to be available to other source files, those type declarations can be placed in a corresponding header file which this and other source files can include using the #include compiler directive. This ensures all type declarations are declared consistently across all the source files that use them.

Essentially, the #include directive instructs the compiler to import the code from the named header file into the source code at the point it was declared, just as if the programmer had copy/pasted that code by hand. This is done by the preprocessor which processes all the compiler directives (lines beginning with a # symbol) and strips out all user-defined comments from the source file, including its headers. Note that the source file is not physically changed by the preprocessor, it simply creates a new source file, known as a translation unit. After preprocessing, the compiler only sees the translation unit, not the source file. A translation unit must be entirely self-contained and must not depend on any names in any other translation unit, other than those that are explicitly declared with external linkage.

The compiler processes each translation unit in turn to create an object file, which is essentially the machine code translation of the source code. The machine code is only partially complete at this stage because all offset memory addresses cannot be finalised until all the object files are created. These addresses are symbolised and placed in a table at the end of the object file, along with external linkage information required by the linker.

Once all the object files are created, the linker takes over, linking the object files together to produce a machine code executable. All offset addresses are finalised at this stage. Note that the linker is the only program that "sees" the entire program.

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is stored in source file object file and an executable file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How can create a exe file in c?

An 'exe' extension file is created by a compiler that translates source code to machine code, usually in a Windows environment. An executable program can open any file (including other executable files) by using the standard file API calls with a binary open option. Unless you are doing something very specific with executable files it doesn't make much sense to read in an executable file from another executable file or program.


What is a source code file in c plus plus?

A source code file is a plain-text file containing C++ instructions. The instructions must be compiled and linked to create a native machine code executable.


What is difference between source programm and an abject module?

Source code is the "source" of a program. This means that this is the code provided by a programmer in a human readable and modifiable form. When a programmer writes a program, he/she will develop source code in a programming language such as C, C++, maybe Pascal among others. An object module can mean two different things depending on the context. An object module generally is an intermediate step between source code and an executable file like a .EXE on Windows. An executable file is actually what is generated by a compiler (like GCC or Visual C++) from source code and is effectively "machine language". It is not human readable and to a certain extend is not even machine readable as a whole. The way it works is that part of an executable file contains information to tell the operating system how to read the file into memory and where to start running it. The operating system will then tell the CPU where to start reading the program while it is in memory. The executable is a series of instructions understandable by the CPU and it performs them one by one as the program defines. Consider this overall process of compiling as someone writing a recipe for a certain type of food and then another person will compile a list of instructions in way that a resturant kitchen staff can follow it over and over. A different compiler might even translate the recipe to a different spoken language. In a similar fashion, one compiler might translate from C to Intel x86 while another would translate to IBM PowerPC. An object file often is an intermediate step between source and executable. This file is the result of compiling a single source file as opposed to all the source files of an entire program. Some programs fit in a single source file, but others can be hundreds or even thousands of source files. To compile the Linux kernel in it's full form as a single static executable can require compiling tens of thousands of files. Once each file is mostly translated to machine language and stored as an object file, a program called a linker is used to merge those files together into a single executable. This process might be seems as taking the recipe for and English muffin, another for hollandaise sauce and a final one for Eggs Benedict and merging all the steps together into a single recipe which a kitchen staff can execute in a given order to start with raw ingredients and produce the final product.


What is a Linker used for in computer programming?

Linking is the process of combining various pieces of code and data together to form a single executable that can be loaded in memory. Linking can be done at compile time, at load time (by loaders) and also at run time (by application programs)


Difference between source code and target code?

Source code is code written in a programming language, such as C++ or Java. It is designed to be architecture-independent and human-readable. Source code must be converted to object code (aka machine code) before it can be executed. Object code is architecture-dependent and is not easily human-readable (think ones and zeros). The point of this setup is that you can ensure that code you write in a programming language (source code) can be executed on ANY architecture that has a proper compiler.

Related questions

What is responsible for producing the object file during the transformation of source code to an executable?

Compiler.


Which type of object is stored only in its source file?

embedded object


What are the file created after c file is save?

Having saved the source file (*.C), you can compile it into an object module (*.OBJ), then link an executable program (*.EXE)


How do you link one C source file in another?

Linking means combining object modules and libraries into an executable file. The details are platform-dependent.


What is stored in an executable file?

Commands for applications are stored in an executable file. They are the primary programs that operate all Windows operating systems.


What is source file and Object file?

A "source file" holds the instructions for a program in text, e.g. computer commands like printf(). When the source file is processed by a computer language compiler object files are created. These will then be linked together by another special computer program called a linker to create an executable program file. Think of the source as being text for humans and the object as being computer files that are generally unreadable.


Why embedded object document requires more size than linked object?

Because a linked object is created and stored in a separate source file and then it is linked to the destination file, while an embedded object is created in a separate source file but then it is inserted into the destination file , becoming the part of that file.


Why embedded object documents requires more size than linked object?

Because a linked object is created and stored in a separate source file and then it is linked to the destination file, while an embedded object is created in a separate source file but then it is inserted into the destination file , becoming the part of that file.


How can create a exe file in c?

An 'exe' extension file is created by a compiler that translates source code to machine code, usually in a Windows environment. An executable program can open any file (including other executable files) by using the standard file API calls with a binary open option. Unless you are doing something very specific with executable files it doesn't make much sense to read in an executable file from another executable file or program.


What is the difference between an executable file and a .class file?

Both are binary files but the differences between those are:- 1) we can execute an executable file while we cannot execute an object file. 2) An object file is a file where compiler has not yet linked to the libraries, so you get an object file just before linking to the libraries, so still some of the symbols or function definitions are not yet resolved which are actually present in the libraries, and that's why we cannot execute it. Once an object file is linked with the library by the compiler, then all the symbols are resolved and we get an executable file which can be executed on the appropriate platform. So basically the difference is that we get an object file when we don't link with library while executable file is with the linking phase. In gcc we can direct compiler not to link with library and so it will prepare the object file :- gcc -c test.c It will automatically create test.o object file when you try to execute it like:- ./test.o cannot execute binary file


What is exe file?

An exe file is an executable file .It may or may not be a virus. It could also be a harmless program file. You would need to run an exe file through virus total to find out if it is malicious. An exe is produced by compiling source code into object code then linking it into machine code and writing that to the exe file. Exe is short for executable and is the extension for an application on Win 32


What is another name for executable file?

an executable file is a file that is extended longer