HP-UX HB v13.00 Ch-11 - Software Development

HP-UX Handbook Rev 13.00 Page 7 (of 101)
Chapter 11 Software Development
October 29, 2013
You might wonder where this stdio.h file can be found. This is one of the header files that are
provided with the operating system, because it provides the declarations of symbols that are
commonly used by a lot of programs. These files are collected inside the default path for system
header files, /usr/include. The compiler frontend knows this default path so we don't need to
care for it.
From the programmers point of view main() is the function which is called first when the
program is executed. Our main() calls the function printf(). Its declaration can be found in
stdio.h. but not its definition. The function is already compiled and linked into a library as we
will see later. The function printf() produces a formatted output of its arguments.
Compiling
When talking of compiling, usually two steps are meant: preprocessing and compiling. But most
of the time preprocessing and compiling is looked at as a single step. Note that not every
programming language has the concept of header files (e.g. java, fortran). In such cases you only
have source files and there is no preprocessing phase.
Preprocessing
The source file first is passed to the preprocessor. Among other things the preprocessor resolves
the references to header files which means wherever it finds a reference to a header file, it
includes the contents of the header file at that position, thus generating one big output file, the
preprocessed file.
For the HelloWorld.c source file the preprocessor would insert the contents of the header file
stdio.h at the beginning of the preprocessed file.
HelloWorld.c:
HelloWorld.i:
reference to stdio.h
definition of main()
Preprocessor
contents of stdio.h
definition of main()
The preprocessor knows some default paths where to look for files to be included. If a header file
exists in another path, this path must be passed to the preprocessor via a command line option.
The preprocessed file has the same name as the source file, but with the extension .i. To tell the
compiler frontend to only preprocess a source, the -P option must be added.