computer it is actually running on. Machine-specific features are isolated in a few
modules within the UNIX kernel, which makes it easy for you to modify them when you
are porting to different hardware architectures.
C is a compiled language, which means that your C source code is first analyzed by the
preprocessor and then translated into assembly language first and then into machine
instructions that are appropriate to the target CPU. An assembler then creates a binary, or
object, file from the machine instructions. Finally, the object file is linked to any required
external software support by the linker. A C program is stored in a text file that ends with
.c extension and always contains at least one routine, or function, such as main(),
unless the file is an include file (with a
.h extension, also known as a header file) contain-
ing shared variable definitions or other data or declarations. Functions are the commands
that perform each step of the task that the C program was written to accomplish.
The Linux kernel is mostly written in C, which is why Linux works with so many different
CPUs. To learn more about building the Linux kernel from source, see Chapter 35,
“Kernel and Module Management.”
Programming in C++
C++ is an object-oriented extension to C. Because C++ is a superset of C, C++ compilers
compile C programs correctly, and it is possible to write non–object-oriented code in C++.
The reverse is not true: C compilers cannot compile C++ code.
C++ extends the capabilities of C by providing the necessary features for object-oriented
design and code. C++ also provides some features, such as the capability to associate func-
tions with data structures, that do not require the use of class-based object-oriented tech-
niques. For these reasons, the C++ language enables existing UNIX programs to migrate
toward the adoption of object orientation over time.
Support for C++ programming is provided by
gcc, which you run with the name g++
when you are compiling C++ code. KDE includes some intermediate C++ tools, such as
moc (the Meta Object Compiler) for use when building KDE applications.
Getting Started with Linux C/C++ Programming
Writing C programs for Linux requires that you understand C syntax, have some under-
standing of how to interface with the Linux kernel (by using one or more of 1,100 differ-
ent C functions, known as system calls), and know how to use Linux programming tools
gcc and make. You’ll learn about each of these concepts and processes in this
To get started, you need to make sure that you have installed all the necessary software
development packages (perhaps by using the
synaptic client; see Chapter 7, “Managing
Software”) to support your project. Installation of basic development software requires
CHAPTER 30 C/C++ Programming Tools for Ubuntu