Intro To GCC
Intro To GCC
Intro To GCC
Brian Gough
Foreword by Richard M. Stallman
A catalogue record for this book is available from the British Library.
15 Royal Park
Bristol
BS8 3AL
United Kingdom
Email: info@network-theory.co.uk
ISBN 0-9541617-9-3
Table of Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1 A brief history of GCC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Major features of GCC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Programming in C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Conventions used in this manual. . . . . . . . . . . . . . . . . . . . . . . 5
2 Compiling a C program . . . . . . . . . . . . . . 7
2.1 Compiling a simple C program . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Finding errors in a simple program . . . . . . . . . . . . . . . . . . . . 8
2.3 Compiling multiple source files . . . . . . . . . . . . . . . . . . . . . . . . 9
2.4 Compiling files independently . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4.1 Creating object files from source files . . . . . . . . 11
2.4.2 Creating executables from object files. . . . . . . . 11
2.4.3 Link order of object files. . . . . . . . . . . . . . . . . . . . 12
2.5 Recompiling and relinking . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.6 Linking with external libraries . . . . . . . . . . . . . . . . . . . . . . . 14
2.6.1 Link order of libraries . . . . . . . . . . . . . . . . . . . . . . 15
2.7 Using library header files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3 Compilation options . . . . . . . . . . . . . . . . . 19
3.1 Setting search paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1.1 Search path example . . . . . . . . . . . . . . . . . . . . . . . 20
3.1.2 Environment variables . . . . . . . . . . . . . . . . . . . . . . 21
3.1.3 Extended search paths . . . . . . . . . . . . . . . . . . . . . 22
3.2 Shared libraries and static libraries . . . . . . . . . . . . . . . . . . . 23
3.3 C language standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.3.1 ANSI/ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.3.2 Strict ANSI/ISO . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.3.3 Selecting specific standards . . . . . . . . . . . . . . . . . 28
3.4 Warning options in -Wall . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5 Additional warning options . . . . . . . . . . . . . . . . . . . . . . . . . . 30
ii An Introduction to GCC
8 Platform-specific options . . . . . . . . . . . . 63
8.1 Intel and AMD x86 options . . . . . . . . . . . . . . . . . . . . . . . . . . 63
8.2 DEC Alpha options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
8.3 SPARC options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.4 POWER/PowerPC options . . . . . . . . . . . . . . . . . . . . . . . . . . 65
8.5 Multi-architecture support . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
9 Troubleshooting. . . . . . . . . . . . . . . . . . . . . 69
9.1 Help for command-line options . . . . . . . . . . . . . . . . . . . . . . . 69
9.2 Version numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
9.3 Verbose compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
iii
10 Compiler-related tools. . . . . . . . . . . . . . 73
10.1 Creating a library with the GNU archiver . . . . . . . . . . . . 73
10.2 Using the profiler gprof . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
10.3 Coverage testing with gcov . . . . . . . . . . . . . . . . . . . . . . . . . 77
13 Getting help . . . . . . . . . . . . . . . . . . . . . . . 89
Further reading . . . . . . . . . . . . . . . . . . . . . . . . 91
Acknowledgements . . . . . . . . . . . . . . . . . . . . . 93
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
iv An Introduction to GCC
Foreword 1
Foreword
This foreword has been kindly contributed by Richard M. Stallman, the
principal author of GCC and founder of the GNU Project.
This book is a guide to getting started with GCC, the GNU Compiler
Collection. It will tell you how to use GCC as a programming tool. GCC
is a programming tool, that’s true—but it is also something more. It is
part of a 20-year campaign for freedom for computer users.
We all want good software, but what does it mean for software to
be “good”? Convenient features and reliability are what it means to be
technically good, but that is not enough. Good software must also be
ethically good: it has to respect the users’ freedom.
As a user of software, you should have the right to run it as you see
fit, the right to study the source code and then change it as you see fit,
the right to redistribute copies of it to others, and the right to publish a
modified version so that you can contribute to building the community.
When a program respects your freedom in this way, we call it free software.
Before GCC, there were other compilers for C, Fortran, Ada, etc. But
they were not free software; you could not use them in freedom. I wrote
GCC so we could use a compiler without giving up our freedom.
A compiler alone is not enough—to use a computer system, you need
a whole operating system. In 1983, all operating system for modern com-
puters were non-free. To remedy this, in 1984 I began developing the
GNU operating system, a Unix-like system that would be free software.
Developing GCC was one part of developing GNU.
By the early 90s, the nearly-finished GNU operating system was com-
pleted by the addition of a kernel, Linux, that became free software in
1992. The combined GNU/Linux operating system has achieved the goal
of making it possible to use a computer in freedom. But freedom is never
automatically secure, and we need to work to defend it. The Free Software
Movement needs your support.
Richard M. Stallman
February 2004
2 An Introduction to GCC
Chapter 1: Introduction 3
1 Introduction
The purpose of this book is to explain the use of the GNU C and C++
compilers, gcc and g++. After reading this book you should understand
how to compile a program, and how to use basic compiler options for
optimization and debugging. This book does not attempt to teach the C
or C++ languages themselves, since this material can be found in many
other places (see [Further reading], page 91).
Experienced programmers who are familiar with other systems, but
new to the GNU compilers, can skip the early sections of the chapters
“Compiling a C program”, “Using the preprocessor” and “Compiling a
C++ program”. The remaining sections and chapters should provide a
good overview of the features of GCC for those already know how to use
other compilers.
GCC is now used to refer to the “GNU Compiler Collection”. Its devel-
opment is guided by the GCC Steering Committee, a group composed
of representatives from GCC user communities in industry, research and
academia.
(1)
For details see the license file ‘COPYING’ distributed with GCC.
Chapter 1: Introduction 5
(2)
See http://www.network-theory.co.uk/gcc/intro/
6 An Introduction to GCC
2 Compiling a C program
This chapter describes how to compile C programs using gcc. Programs
can be compiled from a single source file or from multiple source files, and
may use system libraries and header files.
Compilation refers to the process of converting a program from the
textual source code, in a programming language such as C or C++, into
machine code, the sequence of 1’s and 0’s used to control the central
processing unit (CPU) of the computer. This machine code is then stored
in a file known as an executable file, sometimes referred to as a binary
file.
int
main (void)
{
printf ("Hello, world!\n");
return 0;
}
We will assume that the source code is stored in a file called ‘hello.c’.
To compile the file ‘hello.c’ with gcc, use the following command:
$ gcc -Wall hello.c -o hello
This compiles the source code in ‘hello.c’ to machine code and stores
it in an executable file ‘hello’. The output file for the machine code is
specified using the ‘-o’ option. This option is usually given as the last
argument on the command line. If it is omitted, the output is written to
a default file called ‘a.out’.
Note that if a file with the same name as the executable file already
exists in the current directory it will be overwritten.
The option ‘-Wall’ turns on all the most commonly-used compiler
warnings—it is recommended that you always use this option! There are
many other warning options which will be discussed in later chapters, but
‘-Wall’ is the most important. GCC will not produce any warnings unless
8 An Introduction to GCC
int
main (void)
{
printf ("Two plus two is %f\n", 4);
return 0;
}
This error is not obvious at first sight, but can be detected by the compiler
if the warning option ‘-Wall’ has been enabled.
Compiling the program above, ‘bad.c’, with the warning option
‘-Wall’ produces the following message:
$ gcc -Wall bad.c -o bad
bad.c: In function ‘main’:
bad.c:6: warning: double format, different
type arg (arg 2)
This indicates that a format string has been used incorrectly in the file
‘bad.c’ at line 6. The messages produced by GCC always have the form
file:line-number:message. The compiler distinguishes between error mes-
sages, which prevent successful compilation, and warning messages which
indicate possible problems (but do not stop the program from compiling).
In this case, the correct format specifier would have been ‘%d’ (the
allowed format specifiers for printf can be found in any general book on
Chapter 2: Compiling a C program 9
int
main (void)
{
hello ("world");
return 0;
}
The original call to the printf system function in the previous program
‘hello.c’ has been replaced by a call to a new external function hello,
which we will define in a separate file ‘hello_fn.c’.
The main program also includes the header file ‘hello.h’ which will
contain the declaration of the function hello. The declaration is used
to ensure that the types of the arguments and return value match up
correctly between the function call and the function definition. We no
10 An Introduction to GCC
void
hello (const char * name)
{
printf ("Hello, %s!\n", name);
}
This function prints the message “Hello, name!” using its argument as
the value of name.
Incidentally, the difference between the two forms of the include state-
ment #include "FILE.h" and #include <FILE.h> is that the former
searches for ‘FILE.h’ in the current directory before looking in the sys-
tem header file directories. The include statement #include <FILE.h>
searches the system header files, but does not look in the current direc-
tory by default.
To compile these source files with gcc, use the following command:
$ gcc -Wall main.c hello_fn.c -o newhello
In this case, we use the ‘-o’ option to specify a different output file for
the executable, ‘newhello’. Note that the header file ‘hello.h’ is not
specified in the list of files on the command line. The directive #include
"hello.h" in the source files instructs the compiler to include it auto-
matically at the appropriate points.
To run the program, type the path name of the executable:
$ ./newhello
Hello, world!
All the parts of the program have been combined into a single executable
file, which produces the same result as the executable created from the
single source file used earlier.
Chapter 2: Compiling a C program 11
int
main (void)
{
hello ("everyone"); /* changed from "world" */
return 0;
}
The updated file ‘main.c’ can now be recompiled with the following com-
mand:
$ gcc -Wall -c main.c
This produces a new object file ‘main.o’. There is no need to create a
new object file for ‘hello_fn.c’, since that file and the related files that
it depends on, such as header files, have not changed.
The new object file can be relinked with the hello function to create
a new executable file:
$ gcc main.o hello_fn.o -o hello
The resulting executable ‘hello’ now uses the new main function to pro-
duce the following output:
$ ./hello
Hello, everyone!
Note that only the file ‘main.c’ has been recompiled, and then relinked
with the existing object file for the hello function. If the file ‘hello_fn.c’
had been modified instead, we could have recompiled ‘hello_fn.c’ to
create a new object file ‘hello_fn.o’ and relinked this with the existing
file ‘main.o’.(1)
In general, linking is faster than compilation—in a large project with
many source files, recompiling only those that have been modified can
make a significant saving. The process of recompiling only the modified
(1)
If the prototype of a function has changed, it is necessary to modify and
recompile all of the other source files which use it.
14 An Introduction to GCC
files in a project can be automated using GNU Make (see [Further read-
ing], page 91).
int
main (void)
{
double x = sqrt (2.0);
printf ("The square root of 2.0 is %f\n", x);
return 0;
}
Trying to create an executable from this source file alone causes the com-
piler to give an error at the link stage:
(2)
On systems supporting both 64 and 32-bit executables the 64-bit versions
of the libraries will often be stored in ‘/usr/lib64’ and ‘/lib64’, with the
32-bit versions in ‘/usr/lib’ and ‘/lib’.
Chapter 2: Compiling a C program 15
int
main (void)
{
double x = pow (2.0, 3.0);
printf ("Two cubed is %f\n", x);
return 0;
Chapter 2: Compiling a C program 17
}
However, the program contains an error—the #include statement for
‘math.h’ is missing, so the prototype double pow (double x, double y)
given there will not be seen by the compiler.
Compiling the program without any warning options will produce an
executable file which gives incorrect results:
$ gcc badpow.c -lm
$ ./a.out
Two cubed is 2.851120 (incorrect result, should be 8)
The results are corrupted because the arguments and return value of the
call to pow are passed with incorrect types.(3) This can be detected by
turning on the warning option ‘-Wall’:
$ gcc -Wall badpow.c -lm
badpow.c: In function ‘main’:
badpow.c:6: warning: implicit declaration of
function ‘pow’
This example shows again the importance of using the warning option
‘-Wall’ to detect serious problems that could otherwise easily be over-
looked.
(3)
The actual output shown above may differ, depending on the specific plat-
form and environment.
18 An Introduction to GCC
Chapter 3: Compilation options 19
3 Compilation options
This chapter describes other commonly-used compiler options available
in GCC. These options control features such as the search paths used
for locating libraries and include files, the use of additional warnings and
diagnostics, preprocessor macros and C language dialects.
int
main (void)
{
GDBM_FILE dbf;
datum key = { "testkey", 7 }; /* key, length */
datum value = { "testvalue", 9 }; /* value, length */
For example, if version 1.8.3 of the GDBM package is installed under the
directory ‘/opt/gdbm-1.8.3’ the location of the header file would be,
/opt/gdbm-1.8.3/include/gdbm.h
which is not part of the default gcc include path. Adding the appropriate
directory to the include path with the command-line option ‘-I’ allows
the program to be compiled, but not linked:
$ gcc -Wall -I/opt/gdbm-1.8.3/include dbmain.c -lgdbm
/usr/bin/ld: cannot find -lgdbm
collect2: ld returned 1 exit status
The directory containing the library is still missing from the link path. It
can be added to the link path using the following option:
-L/opt/gdbm-1.8.3/lib/
The following command line allows the program to be compiled and linked:
$ gcc -Wall -I/opt/gdbm-1.8.3/include
-L/opt/gdbm-1.8.3/lib dbmain.c -lgdbm
This produces the final executable linked to the GDBM library. Before
seeing how to run this executable we will take a brief look at the environ-
ment variables that affect the ‘-I’ and ‘-L’ options.
Note that you should never place the absolute paths of header files in
#include statements in your source code, as this will prevent the program
from compiling on other systems. The ‘-I’ option or the INCLUDE_PATH
variable described below should always be used to set the include path for
header files.
variable in each shell session, and can also be set in the appropriate login
file.
Similarly, additional directories can be added to the link path using
the environment variable LIBRARY_PATH. For example, the following com-
mands will add ‘/opt/gdbm-1.8.3/lib’ to the link path:
$ LIBRARY_PATH=/opt/gdbm-1.8.3/lib
$ export LIBRARY_PATH
This directory will be searched after any directories specified on the com-
mand line with the option ‘-L’, and before the standard default directories
‘/usr/local/lib’ and ‘/usr/lib’.
With the environment variable settings given above the program
‘dbmain.c’ can be compiled without the ‘-I’ and ‘-L’ options,
$ gcc -Wall dbmain.c -lgdbm
because the default paths now use the directories specified in the environ-
ment variables C_INCLUDE_PATH and LIBRARY_PATH.
(2)
The current directory can also be specified using an empty path element.
For example, :DIR1 :DIR2 is equivalent to .:DIR1 :DIR2 .
Chapter 3: Compilation options 23
In day-to-day usage, directories are usually added to the search paths with
the options ‘-I’ and ‘-L’.
(3)
Note that the directory containing the shared library can, in principle,
be stored (“hard-coded”) in the executable itself using the linker option
‘-rpath’, but this is not usually done since it creates problems if the library
is moved or the executable is copied to another system.
Chapter 3: Compilation options 25
lowing command sets the load path to use the ‘lib’ directories under
‘/opt/gdbm-1.8.3’ and ‘/opt/gtk-1.4’:
$ LD_LIBRARY_PATH=/opt/gdbm-1.8.3/lib:/opt/gtk-1.4/lib
$ export LD_LIBRARY_PATH
If the load path contains existing entries, it can be extended using the syn-
tax LD_LIBRARY_PATH=NEWDIRS :$LD_LIBRARY_PATH. For example, the
following command adds the directory ‘/opt/gsl-1.5/lib’ to the load
path shown above:
$ LD_LIBRARY_PATH=/opt/gsl-1.5/lib:$LD_LIBRARY_PATH
$ echo $LD_LIBRARY_PATH
/opt/gsl-1.5/lib:/opt/gdbm-1.8.3/lib:/opt/gtk-1.4/lib
It is possible for the system administrator to set the LD_LIBRARY_PATH
variable for all users, by adding it to a default login script, such as
‘/etc/profile’. On GNU systems, a system-wide path can also be de-
fined in the loader configuration file ‘/etc/ld.so.conf’.
Alternatively, static linking can be forced with the ‘-static’ option
to gcc to avoid the use of shared libraries:
$ gcc -Wall -static -I/opt/gdbm-1.8.3/include/
-L/opt/gdbm-1.8.3/lib/ dbmain.c -lgdbm
This creates an executable linked with the static library ‘libgdbm.a’
which can be run without setting the environment variable LD_LIBRARY_
PATH or putting shared libraries in the default directories:
$ ./a.out
Storing key-value pair... done.
As noted earlier, it is also possible to link directly with individual library
files by specifying the full path to the library on the command line. For
example, the following command will link directly with the static library
‘libgdbm.a’,
$ gcc -Wall -I/opt/gdbm-1.8.3/include
dbmain.c /opt/gdbm-1.8.3/lib/libgdbm.a
and the command below will link with the shared library file ‘libgdbm.so’:
$ gcc -Wall -I/opt/gdbm-1.8.3/include
dbmain.c /opt/gdbm-1.8.3/lib/libgdbm.so
In the latter case it is still necessary to set the library load path when
running the executable.
ANSI/ISO standard for the C language with several useful GNU exten-
sions, such as nested functions and variable-size arrays. Most ANSI/ISO
programs will compile under GNU C without changes.
There are several options which control the dialect of C used by gcc.
The most commonly-used options are ‘-ansi’ and ‘-pedantic’. The spe-
cific dialects of the C language for each standard can also be selected with
the ‘-std’ option.
3.3.1 ANSI/ISO
Occasionally a valid ANSI/ISO program may be incompatible with the
extensions in GNU C. To deal with this situation, the compiler option
‘-ansi’ disables those GNU extensions which conflict with the ANSI/ISO
standard. On systems using the GNU C Library (glibc) it also disables
extensions to the C standard library. This allows programs written for
ANSI/ISO C to be compiled without any unwanted effects from GNU
extensions.
For example, here is a valid ANSI/ISO C program which uses a variable
called asm:
#include <stdio.h>
int
main (void)
{
const char asm[] = "6502";
printf ("the string asm is ’%s’\n", asm);
return 0;
}
The variable name asm is valid under the ANSI/ISO standard, but this
program will not compile in GNU C because asm is a GNU C keyword
extension (it allows native assembly instructions to be used in C func-
tions). Consequently, it cannot be used as a variable name without giving
a compilation error:
$ gcc -Wall ansi.c
ansi.c: In function ‘main’:
ansi.c:6: parse error before ‘asm’
ansi.c:7: parse error before ‘asm’
In contrast, using the ‘-ansi’ option disables the asm keyword extension,
and allows the program above to be compiled correctly:
$ gcc -Wall -ansi ansi.c
$ ./a.out
the string asm is ’6502’
Chapter 3: Compilation options 27
For reference, the non-standard keywords and macros defined by the GNU
C extensions are asm, inline, typeof, unix and vax. More details can be
found in the GCC Reference Manual “Using GCC” (see [Further reading],
page 91).
The next example shows the effect of the ‘-ansi’ option on systems
using the GNU C Library, such as GNU/Linux systems. The program be-
low prints the value of pi, π = 3.14159..., from the preprocessor definition
M_PI in the header file ‘math.h’:
#include <math.h>
#include <stdio.h>
int
main (void)
{
printf("the value of pi is %f\n", M_PI);
return 0;
}
The constant M_PI is not part of the ANSI/ISO C standard library (it
comes from the BSD version of Unix). In this case, the program will not
compile with the ‘-ansi’ option:
$ gcc -Wall -ansi pi.c
pi.c: In function ‘main’:
pi.c:7: ‘M_PI’ undeclared (first use in this function)
pi.c:7: (Each undeclared identifier is reported only once
pi.c:7: for each function it appears in.)
The program can be compiled without the ‘-ansi’ option. In this case
both the language and library extensions are enabled by default:
$ gcc -Wall pi.c
$ ./a.out
the value of pi is 3.141593
It is also possible to compile the program using ANSI/ISO C, by enabling
only the extensions in the GNU C Library itself. This can be achieved by
defining special macros, such as _GNU_SOURCE, which enable extensions in
the GNU C Library:(4)
$ gcc -Wall -ansi -D_GNU_SOURCE pi.c
$ ./a.out
the value of pi is 3.141593
The GNU C Library provides a number of these macros (referred to as
feature test macros) which allow control over the support for POSIX ex-
(4)
The ‘-D’ option for defining macros will be explained in detail in the next
chapter.
28 An Introduction to GCC
return 0;
}
This program will compile with ‘-ansi’, because support for variable
length arrays does not interfere with the compilation of valid ANSI/ISO
programs—it is a backwards-compatible extension:
$ gcc -Wall -ansi gnuarray.c
However, compiling with ‘-ansi -pedantic’ reports warnings about vio-
lations of the ANSI/ISO standard:
$ gcc -Wall -ansi -pedantic gnuarray.c
gnuarray.c: In function ‘main’:
gnuarray.c:5: warning: ISO C90 forbids variable-size
array ‘x’
Note that an absence of warnings from ‘-ansi -pedantic’ does not guar-
antee that a program strictly conforms to the ANSI/ISO standard. The
standard itself specifies only a limited set of circumstances that should
generate diagnostics, and these are what ‘-ansi -pedantic’ reports.
Chapter 3: Compilation options 29
int
main (void)
{
printf ("hello world\n");
return;
}
The lack of a return value in the code above could be the result
of an accidental omission by the programmer—the value returned
by the main function is actually the return value of the printf
function (the number of characters printed). To avoid ambiguity,
it is preferable to use an explicit value in the return statement,
either as a variable or a constant, such as return 0.
The complete set of warning options included in ‘-Wall’ can be found
in the GCC Reference Manual “Using GCC” (see [Further reading],
page 91). The options included in ‘-Wall’ have the common characteris-
tic that they report constructions which are always wrong, or can easily
be rewritten in an unambiguously correct way. This is why they are so
useful—any warning produced by ‘-Wall’ can be taken as an indication
of a potentially serious problem.
Chapter 3: Compilation options 31
(5)
The traditional form of the C language was described in the original C refer-
ence manual “The C Programming Language (First Edition)” by Kernighan
and Ritchie.
34 An Introduction to GCC
Chapter 4: Using the preprocessor 35
int
main (void)
{
#ifdef TEST
printf ("Test mode\n");
#endif
printf ("Running...\n");
return 0;
}
The gcc option ‘-DNAME ’ defines a preprocessor macro NAME from the
command line. If the program above is compiled with the command-
line option ‘-DTEST’, the macro TEST will be defined and the resulting
executable will print both messages:
$ gcc -Wall -DTEST dtest.c
$ ./a.out
Test mode
Running...
(1)
In recent versions of GCC the preprocessor is integrated into the compiler,
although a separate cpp command is also provided.
36 An Introduction to GCC
If the same program is compiled without the ‘-D’ option then the “Test
mode” message is omitted from the source code after preprocessing, and
the final executable does not include the code for it:
$ gcc -Wall dtest.c
$ ./a.out
Running...
Macros are generally undefined, unless specified on the command line with
the option ‘-D’, or in a source file (or library header file) with #define.
Some macros are automatically defined by the compiler—these typically
use a reserved namespace beginning with a double-underscore prefix ‘__’.
The complete set of predefined macros can be listed by running the
GNU preprocessor cpp with the option ‘-dM’ on an empty file:
$ cpp -dM /dev/null
#define __i386__ 1
#define __i386 1
#define i386 1
#define __unix 1
#define __unix__ 1
#define __ELF__ 1
#define unix 1
.......
Note that this list includes a small number of system-specific macros de-
fined by gcc which do not use the double-underscore prefix. These non-
standard macros can be disabled with the ‘-ansi’ option of gcc.
int
main (void)
{
printf("Value of NUM is %d\n", NUM);
return 0;
}
Note that macros are not expanded inside strings—only the occurrence of
NUM outside the string is substituted by the preprocessor.
Chapter 4: Using the preprocessor 37
int
main (void)
{
printf("Value of NUM is %d\n", 2+2);
return 0;
}
Note that it is a good idea to surround macros by parentheses when-
ever they are part of an expression. For example, the following program
uses parentheses to ensure the correct precedence for the multiplication
10*NUM:
#include <stdio.h>
int
main (void)
{
printf ("Ten times NUM is %d\n", 10 * (NUM));
return 0;
}
With these parentheses, it produces the expected result when compiled
with the same command line as above:
$ gcc -Wall -DNUM="2+2" dtestmul10.c
$ ./a.out
Ten times NUM is 40
38 An Introduction to GCC
Without parentheses, the program would produce the value 22 from the
literal form of the expression 10*2+2 = 22, instead of the desired value
10*(2+2) = 40.
When a macro is defined with ‘-D’ alone, gcc uses a default value of 1.
For example, compiling the original test program with the option ‘-DNUM’
generates an executable which produces the following output:
$ gcc -Wall -DNUM dtestval.c
$ ./a.out
Value of NUM is 1
A macro can be defined to a empty value using quotes on the command
line, -DNAME ="". Such a macro is still treated as defined by conditionals
such as #ifdef, but expands to nothing.
A macro containing quotes can be defined using shell-escaped quote
characters. For example, the command-line option -DMESSAGE="\"Hello,
World!\"" defines a macro MESSAGE which expands to the sequence of
characters "Hello, World!". For an explanation of the different types
of quoting and escaping used in the shell see the “GNU Bash Reference
Manual”, [Further reading], page 91.
int
main (void)
{
printf ("Hello, world!\n");
return 0;
}
It is possible to see the declarations from the included header file by
preprocessing the file with gcc -E:
$ gcc -E hello.c
On a GNU system, this produces output similar to the following:
# 1 "hello.c"
# 1 "/usr/include/stdio.h" 1 3
# 1 "hello.c" 2
int
main (void)
{
printf ("Hello, world!\n");
return 0;
}
The preprocessed system header files usually generate a lot of output.
This can be redirected to a file, or saved more conveniently using the gcc
‘-save-temps’ option:
$ gcc -c -save-temps hello.c
After running this command, the preprocessed output will be available
in the file ‘hello.i’. The ‘-save-temps’ option also saves ‘.s’ assembly
files and ‘.o’ object files in addition to preprocessed ‘.i’ files.
40 An Introduction to GCC
Chapter 5: Compiling for debugging 41
int
main (void)
{
42 An Introduction to GCC
int
a (int *p)
{
int y = *p;
return y;
}
The program attempts to dereference a null pointer p, which is an invalid
operation. On most systems, this will cause a crash.(1)
In order to be able to find the cause of the crash later, we need to
compile the program with the ‘-g’ option:
$ gcc -Wall -g null.c
Note that a null pointer will only cause a problem at run-time, so the
option ‘-Wall’ does not produce any warnings.
Running the executable file on an x86 GNU/Linux system will cause
the operating system to terminate the program abnormally:
$ ./a.out
Segmentation fault (core dumped)
Whenever the error message ‘core dumped’ is displayed, the operating sys-
tem should produce a file called ‘core’ in the current directory.(2) This
core file contains a complete copy of the pages of memory used by the
program at the time it was terminated. Incidentally, the term segmenta-
tion fault refers to the fact that the program tried to access a restricted
memory “segment” outside the area of memory which had been allocated
to it.
Some systems are configured not to write core files by default, since the
files can be large and rapidly fill up the available disk space on a system.
In the GNU Bash shell the command ulimit -c controls the maximum
size of core files. If the size limit is zero, no core files are produced. The
current size limit can be shown by typing the following command:
$ ulimit -c
0
(1)
Historically, a null pointer has typically corresponded to memory location 0,
which is usually restricted to the operating system kernel and not accessible
to user programs.
(2)
Some systems, such as FreeBSD and Solaris, can also be configured to write
core files in specific directories, e.g. ‘/var/coredumps/’, using the sysctl
or coreadm commands.
Chapter 5: Compiling for debugging 43
If the result is zero, as shown above, then it can be increased with the
following command to allow core files of any size to be written:(3)
$ ulimit -c unlimited
Note that this setting only applies to the current shell. To set the limit
for future sessions the command should be placed in an appropriate login
file, such as ‘.bash_profile’ for the GNU Bash shell.
Core files can be loaded into the GNU Debugger gdb with the following
command:
$ gdb EXECUTABLE-FILE CORE-FILE
Note that both the original executable file and the core file are required
for debugging—it is not possible to debug a core file without the corre-
sponding executable. In this example, we can load the executable and
core file with the command:
$ gdb a.out core
The debugger immediately begins printing diagnostic information, and
shows a listing of the line where the program crashed (line 13):
$ gdb a.out core
Core was generated by ‘./a.out’.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /lib/libc.so.6...done.
Loaded symbols for /lib/libc.so.6
Reading symbols from /lib/ld-linux.so.2...done.
Loaded symbols for /lib/ld-linux.so.2
#0 0x080483ed in a (p=0x0) at null.c:13
13 int y = *p;
(gdb)
The final line (gdb) is the GNU Debugger prompt—it indicates that fur-
ther commands can be entered at this point.
To investigate the cause of the crash, we display the value of the pointer
p using the debugger print command:
(gdb) print p
$1 = (int *) 0x0
This shows that p is a null pointer (0x0) of type ‘int *’, so we know that
dereferencing it with the expression *p in this line has caused the crash.
(3)
This example uses the ulimit command in the GNU Bash shell. On other
systems the usage of the ulimit command may vary, or have a different
name (the tcsh shell uses the limit command instead). The size limit for
core files can also be set to a specific value in kilobytes.
44 An Introduction to GCC
(1)
Temporary values introduced by the compiler during common subexpres-
sion elimination are only used internally, and do not affect real variables.
The name of the temporary variable ‘t’ shown above is only used as an
illustration.
Chapter 6: Compiling with optimization 47
inating the “end of loop” condition on each iteration. For example, the
following loop from 0 to 7 tests the condition i < 8 on each iteration:
for (i = 0; i < 8; i++)
{
y[i] = i;
}
At the end of the loop, this test will have been performed 9 times, and a
large fraction of the run time will have been spent checking it.
A more efficient way to write the same code is simply to unroll the
loop and execute the assignments directly:
y[0] = 0;
y[1] = 1;
y[2] = 2;
y[3] = 3;
y[4] = 4;
y[5] = 5;
y[6] = 6;
y[7] = 7;
This form of the code does not require any tests, and executes at maximum
speed. Since each assignment is independent, it also allows the compiler
to use parallelism on processors that support it. Loop unrolling is an
optimization that increases the speed of the resulting executable but also
generally increases its size (unless the loop is very short, with only one or
two iterations, for example).
Loop unrolling is also possible when the upper bound of the loop is
unknown, provided the start and end conditions are handled correctly.
For example, the same loop with an arbitrary upper bound,
for (i = 0; i < n; i++)
{
y[i] = i;
}
can be rewritten by the compiler as follows:
for (i = 0; i < (n % 2); i++)
{
y[i] = i;
}
The first loop handles the case i = 0 when n is odd, and the second loop
handles all the remaining iterations. Note that the second loop does
not use an initializer in the first argument of the for statement, since
it continues where the first loop finishes. The assignments in the second
loop can be parallelized, and the overall number of tests is reduced by a
factor of 2 (approximately). Higher factors can be achieved by unrolling
more assignments inside the loop, at the cost of greater code size.
6.3 Scheduling
The lowest level of optimization is scheduling, in which the compiler de-
termines the best ordering of individual instructions. Most CPUs allow
one or more new instructions to start executing before others have fin-
ished. Many CPUs also support pipelining, where multiple instructions
execute in parallel on the same CPU.
When scheduling is enabled, instructions must be arranged so that
their results become available to later instructions at the right time, and to
allow for maximum parallel execution. Scheduling improves the speed of
an executable without increasing its size, but requires additional memory
and time in the compilation process itself (due to its complexity).
6.5 Examples
The following program will be used to demonstrate the effects of different
optimization levels:
Chapter 6: Compiling with optimization 51
#include <stdio.h>
double
powern (double d, unsigned n)
{
double x = 1.0;
unsigned j;
return x;
}
int
main (void)
{
double sum = 0.0;
unsigned i;
$ time ./a.out
real 0m10.030s
user 0m10.030s
sys 0m0.000s
The relevant entry in the output for comparing the speed of the resulting
executables is the ‘user’ time, which gives the actual CPU time spent
running the process. The other rows, ‘real’ and ‘sys’, record the total
real time for the process to run (including times where other processes
were using the CPU) and the time spent waiting for operating system
calls. Although only one run is shown for each case above, the benchmarks
were executed several times to confirm the results.
From the results it can be seen in this case that increasing the opti-
mization level with ‘-O1’, ‘-O2’ and ‘-O3’ produces an increasing speedup,
relative to the unoptimized code compiled with ‘-O0’. The additional
option ‘-funroll-loops’ produces a further speedup. The speed of the
program is more than doubled overall, when going from unoptimized code
to the highest level of optimization.
Note that for a small program such as this there can be considerable
variation between systems and compiler versions. For example, on a Mo-
bile 2.0 GHz Intel Pentium 4M system the trend of the results using the
same version of GCC is similar except that the performance with ‘-O2’
is slightly worse than with ‘-O1’. This illustrates an important point:
optimizations may not necessarily make a program faster in every case.
Chapter 6: Compiling with optimization 53
if (x > 0)
s = 1;
else if (x < 0)
s = -1;
return s;
}
The function works correctly for most arguments, but has a bug when x
is zero—in this case the return value of the variable s will be undefined.
54 An Introduction to GCC
Compiling the program with the ‘-Wall’ option alone does not pro-
duce any warnings, because data-flow analysis is not carried out without
optimization:
$ gcc -Wall -c uninit.c
To produce a warning, the program must be compiled with ‘-Wall’ and
optimization simultaneously. In practice, the optimization level ‘-O2’ is
needed to give good warnings:
$ gcc -Wall -O2 -c uninit.c
uninit.c: In function ‘sign’:
uninit.c:4: warning: ‘s’ might be used uninitialized
in this function
This correctly detects the possibility of the variable s being used without
being defined.
Note that while GCC will usually find most uninitialized variables,
it does so using heuristics which will occasionally miss some complicated
cases or falsely warn about others. In the latter situation, it is often
possible to rewrite the relevant lines in a simpler way that removes the
warning and improves the readability of the source code.
Chapter 7: Compiling a C++ program 55
int
main ()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
The program can be compiled with the following command line:
$ g++ -Wall hello.cc -o hello
The C++ frontend of GCC uses many of the same the same options as the
C compiler gcc. It also supports some additional options for controlling
C++ language features, which will be described in this chapter. Note that
C++ source code should be given one of the valid C++ file extensions ‘.cc’,
‘.cpp’, ‘.cxx’ or ‘.C’ rather than the ‘.c’ extension used for C programs.
The resulting executable can be run in exactly same way as the C
version, simply by typing its filename:
$ ./hello
Hello, world!
The executable produces the same output as the C version of the program,
using std::cout instead of the C printf function. All the options used in
56 An Introduction to GCC
int
Chapter 7: Compiling a C++ program 57
main ()
{
string s1 = "Hello,";
string s2 = "World!";
cout << s1 + " " + s2 << endl;
return 0;
}
The program can be compiled and run using the same commands as above:
$ g++ -Wall hellostr.cc
$ ./a.out
Hello, World!
Note that in accordance with the C++ standard, the header files for the
C++ library itself do not use a file extension. The classes in the library
are also defined in the std namespace, so the directive using namespace
std is needed to access them, unless the prefix std:: is used throughout
(as in the previous section).
7.3 Templates
Templates provide the ability to define C++ classes which support generic
programming techniques. Templates can be considered as a powerful
kind of macro facility. When a templated class or function is used with a
specific class or type, such as float or int, the corresponding template
code is compiled with that type substituted in the appropriate places.
int
main ()
{
58 An Introduction to GCC
list<string> list;
list.push_back("Hello");
list.push_back("World");
cout << "List size = " << list.size() << endl;
return 0;
}
No special options are needed to use the template classes in the standard
library; the command-line options for compiling this program are the same
as before:
$ g++ -Wall string.cc
$ ./a.out
List size = 2
Note that the executables created by g++ using the C++ standard library
will be linked to the shared library ‘libstdc++’, which is supplied as
part of the default GCC installation. There are several versions of this
library—if you distribute executables using the C++ standard library you
need to ensure that the recipient has a compatible version of ‘libstdc++’,
or link your program statically using the command-line option ‘-static’.
};
#endif /* BUFFER_H */
The file contains both the declaration of the class and the definitions of
the member functions. This class is only given for demonstration purposes
and should not be considered an example of good programming. Note the
use of include guards, which test for the presence of the macro BUFFER_H,
ensuring that the definitions in the header file are only parsed once, if the
file is included multiple times in the same context.
The program below uses the templated Buffer class to create a buffer
of size 10, storing the floating point values 0.25 and 1.0 in the buffer:
#include <iostream>
#include "buffer.h"
int
main ()
{
Buffer<float> f(10);
60 An Introduction to GCC
f.insert (0.25);
f.insert (1.0 + f.get(0));
cout << "stored value = " << f.get(0) << endl;
return 0;
}
The definitions for the template class and its functions are included in the
source file for the program with ‘#include "buffer.h"’ before they are
used. The program can then be compiled using the following command
line:
$ g++ -Wall tprog.cc
$ ./a.out
stored value = 1.25
At the points where the template functions are used in the source file,
g++ compiles the appropriate definition from the header file and places
the compiled function in the corresponding object file.
If a template function is used several times in a program it will be
stored in more than one object file. The GNU Linker ensures that only one
copy is placed in the final executable. Other linkers may report “multiply
defined symbol” errors when they encounter more than one copy of a
template function—a method of working with these linkers is described
below.
#include "buffer.h"
template class Buffer<float>;
The whole program can be compiled and linked using explicit instantiation
with the following commands:
$ g++ -Wall -fno-implicit-templates -c tprog.cc
$ g++ -Wall -fno-implicit-templates -c templates.cc
$ g++ tprog.o templates.o
$ ./a.out
stored value = 1.25
The object code for all the template functions is contained in the
file ‘templates.o’. There is no object code for template functions in
‘tprog.o’ when it is compiled with the ‘-fno-implicit-templates’ op-
tion.
If the program is modified to use additional types, then further explicit
instantiations can be added to the file ‘templates.cc’. For example, the
following code adds instantiations for Buffer objects containing double
and int values:
#include "buffer.h"
template class Buffer<float>;
template class Buffer<double>;
template class Buffer<int>;
The disadvantage of explicit instantiation is that it is necessary to know
which template types are needed by the program. For a complicated pro-
gram this may be difficult to determine in advance. Any missing template
instantiations can be determined at link time, however, and added to the
list of explicit instantiations, by noting which functions are undefined.
Explicit instantiation can also be used to make libraries of precompiled
template functions, by creating an object file containing all the required
instantiations of a template function (as in the file ‘templates.cc’ above).
For example, the object file created from the template instantiations above
contains the machine code needed for Buffer classes with ‘float’, ‘double’
and ‘int’ types, and could be distributed in a library.
The export keyword is not widely used, and most other compilers do
not support it either. The inclusion compilation model described earlier
is recommended as the simplest and most portable way to use templates.
Chapter 8: Platform-specific options 63
8 Platform-specific options
GCC provides a range of platform-specific options for different types of
CPUs. These options control features such as hardware floating-point
modes, and the use of special instructions for different CPUs. They can
be selected with the ‘-m’ option on the command line, and work with all
the GCC language frontends, such as gcc and g++.
The following sections describe some of the options available for com-
mon platforms. A complete list of all platform-specific options can be
found in the GCC Reference Manual, “Using GCC” (see [Further read-
ing], page 91). Support for new processors is added to GCC as they
become available, therefore some of the options described in this chapter
may not be found in older versions of GCC.
processor, in terms of instruction scheduling, but does not use any in-
structions which are not available on other CPUs in the x86 family. The
resulting code will be compatible with all the CPUs, and have a speed
advantage on the CPU specified by ‘-mcpu’. The executables generated
by ‘-mcpu’ cannot achieve the same performance as ‘-march’, but may be
more convenient in practice.
AMD has enhanced the 32-bit x86 instruction set to a 64-bit instruc-
tion set called x86-64, which is implemented in their AMD64 processors.(2)
On AMD64 systems GCC generates 64-bit code by default. The option
‘-m32’ allows 32-bit code to be generated instead.
The AMD64 processor has several different memory models for pro-
grams running in 64-bit mode. The default model is the small code model,
which allows code and data up to 2 GB in size. The medium code model
allows unlimited data sizes and can be selected with ‘-mcmodel=medium’.
There is also a large code model, which supports an unlimited code size in
addition to unlimited data size. It is not currently implemented in GCC
since the medium code model is sufficient for all practical purposes—
executables with sizes greater than 2 GB are not encountered in practice.
A special kernel code model ‘-mcmodel=kernel’ is provided for system-
level code, such as the Linux kernel. An important point to note is that by
default on the AMD64 there is a 128-byte area of memory allocated below
the stack pointer for temporary data, referred to as the “red-zone”, which
is not supported by the Linux kernel. Compilation of the Linux kernel on
the AMD64 requires the options ‘-mcmodel=kernel -mno-red-zone’.
cations which require these features, GCC provides the option ‘-mieee’
to enable full support for IEEE arithmetic.
To demonstrate the difference between the two cases the following
program divides 1 by 0:
#include <stdio.h>
int
main (void)
{
double x = 1.0, y = 0.0;
printf ("x/y = %g\n", x / y);
return 0;
}
In IEEE arithmetic the result of 1/0 is inf (Infinity). If the program is
compiled for the Alpha processor with the default settings it generates an
exception, which terminates the program:
$ gcc -Wall alpha.c
$ ./a.out
Floating point exception (on an Alpha processor)
Using the ‘-mieee’ option ensures full IEEE compliance – the division 1/0
correctly produces the result inf and the program continues executing
successfully:
$ gcc -Wall -mieee alpha.c
$ ./a.out
x/y = inf
Note that programs which generate floating-point exceptions run more
slowly when compiled with ‘-mieee’, because the exceptions are handled
in software rather than hardware.
(3)
The options ‘-maix64’ and ‘-maix32’ are used on AIX.
Chapter 8: Platform-specific options 67
same name to exist on the same system. Other systems, such as the
IA64/Itanium, use the directories ‘/usr/lib’ and ‘/lib’ for 64-bit li-
braries. GCC knows about these paths and uses the appropriate path
when compiling 64-bit or 32-bit code.
68 An Introduction to GCC
Chapter 9: Troubleshooting 69
9 Troubleshooting
GCC provides several help and diagnostic options to assist in trou-
bleshooting problems with the compilation process. All the options de-
scribed in this chapter work with both gcc and g++.
This includes information on the build flags of the compiler itself and the
installed configuration file, ‘specs’.
10 Compiler-related tools
This chapter describes a number of tools which are useful in combination
with GCC. These include the GNU archiver ar, for creating libraries, and
the GNU profiling and coverage testing programs, gprof and gcov.
void
hello (const char * name)
{
printf ("Hello, %s!\n", name);
}
The second object file will be generated from the source file ‘bye_fn.c’,
which contains the new function bye:
#include <stdio.h>
#include "hello.h"
void
bye (void)
{
printf ("Goodbye!\n");
}
Both functions use the header file ‘hello.h’, now with a prototype for
the function bye():
void hello (const char * name);
void bye (void);
74 An Introduction to GCC
The source code can be compiled to the object files ‘hello_fn.o’ and
‘bye_fn.o’ using the commands:
$ gcc -Wall -c hello_fn.c
$ gcc -Wall -c bye_fn.c
These object files can be combined into a static library using the following
command line:
$ ar cr libhello.a hello_fn.o bye_fn.o
The option ‘cr’ stands for “create and replace”.(1) If the library does
not exist, it is first created. If the library already exists, any original
files in it with the same names are replaced by the new files specified on
the command line. The first argument ‘libhello.a’ is the name of the
library. The remaining arguments are the names of the object files to be
copied into the library.
The archiver ar also provides a “table of contents” option ‘t’ to list
the object files in an existing library:
$ ar t libhello.a
hello_fn.o
bye_fn.o
Note that when a library is distributed, the header files for the public
functions and variables it provides should also be made available, so that
the end-user can include them and obtain the correct prototypes.
We can now write a program using the functions in the newly created
library:
#include "hello.h"
int
main (void)
{
hello ("everyone");
bye ();
return 0;
}
This file can be compiled with the following command line, as described in
Section 2.6 [Linking with external libraries], page 14, assuming the library
‘libhello.a’ is stored in the current directory:
$ gcc -Wall main.c libhello.a -o hello
The main program is linked against the object files found in the library
file ‘libhello.a’ to produce the final executable.
(1)
Note that ar does not require a prefix ‘-’ for its options.
Chapter 10: Compiler-related tools 75
The short-cut library linking option ‘-l’ can also be used to link the
program, without needing to specify the full filename of the library ex-
plicitly:
$ gcc -Wall -L. main.c -lhello -o hello
The option ‘-L.’ is needed to add the current directory to the library
search path. The resulting executable can be run as usual:
$ ./hello
Hello, everyone!
Goodbye!
It displays the output from both the hello and bye functions defined in
the library.
unsigned int
step (unsigned int x)
{
if (x % 2 == 0)
{
(2)
American Mathematical Monthly, Volume 92 (1985), 3–23
76 An Introduction to GCC
return (x / 2);
}
else
{
return (3 * x + 1);
}
}
unsigned int
nseq (unsigned int x0)
{
unsigned int i = 1, x;
if (x0 == 1 || x0 == 0)
return i;
x = step (x0);
while (x != 1 && x != 0)
{
x = step (x);
i++;
}
return i;
}
int
main (void)
{
unsigned int i, m = 0, im = 0;
if (k > m)
{
m = k;
im = i;
printf ("sequence length = %u for %u\n", m, im);
}
}
return 0;
}
To use profiling, the program must be compiled and linked with the ‘-pg’
profiling option:
Chapter 10: Compiler-related tools 77
int
main (void)
{
int i;
return 0;
}
To enable coverage testing the program must be compiled with the fol-
lowing options:
$ gcc -Wall -fprofile-arcs -ftest-coverage cov.c
This creates an instrumented executable which contains additional in-
structions that record the number of times each line of the program is ex-
ecuted. The option ‘-ftest-coverage’ adds instructions for counting the
number of times individual lines are executed, while ‘-fprofile-arcs’ in-
corporates instrumentation code for each branch of the program. Branch
instrumentation records how frequently different paths are taken through
‘if’ statements and other conditionals. The executable must then be run
to create the coverage data:
$ ./a.out
3 is divisible by 3
6 is divisible by 3
9 is divisible by 3
The data from the run is written to several files with the extensions ‘.bb’
‘.bbg’ and ‘.da’ respectively in the current directory. This data can be
analyzed using the gcov command and the name of a source file:
$ gcov cov.c
88.89% of 9 source lines executed in file cov.c
Creating cov.c.gcov
Chapter 10: Compiler-related tools 79
int
main (void)
{
1 int i;
1 return 0;
1 }
The line counts can be seen in the first column of the output. Lines which
were not executed are marked with hashes ‘######’. The command ‘grep
’######’ *.gcov’ can be used to find parts of a program which have not
been used.
80 An Introduction to GCC
Chapter 11: How the compiler works 81
int
main (void)
{
printf ("Hello, world!\n");
return 0;
}
Note that it is not necessary to use any of the individual commands de-
scribed in this section to compile a program. All the commands are exe-
cuted automatically and transparently by GCC internally, and can be seen
using the ‘-v’ option described earlier (see Section 9.3 [Verbose compila-
tion], page 70). The purpose of this chapter is to provide an understanding
of how the compiler works.
Although the Hello World program is very simple it uses external
header files and libraries, and so exercises all the major steps of the com-
pilation process.
82 An Introduction to GCC
(1)
As mentioned earlier, the preprocessor is integrated into the compiler in
recent versions of GCC. Conceptually, the compilation process is the same
as running the preprocessor as separate application.
Chapter 11: How the compiler works 83
(1)
The MSB and LSB orderings are also known as big-endian and little-endian
respectively (the terms originate from Jonathan Swift’s satire “Gulliver’s
Travels”, 1727).
86 An Introduction to GCC
version 1 (SYSV)
This is the version of the internal format of the file.
dynamically linked
The executable uses shared libraries (statically linked indicates
programs linked statically, for example using the ‘-static’ option)
not stripped
The executable contains a symbol table (this can be removed with
the strip command).
The file command can also be used on object files, where it gives similar
output. The POSIX standard(2) for Unix systems defines the behavior of
the file command.
(2)
POSIX.1 (2003 edition), IEEE Std 1003.1-2003.
Chapter 12: Examining compiled files 87
13 Getting help
If you encounter a problem not covered by this manual, there are sev-
eral reference manuals which describe GCC and language-related topics
in more detail (see [Further reading], page 91). These manuals contain
answers to common questions, and careful study of them will usually yield
a solution. If the manuals are unclear, the most appropriate way to obtain
help is to ask a knowledgeable colleague for assistance.
Alternatively, there are many companies and consultants who offer
commercial support for programming matters related to GCC on an
hourly or ongoing basis. For businesses this can be a cost-effective way to
obtain high-quality support.
A directory of free software support companies and their current rates
can be found on the GNU Project website.(1) With free software, com-
mercial support is available in a free market—service companies compete
in quality and price, and users are not tied to any particular one. In con-
trast, support for proprietary software is usually only available from the
original vendor.
A higher-level of commercial support for GCC is available from compa-
nies involved in the development of the GNU compiler toolchain itself. A
listing of these companies can be found in the “Development Companies”
section of the publisher’s webpage for this book.(2) These companies can
provide services such as extending GCC to generate code for new CPUs
or fixing bugs in the compiler.
(1)
http://www.gnu.org/prep/service.html
(2)
http://www.network-theory.co.uk/gcc/intro/
90 An Introduction to GCC
Further reading 91
Further reading
The definitive guide to GCC is the official reference manual, “Using
GCC”, published by GNU Press:
Using GCC (for GCC version 3.3.1) by Richard M. Stallman and
the GCC Developer Community (Published by GNU Press, ISBN
1-882114-39-6)
This manual is essential for anyone working with GCC because it describes
every option in detail. Note that the manual is updated when new releases
of GCC become available, so the ISBN number may change in the future.
If you are new to programming with GCC you will also want to learn
how to use the GNU Debugger GDB, and how to compile large programs
easily with GNU Make. These tools are described in the following manu-
als:
Debugging with GDB: The GNU Source-Level Debugger by Richard
M. Stallman, Roland Pesch, Stan Shebs, et al. (Published by GNU
Press, ISBN 1-882114-88-4)
GNU Make: A Program for Directing Recompilation by Richard M.
Stallman and Roland McGrath (Published by GNU Press, ISBN 1-
882114-82-5)
For effective C programming it is also essential to have a good knowl-
edge of the C standard library. The following manual documents all the
functions in the GNU C Library:
The GNU C Library Reference Manual by Sandra Loosemore with
Richard M. Stallman, et al (2 vols) (Published by GNU Press, ISBN
1-882114-22-1 and 1-882114-24-8)
Be sure to check the website http://www.gnupress.org/ for the latest
printed editions of manuals published by GNU Press. The manuals can be
purchased online using a credit card at the FSF website(1) in addition to
being available for order through most bookstores using the ISBNs. Man-
uals published by GNU Press raise funds for the Free Software Foundation
and the GNU Project.
Information about shell commands, environment variables and shell-
quoting rules can be found in the following book:
The GNU Bash Reference Manual by Chet Ramey and Brian Fox
(Published by Network Theory Ltd, ISBN 0-9541617-7-7)
(1)
http://order.fsf.org/
92 An Introduction to GCC
(2)
http://www.network-theory.co.uk/gcc/intro/
Acknowledgements 93
Acknowledgements
Many people have contributed to this book, and it is important to record
their names here:
Thanks to Gerald Pfeifer, for his careful reviewing and numerous sug-
gestions for improving the book.
Thanks to Andreas Jaeger, for information on AMD64 and multi-
architecture support, and many helpful comments.
Thanks to David Edelsohn, for information on the POWER/PowerPC
series of processors.
Thanks to Jamie Lokier, for research.
Thanks to Stephen Compall, for helpful corrections.
Thanks to Gerard Jungman, for useful comments.
Thanks to Steven Rubin, for generating the chip layout for the cover
with Electric.
And most importantly, thanks to Richard Stallman, founder of the
GNU Project, for writing GCC and making it free software.
94 An Introduction to GCC
Other books from the publisher 95
Document may contain zero Invariant Sections. If the Document does not iden-
tify any Invariant Sections then there are none.
The “Cover Texts” are certain short passages of text that are listed, as Front-
Cover Texts or Back-Cover Texts, in the notice that says that the Document is
released under this License. A Front-Cover Text may be at most 5 words, and a
Back-Cover Text may be at most 25 words.
A “Transparent” copy of the Document means a machine-readable copy, repre-
sented in a format whose specification is available to the general public, that is
suitable for revising the document straightforwardly with generic text editors or
(for images composed of pixels) generic paint programs or (for drawings) some
widely available drawing editor, and that is suitable for input to text formatters
or for automatic translation to a variety of formats suitable for input to text
formatters. A copy made in an otherwise Transparent file format whose markup,
or absence of markup, has been arranged to thwart or discourage subsequent
modification by readers is not Transparent. An image format is not Transparent
if used for any substantial amount of text. A copy that is not “Transparent” is
called “Opaque”.
Examples of suitable formats for Transparent copies include plain ascii without
markup, Texinfo input format, LaTEX input format, sgml or xml using a publicly
available dtd, and standard-conforming simple html, PostScript or pdf designed
for human modification. Examples of transparent image formats include png,
xcf and jpg. Opaque formats include proprietary formats that can be read
and edited only by proprietary word processors, sgml or xml for which the dtd
and/or processing tools are not generally available, and the machine-generated
html, PostScript or pdf produced by some word processors for output purposes
only.
The “Title Page” means, for a printed book, the title page itself, plus such
following pages as are needed to hold, legibly, the material this License requires
to appear in the title page. For works in formats which do not have any title
page as such, “Title Page” means the text near the most prominent appearance
of the work’s title, preceding the beginning of the body of the text.
A section “Entitled XYZ” means a named subunit of the Document whose title
either is precisely XYZ or contains XYZ in parentheses following text that trans-
lates XYZ in another language. (Here XYZ stands for a specific section name
mentioned below, such as “Acknowledgements”, “Dedications”, “Endorsements”,
or “History”.) To “Preserve the Title” of such a section when you modify the
Document means that it remains a section “Entitled XYZ” according to this
definition.
The Document may include Warranty Disclaimers next to the notice which states
that this License applies to the Document. These Warranty Disclaimers are con-
sidered to be included by reference in this License, but only as regards disclaiming
warranties: any other implication that these Warranty Disclaimers may have is
void and has no effect on the meaning of this License.
2. VERBATIM COPYING
You may copy and distribute the Document in any medium, either commercially
or noncommercially, provided that this License, the copyright notices, and the
license notice saying this License applies to the Document are reproduced in
all copies, and that you add no other conditions whatsoever to those of this
License. You may not use technical measures to obstruct or control the reading
or further copying of the copies you make or distribute. However, you may accept
compensation in exchange for copies. If you distribute a large enough number of
copies you must also follow the conditions in section 3.
GNU Free Documentation License 101
You may also lend copies, under the same conditions stated above, and you may
publicly display copies.
3. COPYING IN QUANTITY
If you publish printed copies (or copies in media that commonly have printed
covers) of the Document, numbering more than 100, and the Document’s license
notice requires Cover Texts, you must enclose the copies in covers that carry,
clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover,
and Back-Cover Texts on the back cover. Both covers must also clearly and
legibly identify you as the publisher of these copies. The front cover must present
the full title with all words of the title equally prominent and visible. You may
add other material on the covers in addition. Copying with changes limited to
the covers, as long as they preserve the title of the Document and satisfy these
conditions, can be treated as verbatim copying in other respects.
If the required texts for either cover are too voluminous to fit legibly, you should
put the first ones listed (as many as fit reasonably) on the actual cover, and
continue the rest onto adjacent pages.
If you publish or distribute Opaque copies of the Document numbering more than
100, you must either include a machine-readable Transparent copy along with
each Opaque copy, or state in or with each Opaque copy a computer-network lo-
cation from which the general network-using public has access to download using
public-standard network protocols a complete Transparent copy of the Document,
free of added material. If you use the latter option, you must take reasonably
prudent steps, when you begin distribution of Opaque copies in quantity, to en-
sure that this Transparent copy will remain thus accessible at the stated location
until at least one year after the last time you distribute an Opaque copy (directly
or through your agents or retailers) of that edition to the public.
It is requested, but not required, that you contact the authors of the Document
well before redistributing any large number of copies, to give them a chance to
provide you with an updated version of the Document.
4. MODIFICATIONS
You may copy and distribute a Modified Version of the Document under the
conditions of sections 2 and 3 above, provided that you release the Modified
Version under precisely this License, with the Modified Version filling the role
of the Document, thus licensing distribution and modification of the Modified
Version to whoever possesses a copy of it. In addition, you must do these things
in the Modified Version:
A. Use in the Title Page (and on the covers, if any) a title distinct from that of
the Document, and from those of previous versions (which should, if there
were any, be listed in the History section of the Document). You may use
the same title as a previous version if the original publisher of that version
gives permission.
B. List on the Title Page, as authors, one or more persons or entities respon-
sible for authorship of the modifications in the Modified Version, together
with at least five of the principal authors of the Document (all of its prin-
cipal authors, if it has fewer than five), unless they release you from this
requirement.
C. State on the Title page the name of the publisher of the Modified Version,
as the publisher.
D. Preserve all the copyright notices of the Document.
E. Add an appropriate copyright notice for your modifications adjacent to the
other copyright notices.
102 An Introduction to GCC
5. COMBINING DOCUMENTS
You may combine the Document with other documents released under this Li-
cense, under the terms defined in section 4 above for modified versions, provided
that you include in the combination all of the Invariant Sections of all of the
original documents, unmodified, and list them all as Invariant Sections of your
combined work in its license notice, and that you preserve all their Warranty
Disclaimers.
The combined work need only contain one copy of this License, and multiple
identical Invariant Sections may be replaced with a single copy. If there are
multiple Invariant Sections with the same name but different contents, make the
title of each such section unique by adding at the end of it, in parentheses, the
name of the original author or publisher of that section if known, or else a unique
number. Make the same adjustment to the section titles in the list of Invariant
Sections in the license notice of the combined work.
In the combination, you must combine any sections Entitled “History” in the vari-
ous original documents, forming one section Entitled “History”; likewise combine
any sections Entitled “Acknowledgements”, and any sections Entitled “Dedica-
tions”. You must delete all sections Entitled “Endorsements.”
6. COLLECTIONS OF DOCUMENTS
You may make a collection consisting of the Document and other documents
released under this License, and replace the individual copies of this License
in the various documents with a single copy that is included in the collection,
provided that you follow the rules of this License for verbatim copying of each of
the documents in all other respects.
You may extract a single document from such a collection, and distribute it
individually under this License, provided you insert a copy of this License into
the extracted document, and follow this License in all other respects regarding
verbatim copying of that document.
7. AGGREGATION WITH INDEPENDENT WORKS
A compilation of the Document or its derivatives with other separate and in-
dependent documents or works, in or on a volume of a storage or distribution
medium, is called an “aggregate” if the copyright resulting from the compila-
tion is not used to limit the legal rights of the compilation’s users beyond what
the individual works permit. When the Document is included in an aggregate,
this License does not apply to the other works in the aggregate which are not
themselves derivative works of the Document.
If the Cover Text requirement of section 3 is applicable to these copies of the
Document, then if the Document is less than one half of the entire aggregate, the
Document’s Cover Texts may be placed on covers that bracket the Document
within the aggregate, or the electronic equivalent of covers if the Document is in
electronic form. Otherwise they must appear on printed covers that bracket the
whole aggregate.
8. TRANSLATION
Translation is considered a kind of modification, so you may distribute transla-
tions of the Document under the terms of section 4. Replacing Invariant Sec-
tions with translations requires special permission from their copyright holders,
but you may include translations of some or all Invariant Sections in addition to
the original versions of these Invariant Sections. You may include a translation
of this License, and all the license notices in the Document, and any Warranty
Disclaimers, provided that you also include the original English version of this
License and the original versions of those notices and disclaimers. In case of a
104 An Introduction to GCC
disagreement between the translation and the original version of this License or
a notice or disclaimer, the original version will prevail.
If a section in the Document is Entitled “Acknowledgements”, “Dedications”,
or “History”, the requirement (section 4) to Preserve its Title (section 1) will
typically require changing the actual title.
9. TERMINATION
You may not copy, modify, sublicense, or distribute the Document except as
expressly provided for under this License. Any other attempt to copy, modify,
sublicense or distribute the Document is void, and will automatically terminate
your rights under this License. However, parties who have received copies, or
rights, from you under this License will not have their licenses terminated so
long as such parties remain in full compliance.
10. FUTURE REVISIONS OF THIS LICENSE
The Free Software Foundation may publish new, revised versions of the GNU Free
Documentation License from time to time. Such new versions will be similar in
spirit to the present version, but may differ in detail to address new problems or
concerns. See http://www.gnu.org/copyleft/.
Each version of the License is given a distinguishing version number. If the Doc-
ument specifies that a particular numbered version of this License “or any later
version” applies to it, you have the option of following the terms and conditions
either of that specified version or of any later version that has been published (not
as a draft) by the Free Software Foundation. If the Document does not specify a
version number of this License, you may choose any version ever published (not
as a draft) by the Free Software Foundation.
Index
# ‘-lm’ option, link with math library
#define, preprocessor directive . . . 35 . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
#if, preprocessor directive . . . . . . . 29 ‘-m’ option, platform-specific settings
. . . . . . . . . . . . . . . . . . . . . . . . . . . 63
#ifdef, preprocessor directive . . . . 35
‘-m32’ and ‘-m64’ options, compile for
#include, preprocessor directive . . 10
32 or 64-bit environment . . . . 65
‘-maltivec’ option, enables use of
$ Altivec processor on PowerPC
. . . . . . . . . . . . . . . . . . . . . . . . . . . 66
$, shell prompt . . . . . . . . . . . . . . . . . . . 5 ‘-march’ option, compile for specific
CPU . . . . . . . . . . . . . . . . . . . . . . . 63
‘-mcmodel’ option, for AMD64 . . . 64
- ‘-mcpu’ option, compile for specific
‘--help’ option, display CPU . . . . . . . . . . . . . . . . . . . . . . . 65
command-line options . . . . . . . 69 ‘-mieee’ option, floating-point
‘--version’ option, display version support on DEC Alpha . . . . . . 64
number . . . . . . . . . . . . . . . . . . . . 69 ‘-mminimal-toc’ option, on AIX . . 66
‘-ansi’ option, disable language ‘-mno-fused-madd’ option, on
extensions . . . . . . . . . . . . . . . . . . 25 PowerPC . . . . . . . . . . . . . . . . . . . 66
‘-ansi’ option, used with g++ . . . . 55 ‘-mxl-call’ option, compatibility
‘-c’ option, compile to object file with IBM XL compilers on AIX
. . . . . . . . . . . . . . . . . . . . . . . . . . . 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
‘-D’ option, define macro . . . . . . . . . 35 ‘-o’ option, set output filename . . . . 7
‘-dM’ option, list predefined macros ‘-O0’ option, optimization level zero
. . . . . . . . . . . . . . . . . . . . . . . . . . . 36 . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
‘-E’ option, preprocess source files ‘-O1’ option, optimization level one
. . . . . . . . . . . . . . . . . . . . . . . . . . . 38 . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
‘-fno-implicit-templates’ option, ‘-O2’ option, optimization level two
disable implicit instantiation . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
. . . . . . . . . . . . . . . . . . . . . . . . . . . 60 ‘-O3’ option, optimization level three
‘-fprofile-arcs’ option, instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
branches . . . . . . . . . . . . . . . . . . . 78 ‘-Os’ option, optimization for size
‘-ftest-coverage’ option, record . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
coverage. . . . . . . . . . . . . . . . . . . . 78 ‘-pedantic’ option, conform to the
‘-funroll-loops’ option, ANSI standard (with ‘-ansi’)
optimization by loop unrolling . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
. . . . . . . . . . . . . . . . . . . . . . . . . . . 50 ‘-pg’ option, enable profiling . . . . . 76
‘-g’ option, enable debugging . . . . 41 ‘-pthread’ option, on AIX . . . . . . . 66
‘-I’ option, include path . . . . . . . . . 19 ‘-rpath’ option, set run-time shared
‘-L’ option, library search path . . . 19 library search path . . . . . . . . . . 24
‘-l’ option, linking with libraries ‘-S’ option, create assembly code
. . . . . . . . . . . . . . . . . . . . . . . . . . . 15 . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
106 An Introduction to GCC
common errors, not included with creating executable files from object
‘-Wall’ . . . . . . . . . . . . . . . . . . . . . 31 files . . . . . . . . . . . . . . . . . . . . . . . . 12
common subexpression elimination, creating object files from source files
optimization . . . . . . . . . . . . . . . . 45 . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
comparison of ... expression cxx, C++ file extension . . . . . . . . . . . 55
always true/false warning,
example of . . . . . . . . . . . . . . . . . 31
compilation, for debugging . . . . . . . 41 D
compilation, internal stages of . . . . 81
compilation, model for templates ‘D’ option, define macro . . . . . . . . . . 35
. . . . . . . . . . . . . . . . . . . . . . . . . . . 58 data-flow analysis . . . . . . . . . . . . . . . 53
compilation, options . . . . . . . . . . . . . 19 DBM file, created with gdbm . . . . . 20
compilation, stopping on warning debugging, compilation flags . . . . . 41
. . . . . . . . . . . . . . . . . . . . . . . . . . . 33 debugging, with gdb . . . . . . . . . . . . . 41
compile to object file, ‘-c’ option debugging, with optimization . . . . 53
. . . . . . . . . . . . . . . . . . . . . . . . . . . 11 DEC Alpha, platform-specific options
compiled files, examining . . . . . . . . 85 . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
compiler, converting source code to declaration, in header file . . . . . . . . . 9
assembly code . . . . . . . . . . . . . . 82 declaration, missing . . . . . . . . . . . . . 16
compiler, how it works internally default directories, linking and
. . . . . . . . . . . . . . . . . . . . . . . . . . . 81 header files . . . . . . . . . . . . . . . . . 19
compiler-related tools. . . . . . . . . . . . 73 default executable filename, a.out
compiling C programs with gcc . . . 7 ............................ 7
compiling C++ programs with g++ default value, of macro defined with
. . . . . . . . . . . . . . . . . . . . . . . . . . . 55 ‘-D’ . . . . . . . . . . . . . . . . . . . . . . . . 38
compiling files independently . . . . . 11 defining macros . . . . . . . . . . . . . . . . . 35
compiling multiple files . . . . . . . . . . . 9 denormalized numbers, on DEC
compiling with optimization. . . . . . 45 Alpha . . . . . . . . . . . . . . . . . . . . . . 64
configuration files for GCC . . . . . . . 70 dependencies, of shared libraries . . 87
const, warning about overriding by
deployment, options for . . . 41, 50, 53
casts . . . . . . . . . . . . . . . . . . . . . . . 32
dereferencing, null pointer . . . . . . . 42
constant strings, compile-time
warnings . . . . . . . . . . . . . . . . . . . 33 dialects of C language . . . . . . . . . . . 25
consultants, providing commercial different type arg, format warning
support . . . . . . . . . . . . . . . . . . . . 89 ............................ 8
conventions, used in manual . . . . . . . 5 disk space, reduced usage by shared
conversions between types, warning libraries . . . . . . . . . . . . . . . . . . . . 23
of . . . . . . . . . . . . . . . . . . . . . . . . . . 31 displaying a backtrace . . . . . . . . . . . 44
core file, debugging with gdb . . . . . 43 division by zero . . . . . . . . . . . . . . . . . 65
core file, examining from program DLL (dynamically linked library), see
crash. . . . . . . . . . . . . . . . . . . . . . . 41 shared libraries . . . . . . . . . . . . . 23
core file, not produced . . . . . . . . . . . 42 ‘dM’ option, list predefined macros
coverage testing, with gcov . . . . . . 77 . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
CPLUS_INCLUDE_PATH . . . . . . . . . . . . 21 dollar sign $, shell prompt . . . . . . . . 5
cpp, C preprocessor . . . . . . . . . . . . . 35 dynamic loader . . . . . . . . . . . . . . . . . 23
cpp, C++ file extension . . . . . . . . . . . 55 dynamically linked libraries,
‘cr’ option, create/replace archive examining with ldd . . . . . . . . . 87
files . . . . . . . . . . . . . . . . . . . . . . . . 74 dynamically linked library, see shared
crashes, saved in core file . . . . . . . . 41 libraries . . . . . . . . . . . . . . . . . . . . 23
Index 109
link order, from left to right . . 12, 15 manuals, for GNU software . . . . . . 91
link order, of libraries . . . . . . . . . . . 15 ‘march’ option, compile for specific
link order, of object files . . . . . . . . . 12 CPU . . . . . . . . . . . . . . . . . . . . . . . 63
link path, setting with environment math library . . . . . . . . . . . . . . . . . . . . 14
variable . . . . . . . . . . . . . . . . . . . . 22 math library, linking with ‘-lm’. . . 15
linker error, cannot find library ‘mcmodel’ option, for AMD64 . . . . 64
. . . . . . . . . . . . . . . . . . . . . . . . . . . 19 ‘mcpu’ option, compile for specific
linker, GNU compared with other CPU . . . . . . . . . . . . . . . . . . . . . . . 65
linkers . . . . . . . . . . . . . . . . . . . . . 60 ‘mieee’ option, floating-point support
linker, initial description . . . . . . . . . 12 on DEC Alpha . . . . . . . . . . . . . . 64
linker, ld. . . . . . . . . . . . . . . . . . . . 81, 83 minor version number, of GCC . . . 69
linking, creating executable files from MIPS64, multi-architecture support
object files . . . . . . . . . . . . . . . . . 12 . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
linking, default directories . . . . . . . 19 missing header file, causes implicit
linking, dynamic (shared libraries) declaration . . . . . . . . . . . . . . . . . 17
. . . . . . . . . . . . . . . . . . . . . . . . . . . 23 missing header files . . . . . . . . . . . . . . 16
linking, explanation of . . . . . . . . . . . 11 missing prototypes warning . . . . . . 30
linking, undefined reference error due ‘mminimal-toc’ option, on AIX . . . 66
to library link order . . . . . . . . . 16 ‘mno-fused-madd’ option, on
linking, updated object files . . . . . . 13 PowerPC . . . . . . . . . . . . . . . . . . . 66
linking, with external libraries . . . . 14 modified source files, recompiling
linking, with library using ‘-l’ . . . 15 . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Lisp, compared with C/C++ . . . . . . . 5
Motorola 680x0 . . . . . . . . . . . . . . . . . 85
little-endian, word-ordering . . . . . . 85
MSB, most significant byte . . . . . . 85
loader configuration file, ld.so.conf
multi-architecture support, discussion
. . . . . . . . . . . . . . . . . . . . . . . . . . . 25
of . . . . . . . . . . . . . . . . . . . . . . . . . . 66
loader function . . . . . . . . . . . . . . . . . . 23
multiple directories, on include and
login file, setting environment
link paths . . . . . . . . . . . . . . . . . . 22
variables in . . . . . . . . . . . . . . . . . 24
multiple files, compiling . . . . . . . . . . . 9
loop unrolling, optimization . . 47, 50
multiply and add instruction . . . . . 66
LSB, least significant byte . . . . . . . 85
multiply defined symbol error, with
C++ . . . . . . . . . . . . . . . . . . . . . . . . 60
M ‘mxl-call’ option, compatibility with
IBM XL compilers on AIX . . . 66
‘m’ option, platform-specific settings
. . . . . . . . . . . . . . . . . . . . . . . . . . . 63
‘m32’ and ‘m64’ options, compile for
32 or 64-bit environment . . . . 65
N
machine code . . . . . . . . . . . . . . . . . . . . 7 Namespace std in C++ . . . . . . . . . . 57
machine-specific options . . . . . . . . . 63 namespace, reserved prefix for
macros, default value of. . . . . . . . . . 38 preprocessor . . . . . . . . . . . . . . . . 36
macros, defined with value . . . . . . . 36 NaN, not a number, on DEC Alpha
macros, defining in preprocessor . . 35 . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
macros, predefined . . . . . . . . . . . . . . 36 nested comments, warning of . . . . . 29
major features, of GCC . . . . . . . . . . . 4 nm command . . . . . . . . . . . . . . . . . . . . 86
major version number, of GCC . . . 69 No such file or directory, header
‘maltivec’ option, enables use of file not found . . . . . . . . . . . . 19, 20
Altivec processor on PowerPC null pointer, attempt to dereference
. . . . . . . . . . . . . . . . . . . . . . . . . . . 66 . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Index 113