C is a compiled language. So once a C program is written, you must run it through a C compiler that can create an executable file to be run by the computer.
COMPILING
AND EXECUTING C PROGRAMS
C
is a compiled language. So once a C program is written, you must run it through
a C compiler that can create an executable file to be run by the computer.
While the C program is human-readable, the executable file, on the other hand,
is a machine-readable file available in an executable form.
The
mechanical part of running a C program begins with one or more program source
files, and ends with an executable file, which can be run on a computer.
The
programming process starts with creating a source file that consists of the
statements of the program written in C language. This source file usually
contains ASCII characters and can be produced with a text editor, such as
Windows notepad, or in an Integrated Design Environment. The source file is
then processed by a special program called a compiler.
Note
Every
programming language has its own compiler.
The
compiler translates the source code into an object code. The object code
contains the machine instructions for the CPU, and calls to the operating
system API (Application Programming Interface).
However,
even the object file is not an executable file. Therefore, in the next step, the
object file is processed with another special program called a linker. While
there is a different compiler for every individual language, the same linker is
used for object files regardless of the original language in which the new
program was written. The output of the linker is an executable or runnable
file. The process is shown in Figure 2.4.
In
C language programs, there are two kinds of source files. In addition to the
main (.c) source file, which contains
executable statements there are also header (.h)
source files. Since all input and output in C programs is done through library
functions, every C program therefore uses standard header files. These header
files should be written as part of the source code for modular C programs.
The
compilation process shown in Figure 2.5 is done in two steps. In the first
step, the preprocessor program reads the source file as text, and produces
another text file as output. Source code lines which begin with the # symbol
are actually not written in C but in the preprocessor language. The output of
the preprocessor is a text file
which
does not contain any preprocessor statements. This file is ready to be
processed by the compiler. The linker combines the object file with library
routines (supplied with the compiler) to produce the final executable file.
Programming in C: Unit I (b): Introduction to C : Tag: : - Compiling and Executing C Programs
Programming in C
CS3251 2nd Semester CSE Dept 2021 | Regulation | 2nd Semester CSE Dept 2021 Regulation