# SOME DESCRIPTIVE TITLE # Copyright (C) YEAR Free Software Foundation, Inc. # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "POT-Creation-Date: 2011-11-29 13:45+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #. type: Plain text msgid "[[!meta title=\"An Introduction to GCC\"]]" msgstr "" #. type: include #, no-wrap msgid "config-local.texi" msgstr "" #. type: top #: #, no-wrap msgid "An Introduction to GCC" msgstr "" #. type: subtitle #, no-wrap msgid "for the GNU Compilers @code{gcc} and @code{g++}" msgstr "" #. type: subtitle #, no-wrap msgid "Revised and updated" msgstr "" #. type: author #, no-wrap msgid "Brian Gough" msgstr "" #. type: author #, no-wrap msgid "Foreword by Richard M.@: Stallman" msgstr "" #. type: flushleft #, no-wrap msgid "" "A catalogue record for this book is available from the British Library.\n" "\n" msgstr "" #. type: flushleft #, no-wrap msgid "" "Second printing, August 2005 (1/8/2005). Revised and updated.\n" "First printing, March 2004 (7/3/2004).\n" "\n" msgstr "" #. type: flushleft #, no-wrap msgid "" "Published by Network Theory Limited.\n" "\n" msgstr "" #. type: flushleft #, no-wrap msgid "" "15 Royal Park\n" "Bristol \n" "BS8 3AL\n" "United Kingdom\n" "\n" msgstr "" #. type: flushleft #, no-wrap msgid "" "Email: info@@network-theory.co.uk\n" "\n" msgstr "" #. type: flushleft #, no-wrap msgid "" "ISBN 0-9541617-9-3\n" "\n" msgstr "" #. type: flushleft #, no-wrap msgid "" "Further information about this book is available from \n" "@uref{http://www.network-theory.co.uk/gcc/intro/}\n" msgstr "" #. type: ifset msgid "" "Cover Image: From a layout of a fast, energy-efficient hardware " "stack.@footnote{``A Fast and Energy-Efficient Stack'' by J.@: Ebergen, D.@: " "Finchelstein, R.@: Kao, J.@: Lexau and R.@: Hopkins.} Image created with the " "free Electric VLSI design system by Steven Rubin of Static Free Software " "(@uref{http://www.staticfreesoft.com/,,www.staticfreesoft.com}). Static " "Free Software provides support for Electric to the electronics design " "industry." msgstr "" #. type: titlepage msgid "Copyright @copyright{} 2004, 2005 Network Theory Ltd." msgstr "" #. type: titlepage msgid "" "Permission is granted to copy, distribute and/or modify this document under " "the terms of the GNU Free Documentation License, Version 1.2 or any later " "version published by the Free Software Foundation; with no Invariant " "Sections, with the Front-Cover Texts being ``A Network Theory Manual'', and " "with the Back-Cover Texts as in (a) below. A copy of the license is " "included in the section entitled ``GNU Free Documentation License''." msgstr "" #. type: titlepage msgid "" "(a) The Back-Cover Text is: ``The development of this manual was funded " "entirely by Network Theory Ltd. Copies published by Network Theory Ltd " "raise money for more free documentation.''" msgstr "" #. type: ifset msgid "" "The Texinfo source for this manual may be obtained from: @* " "@code{http://www.network-theory.co.uk/gcc/intro/src/}" msgstr "" #. type: node #, no-wrap msgid "Top" msgstr "" #. type: Plain text msgid "" "This manual provides an introduction to the GNU C and C++ Compilers, " "@code{gcc} and @code{g++}, which are part of the GNU Compiler Collection " "(GCC)." msgstr "" #. type: Plain text msgid "" "The development of this manual was funded entirely by " "@uref{http://www.network-theory.co.uk/,Network Theory Ltd}. Copies " "published by Network Theory Ltd raise money for more free documentation." msgstr "" #. type: menuentry msgid "Foreword::" msgstr "" #. type: chapter #: #, no-wrap msgid "Introduction" msgstr "" #. type: chapter #: #, no-wrap msgid "Compiling a C program" msgstr "" #. type: chapter #: #, no-wrap msgid "Compilation options" msgstr "" #. type: chapter #: #, no-wrap msgid "Using the preprocessor" msgstr "" #. type: chapter #: #, no-wrap msgid "Compiling for debugging" msgstr "" #. type: chapter #: #, no-wrap msgid "Compiling with optimization" msgstr "" #. type: chapter #: #, no-wrap msgid "Compiling a C++ program" msgstr "" #. type: chapter #: #, no-wrap msgid "Platform-specific options" msgstr "" #. type: chapter #: #, no-wrap msgid "Troubleshooting" msgstr "" #. type: chapter #: #, no-wrap msgid "Compiler-related tools" msgstr "" #. type: chapter #: #, no-wrap msgid "How the compiler works" msgstr "" #. type: chapter #: #, no-wrap msgid "Examining compiled files" msgstr "" #. type: chapter #: #, no-wrap msgid "Common error messages" msgstr "" #. type: chapter #: #, no-wrap msgid "Getting help" msgstr "" #. type: unnumbered #: #, no-wrap msgid "Further reading" msgstr "" #. type: unnumbered #: #, no-wrap msgid "Acknowledgements" msgstr "" #. type: unnumbered #: #, no-wrap msgid "Free software organizations" msgstr "" #. type: unnumbered #: #, no-wrap msgid "Index" msgstr "" #. type: unnumbered #: #, no-wrap msgid "Foreword" msgstr "" #. type: i{#1} msgid "" "This foreword has been kindly contributed by Richard M.@: Stallman, the " "principal author of GCC and founder of the GNU Project." msgstr "" #. type: ifnotinfo msgid "" "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." msgstr "" #. type: ifnotinfo msgid "" "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 " "@emph{technically} good, but that is not enough. Good software must also be " "@emph{ethically} good: it has to respect the users' freedom." msgstr "" #. type: ifnotinfo msgid "" "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 @dfn{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." msgstr "" #. type: ifnotinfo msgid "" "A compiler alone is not enough---to use a computer system, you need a whole " "operating system. In 1983, all operating systems for modern computers 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." msgstr "" #. type: ifnotinfo msgid "" "By the early 90s, the nearly-finished GNU operating system was completed 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." msgstr "" #. type: flushright #, no-wrap msgid "" "Richard M.@: Stallman\n" "February 2004\n" msgstr "" #. type: Plain text msgid "" "The purpose of this book is to explain the use of the GNU C and C++ " "compilers, @code{gcc} and @code{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 (@pxref{Further reading})." msgstr "" #. type: Plain text msgid "" "Experienced programmers who are familiar with other systems, but new to the " "GNU compilers, can skip the early sections of the chapters ``@cite{Compiling " "a C program}'', ``@cite{Using the preprocessor}'' and ``@cite{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." msgstr "" #. type: section #: #, no-wrap msgid "A brief history of GCC" msgstr "" #. type: section #: #, no-wrap msgid "Major features of GCC" msgstr "" #. type: section #: #, no-wrap msgid "Programming in C and C++" msgstr "" #. type: section #: #, no-wrap msgid "Conventions used in this manual" msgstr "" #. type: cindex #, no-wrap msgid "@code{gcc}, GNU C Compiler" msgstr "" #. type: cindex #, no-wrap msgid "C, @code{gcc} compiler" msgstr "" #. type: cindex #, no-wrap msgid "history, of GCC" msgstr "" #. type: cindex #, no-wrap msgid "Richard Stallman, principal author of GCC" msgstr "" #. type: cindex #, no-wrap msgid "GNU Project, history of" msgstr "" #. type: cindex #, no-wrap msgid "Free Software Foundation (FSF)" msgstr "" #. type: Plain text msgid "" "The original author of the GNU C Compiler (GCC) is Richard Stallman, the " "founder of the GNU Project." msgstr "" #. type: Plain text msgid "" "The GNU Project was started in 1984 to create a complete Unix-like operating " "system as free software, in order to promote freedom and cooperation among " "computer users and programmers. Every Unix-like operating system needs a C " "compiler, and as there were no free compilers in existence at that time, the " "GNU Project had to develop one from scratch. The work was funded by " "donations from individuals and companies to the Free Software Foundation, a " "non-profit organization set up to support the work of the GNU Project." msgstr "" #. type: Plain text msgid "" "The first release of GCC was made in 1987. This was a significant " "breakthrough, being the first portable ANSI C optimizing compiler released " "as free software. Since that time GCC has become one of the most important " "tools in the development of free software." msgstr "" #. type: cindex #, no-wrap msgid "C++, @code{g++} compiler" msgstr "" #. type: cindex #, no-wrap msgid "@code{g++}, GNU C++ Compiler" msgstr "" #. type: cindex #, no-wrap msgid "EGCS (Experimental GNU Compiler Suite)" msgstr "" #. type: Plain text msgid "" "A major revision of the compiler came with the 2.0 series in 1992, which " "added the ability to compile C++. In 1997 an experimental branch of the " "compiler (EGCS) was created, to improve optimization and C++ support. " "Following this work, EGCS was adopted as the new main-line of GCC " "development, and these features became widely available in the 3.0 release " "of GCC in 2001." msgstr "" #. type: cindex #, no-wrap msgid "Fortran, @code{g77} compiler" msgstr "" #. type: cindex #, no-wrap msgid "Objective-C" msgstr "" #. type: cindex #, no-wrap msgid "ADA, @code{gnat} compiler" msgstr "" #. type: cindex #, no-wrap msgid "Java, @code{gcj} compiler" msgstr "" #. type: cindex #, no-wrap msgid "@code{g77}, Fortran compiler" msgstr "" #. type: cindex #, no-wrap msgid "@code{gnat}, GNU ADA compiler" msgstr "" #. type: cindex #, no-wrap msgid "@code{gcj}, GNU Compiler for Java" msgstr "" #. type: Plain text msgid "" "Over time GCC has been extended to support many additional languages, " "including Fortran, ADA, Java and Objective-C. The acronym GCC is now used " "to refer to the ``GNU Compiler Collection''. Its development is guided by " "the @dfn{GCC Steering Committee}, a group composed of representatives from " "GCC user communities in industry, research and academia." msgstr "" #. type: cindex #, no-wrap msgid "features, of GCC" msgstr "" #. type: cindex #, no-wrap msgid "major features, of GCC" msgstr "" #. type: cindex #, no-wrap msgid "GNU Compilers, major features" msgstr "" #. type: Plain text msgid "This section describes some of the most important features of GCC." msgstr "" #. type: Plain text msgid "" "First of all, GCC is a portable compiler---it runs on most platforms " "available today, and can produce output for many types of processors. In " "addition to the processors used in personal computers, it also supports " "microcontrollers, DSPs and 64-bit CPUs." msgstr "" #. type: cindex #, no-wrap msgid "embedded systems, cross-compilation for" msgstr "" #. type: Plain text msgid "" "GCC is not only a native compiler---it can also @dfn{cross-compile} any " "program, producing executable files for a different system from the one used " "by GCC itself. This allows software to be compiled for embedded systems " "which are not capable of running a compiler. GCC is written in C with a " "strong focus on portability, and can compile itself, so it can be adapted to " "new systems easily." msgstr "" #. type: Plain text msgid "" "GCC has multiple language @dfn{frontends}, for parsing different languages. " "Programs in each language can be compiled, or cross-compiled, for any " "architecture. For example, an ADA program can be compiled for a " "microcontroller, or a C program for a supercomputer." msgstr "" #. type: Plain text msgid "" "GCC has a modular design, allowing support for new languages and " "architectures to be added. Adding a new language front-end to GCC enables " "the use of that language on any architecture, provided that the necessary " "run-time facilities (such as libraries) are available. Similarly, adding " "support for a new architecture makes it available to all languages." msgstr "" #. type: Plain text msgid "" "Finally, and most importantly, GCC is free software, distributed under the " "GNU General Public License (GNU GPL).@footnote{For details see the license " "file @file{COPYING} distributed with GCC.} This means you have the freedom " "to use and to modify GCC, as with all GNU software. If you need support for " "a new type of CPU, a new language, or a new feature you can add it yourself, " "or hire someone to enhance GCC for you. You can hire someone to fix a bug " "if it is important for your work." msgstr "" #. type: Plain text msgid "" "Furthermore, you have the freedom to share any enhancements you make to " "GCC. As a result of this freedom you can also make use of enhancements to " "GCC developed by others. The many features offered by GCC today show how " "this freedom to cooperate works to benefit you, and everyone else who uses " "GCC." msgstr "" #. type: cindex #, no-wrap msgid "Lisp, compared with C/C++" msgstr "" #. type: cindex #, no-wrap msgid "Smalltalk, compared with C/C++" msgstr "" #. type: cindex #, no-wrap msgid "Scheme, compared with C/C++" msgstr "" #. type: cindex #, no-wrap msgid "Java, compared with C/C++" msgstr "" #. type: cindex #: #, no-wrap msgid "C/C++, risks of using" msgstr "" #. type: cindex #: #, no-wrap msgid "risks, examples of" msgstr "" #. type: Plain text msgid "" "C and C++ are languages that allow direct access to the computer's memory. " "Historically, they have been used for writing low-level systems software, " "and applications where high-performance or control over resource usage are " "critical. However, great care is required to ensure that memory is accessed " "correctly, to avoid corrupting other data-structures. This book describes " "techniques that will help in detecting potential errors during compilation, " "but the risk in using languages like C or C++ can never be eliminated." msgstr "" #. type: Plain text msgid "" "In addition to C and C++ the GNU Project also provides other high-level " "languages, such as GNU Common Lisp (@code{gcl}), GNU Smalltalk (@code{gst}), " "the GNU Scheme extension language (@code{guile}) and the GNU Compiler for " "Java (@code{gcj}). These languages do not allow the user to access memory " "directly, eliminating the possibility of memory access errors. They are a " "safer alternative to C and C++ for many applications." msgstr "" #. type: cindex #, no-wrap msgid "conventions, used in manual" msgstr "" #. type: cindex #, no-wrap msgid "examples, conventions used in" msgstr "" #. type: cindex #, no-wrap msgid "shell prompt" msgstr "" #. type: cindex #, no-wrap msgid "@code{$}, shell prompt" msgstr "" #. type: Plain text msgid "" "This manual contains many examples which can be typed at the keyboard. A " "command entered at the terminal is shown like this," msgstr "" #. type: example #, no-wrap msgid "$ @i{command}\n" msgstr "" #. type: Plain text msgid "followed by its output. For example:" msgstr "" #. type: example #, no-wrap msgid "" "$ echo \"hello world\"\n" "hello world\n" msgstr "" #. type: cindex #, no-wrap msgid "dollar sign @code{$}, shell prompt" msgstr "" #. type: Plain text msgid "" "The first character on the line is the terminal prompt, and should not be " "typed. The dollar sign @samp{$} is used as the standard prompt in this " "manual, although some systems may use a different character." msgstr "" #. type: Plain text msgid "" "When a command in an example is too long to fit in a single line it is " "wrapped and then indented on subsequent lines, like this:" msgstr "" #. type: example #, no-wrap msgid "" "$ echo \"an example of a line which is too long to fit \n" " in this manual\"\n" msgstr "" #. type: Plain text msgid "" "When entered at the keyboard, the entire command should be typed on a single " "line." msgstr "" #. type: Plain text msgid "" "The example source files used in this manual can be downloaded from the " "publisher's website,@footnote{See " "@uref{http://www.network-theory.co.uk/gcc/intro/}} or entered by hand using " "any text editor, such as the standard GNU editor, @code{emacs}. The example " "compilation commands use @code{gcc} and @code{g++} as the names of the GNU C " "and C++ compilers, and @code{cc} to refer to other compilers. The example " "programs should work with any version of GCC. Any command-line options " "which are only available in recent versions of GCC are noted in the text." msgstr "" #. type: cindex #: #, no-wrap msgid "shell variables" msgstr "" #. type: cindex #: #, no-wrap msgid "environment variables" msgstr "" #. type: Plain text msgid "" "The examples assume the use of a GNU operating system---there may be minor " "differences in the output on other systems. Some non-essential and verbose " "system-dependent output messages (such as very long system paths) have been " "edited in the examples for brevity. The commands for setting environment " "variables use the syntax of the standard GNU shell (@code{bash}), and should " "work with any version of the Bourne shell." msgstr "" #. type: cindex #, no-wrap msgid "compiling C programs with @code{gcc}" msgstr "" #. type: Plain text msgid "" "This chapter describes how to compile C programs using @code{gcc}. Programs " "can be compiled from a single source file or from multiple source files, and " "may use system libraries and header files." msgstr "" #. type: cindex #, no-wrap msgid "source code" msgstr "" #. type: cindex #, no-wrap msgid "machine code" msgstr "" #. type: cindex #, no-wrap msgid "executable file" msgstr "" #. type: cindex #, no-wrap msgid "binary file, also called executable file" msgstr "" #. type: Plain text msgid "" "Compilation refers to the process of converting a program from the textual " "@dfn{source code}, in a programming language such as C or C++, into " "@dfn{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 @dfn{executable file}, sometimes referred to as a " "@dfn{binary file}." msgstr "" #. type: section #: #, no-wrap msgid "Compiling a simple C program" msgstr "" #. type: section #: #, no-wrap msgid "Finding errors in a simple program" msgstr "" #. type: section #: #, no-wrap msgid "Compiling multiple source files" msgstr "" #. type: section #: #, no-wrap msgid "Compiling files independently" msgstr "" #. type: section #: #, no-wrap msgid "Recompiling and relinking" msgstr "" #. type: section #: #, no-wrap msgid "A simple makefile" msgstr "" #. type: section #: #, no-wrap msgid "Linking with external libraries" msgstr "" #. type: section #: #, no-wrap msgid "Using library header files" msgstr "" #. type: cindex #, no-wrap msgid "Hello World program, in C" msgstr "" #. type: cindex #, no-wrap msgid "C, compiling with @code{gcc}" msgstr "" #. type: cindex #, no-wrap msgid "simple C program, compiling" msgstr "" #. type: Plain text msgid "" "The classic example program for the C language is @dfn{Hello World}. Here " "is the source code for our version of the program:" msgstr "" #. type: example #: #, no-wrap msgid "@verbatiminclude hello.c\n" msgstr "" #. type: cindex #, no-wrap msgid "@code{.c}, C source file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{c}, C source file extension" msgstr "" #. type: cindex #, no-wrap msgid "C source file, @code{.c} extension" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.c} source file" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.c} source file" msgstr "" #. type: Plain text msgid "" "We will assume that the source code is stored in a file called " "@file{hello.c}. To compile the file @file{hello.c} with @code{gcc}, use the " "following command:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall hello.c -o hello\n" msgstr "" #. type: cindex #, no-wrap msgid "@code{gcc}, simple example" msgstr "" #. type: cindex #, no-wrap msgid "@option{-o} option, set output filename" msgstr "" #. type: cindex #, no-wrap msgid "@option{o} option, set output filename" msgstr "" #. type: cindex #, no-wrap msgid "output file option, @option{-o}" msgstr "" #. type: cindex #, no-wrap msgid "@code{a.out}, default executable filename" msgstr "" #. type: cindex #, no-wrap msgid "executable, default filename @code{a.out}" msgstr "" #. type: cindex #, no-wrap msgid "default executable filename, @code{a.out}" msgstr "" #. type: Plain text msgid "" "This compiles the source code in @file{hello.c} to machine code and stores " "it in an executable file @file{hello}. The output file for the machine code " "is specified using the @option{-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 @file{a.out}." msgstr "" #. type: Plain text msgid "" "Note that if a file with the same name as the executable file already exists " "in the current directory it will be overwritten." msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wall} option, enable common warnings" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wall} option, enable common warnings" msgstr "" #. type: cindex #, no-wrap msgid "warning options, @option{-Wall}" msgstr "" #. type: Plain text msgid "" "The option @option{-Wall} turns on all the most commonly-used compiler " "warnings---@strong{it is recommended that you always use this option!} There " "are many other warning options which will be discussed in later chapters, " "but @option{-Wall} is the most important. GCC will not produce any warnings " "unless they are enabled. Compiler warnings are an essential aid in " "detecting problems when programming in C and C++." msgstr "" #. type: Plain text msgid "" "In this case, the compiler does not produce any warnings with the " "@option{-Wall} option, since the program is completely valid. Source code " "which does not produce any warnings is said to @dfn{compile cleanly}." msgstr "" #. type: cindex #, no-wrap msgid "executable, running" msgstr "" #. type: cindex #, no-wrap msgid "running an executable file, C" msgstr "" #. type: Plain text msgid "To run the program, type the path name of the executable like this:" msgstr "" #. type: example #: #, no-wrap msgid "" "$ ./hello\n" "Hello, world!\n" msgstr "" #. type: Plain text msgid "" "This loads the executable file into memory and causes the CPU to begin " "executing the instructions contained within it. The path @code{./} refers " "to the current directory, so @code{./hello} loads and runs the executable " "file @file{hello} located in the current directory." msgstr "" #. type: cindex #, no-wrap msgid "@code{printf}, example of error in format" msgstr "" #. type: Plain text msgid "" "As mentioned above, compiler warnings are an essential aid when programming " "in C and C++. To demonstrate this, the program below contains a subtle " "error: it uses the function @code{printf} incorrectly, by specifying a " "floating-point format @samp{%f} for an integer value:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude bad.c\n" msgstr "" #. type: Plain text msgid "" "This error is not obvious at first sight, but can be detected by the " "compiler if the warning option @option{-Wall} has been enabled." msgstr "" #. type: Plain text msgid "" "Compiling the program above, @file{bad.c}, with the warning option " "@option{-Wall} produces the following message:" msgstr "" #. type: cindex #, no-wrap msgid "warning, format with different type arg" msgstr "" #. type: cindex #, no-wrap msgid "format, different type arg warning" msgstr "" #. type: cindex #, no-wrap msgid "different type arg, format warning" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall bad.c -o bad " "\n" "bad.c: In function 'main':\n" "bad.c:6:3: warning: format '%f' expects argument of\n" "type 'double', but argument 2 has type 'int' [-Wformat]\n" msgstr "" #. type: Plain text msgid "" "This indicates that a format string has been used incorrectly in the file " "@file{bad.c} at line 6. The messages produced by GCC always have the form " "@i{file:line-number:message}. The compiler distinguishes between @dfn{error " "messages}, which prevent successful compilation, and @dfn{warning messages} " "which indicate possible problems (but do not stop the program from " "compiling)." msgstr "" #. type: Plain text msgid "" "In this case, the correct format specifier should be @samp{%d} for an " "integer argument. The allowed format specifiers for @code{printf} can be " "found in any general book on C, such as the @cite{GNU C Library Reference " "Manual} (@pxref{Further reading})." msgstr "" #. type: Plain text msgid "" "Without the warning option @option{-Wall} the program appears to compile " "cleanly, but produces incorrect results:" msgstr "" #. type: cindex #: #, no-wrap msgid "bug, example of" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc bad.c -o bad\n" "$ ./bad\n" "Two plus two is 0.000000 @r{(incorrect output)}\n" msgstr "" #. type: Plain text msgid "" "The incorrect format specifier causes the output to be corrupted, because " "the function @code{printf} is passed an integer instead of a floating-point " "number. Integers and floating-point numbers are stored in different formats " "in memory, and generally occupy different numbers of bytes, leading to a " "spurious result. The actual output shown above may differ, depending on the " "specific platform and environment." msgstr "" #. type: Plain text msgid "" "Clearly, it is very dangerous to develop a program without checking for " "compiler warnings. If there are any functions which are not used correctly " "they can cause the program to crash or produce incorrect results. Turning on " "the compiler warning option @option{-Wall} will catch many of the commonest " "errors which occur in C programming." msgstr "" #. type: cindex #, no-wrap msgid "multiple files, compiling" msgstr "" #. type: cindex #, no-wrap msgid "compiling multiple files" msgstr "" #. type: Plain text msgid "" "A program can be split up into multiple files. This makes it easier to edit " "and understand, especially in the case of large programs---it also allows " "the individual parts to be compiled independently." msgstr "" #. type: Plain text msgid "" "In the following example we will split up the program @dfn{Hello World} into " "three files: @file{main.c}, @file{hello_fn.c} and the header file " "@file{hello.h}. Here is the main program @file{main.c}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude main.c\n" msgstr "" #. type: Plain text msgid "" "The original call to the @code{printf} system function in the previous " "program @file{hello.c} has been replaced by a call to a new external " "function @code{hello}, which we will define in a separate file " "@file{hello_fn.c}." msgstr "" #. type: cindex #, no-wrap msgid "declaration, in header file" msgstr "" #. type: cindex #, no-wrap msgid "header file, declarations in" msgstr "" #. type: cindex #, no-wrap msgid "@code{.h}, header file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{h}, header file extension" msgstr "" #. type: cindex #, no-wrap msgid "header file, @code{.h} extension" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.h} header file" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.h} header file" msgstr "" #. type: Plain text msgid "" "The main program also includes the header file @file{hello.h} which will " "contain the declaration of the function @code{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 " "longer need to include the system header file @file{stdio.h} in " "@file{main.c} to declare the function @code{printf}, since the file " "@file{main.c} does not call @code{printf} directly." msgstr "" #. type: Plain text msgid "" "The declaration in @file{hello.h} is a single line specifying the prototype " "of the function @code{hello}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude hello1.h\n" msgstr "" #. type: Plain text msgid "" "The definition of the function @code{hello} itself is contained in the file " "@file{hello_fn.c}:" msgstr "" #. type: example #: #, no-wrap msgid "@verbatiminclude hello_fn.c\n" msgstr "" #. type: Plain text msgid "" "This function prints the message ``@code{Hello, }@var{name}@code{!}'' using " "its argument as the value of @var{name}." msgstr "" #. type: cindex #, no-wrap msgid "@code{#include}, preprocessor directive" msgstr "" #. type: Plain text msgid "" "Incidentally, the difference between the two forms of the include statement " "@code{#include \"@var{FILE}.h\"} and @code{#include <@var{FILE}.h>} is that " "the former searches for @file{@var{FILE}.h} in the current directory before " "looking in the system header file directories. The include statement " "@code{#include <@var{FILE}.h>} searches the system header files, but does " "not look in the current directory by default." msgstr "" #. type: Plain text msgid "To compile these source files with @code{gcc}, use the following command:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall main.c hello_fn.c -o newhello\n" msgstr "" #. type: Plain text msgid "" "In this case, we use the @option{-o} option to specify a different output " "file for the executable, @file{newhello}. Note that the header file " "@file{hello.h} is not specified in the list of files on the command line. " "The directive @code{#include \"hello.h\"} in the source files instructs the " "compiler to include it automatically at the appropriate points." msgstr "" #. type: Plain text msgid "To run the program, type the path name of the executable:" msgstr "" #. type: example #, no-wrap msgid "" "$ ./newhello\n" "Hello, world!\n" msgstr "" #. type: Plain text msgid "" "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." msgstr "" #. type: cindex #, no-wrap msgid "compiling files independently" msgstr "" #. type: cindex #, no-wrap msgid "independent compilation of files" msgstr "" #. type: Plain text msgid "" "If a program is stored in a single file then any change to an individual " "function requires the whole program to be recompiled to produce a new " "executable. The recompilation of large source files can be very " "time-consuming." msgstr "" #. type: cindex #, no-wrap msgid "linking, explanation of" msgstr "" #. type: cindex #, no-wrap msgid "object file, explanation of" msgstr "" #. type: cindex #, no-wrap msgid "@code{.o}, object file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{o}, object file extension" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.o} object file" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.o} object file" msgstr "" #. type: cindex #, no-wrap msgid "object file, @code{.o} extension" msgstr "" #. type: Plain text msgid "" "When programs are stored in independent source files, only the files which " "have changed need to be recompiled after the source code has been modified. " "In this approach, the source files are compiled separately and then " "@dfn{linked} together---a two stage process. In the first stage, a file is " "compiled without creating an executable. The result is referred to as an " "@dfn{object file}, and has the extension @file{.o} when using GCC." msgstr "" #. type: Plain text msgid "" "In the second stage, the object files are merged together by a separate " "program called the @dfn{linker}. The linker combines all the object files " "to create a single executable." msgstr "" #. type: Plain text msgid "" "An object file contains machine code where any references to the memory " "addresses of functions (or variables) in other files are left undefined. " "This allows source files to be compiled without direct reference to each " "other. The linker fills in these missing addresses when it produces the " "executable." msgstr "" #. type: subsection #: #, no-wrap msgid "Creating object files from source files" msgstr "" #. type: subsection #: #, no-wrap msgid "Creating executables from object files" msgstr "" #. type: cindex #, no-wrap msgid "creating object files from source files" msgstr "" #. type: cindex #, no-wrap msgid "@option{-c} option, compile to object file" msgstr "" #. type: cindex #, no-wrap msgid "@option{c} option, compile to object file" msgstr "" #. type: cindex #, no-wrap msgid "compile to object file, @option{-c} option" msgstr "" #. type: cindex #, no-wrap msgid "object file, creating from source using option @option{-c}" msgstr "" #. type: Plain text msgid "" "The command-line option @option{-c} is used to compile a source file to an " "object file. For example, the following command will compile the source " "file @file{main.c} to an object file:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -c main.c\n" msgstr "" #. type: Plain text msgid "" "This produces an object file @file{main.o} containing the machine code for " "the @code{main} function. It contains a reference to the external function " "@code{hello}, but the corresponding memory address is left undefined in the " "object file at this stage (it will be filled in later by linking)." msgstr "" #. type: Plain text msgid "" "The corresponding command for compiling the @code{hello} function in the " "source file @file{hello_fn.c} is:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -c hello_fn.c\n" msgstr "" #. type: Plain text msgid "This produces the object file @file{hello_fn.o}." msgstr "" #. type: Plain text msgid "" "Note that there is no need to use the option @option{-o} to specify the name " "of the output file in this case. When compiling with @option{-c} the " "compiler automatically creates an object file whose name is the same as the " "source file, but with @file{.o} instead of the original extension." msgstr "" #. type: cindex #, no-wrap msgid "header file, not compiled" msgstr "" #. type: Plain text msgid "" "There is no need to put the header file @file{hello.h} on the command line, " "since it is automatically included by the @code{#include} statements in " "@file{main.c} and @file{hello_fn.c}." msgstr "" #. type: cindex #, no-wrap msgid "creating executable files from object files" msgstr "" #. type: cindex #, no-wrap msgid "linking, creating executable files from object files" msgstr "" #. type: cindex #, no-wrap msgid "executable, creating from object files by linking" msgstr "" #. type: cindex #, no-wrap msgid "object files, linking to create executable file" msgstr "" #. type: Plain text msgid "" "The final step in creating an executable file is to use @code{gcc} to link " "the object files together and fill in the missing addresses of external " "functions. To link object files together, they are simply listed on the " "command line:" msgstr "" #. type: example #, no-wrap msgid "$ gcc main.o hello_fn.o -o hello\n" msgstr "" #. type: Plain text msgid "" "This is one of the few occasions where there is no need to use the " "@option{-Wall} warning option, since the individual source files have " "already been successfully compiled to object code. Once the source files " "have been compiled, linking is an unambiguous process which either succeeds " "or fails (it fails only if there are references which cannot be resolved)." msgstr "" #. type: cindex #, no-wrap msgid "linker, initial description" msgstr "" #. type: Plain text msgid "" "To perform the linking step @code{gcc} uses the linker @code{ld}, which is a " "separate program. On GNU systems the GNU linker, GNU @code{ld}, is used. " "Other systems may use the GNU linker with GCC, or may have their own " "linkers. The linker itself will be discussed later (@pxref{How the compiler " "works}). By running the linker, @code{gcc} creates an executable file from " "the object files." msgstr "" #. type: Plain text msgid "The resulting executable file can now be run:" msgstr "" #. type: Plain text msgid "" "It produces the same output as the version of the program using a single " "source file in the previous section." msgstr "" #. type: cindex #: #, no-wrap msgid "recompiling modified source files" msgstr "" #. type: cindex #: #, no-wrap msgid "relinking updated object files" msgstr "" #. type: cindex #: #, no-wrap msgid "modified source files, recompiling" msgstr "" #. type: cindex #, no-wrap msgid "updated object files, relinking" msgstr "" #. type: cindex #, no-wrap msgid "source files, recompiling" msgstr "" #. type: cindex #, no-wrap msgid "object files, relinking" msgstr "" #. type: cindex #, no-wrap msgid "C programs, recompiling after modification" msgstr "" #. type: Plain text msgid "" "To show how source files can be compiled independently we will edit the main " "program @file{main.c} and modify it to print a greeting to @code{everyone} " "instead of @code{world}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude main2.c\n" msgstr "" #. type: Plain text msgid "" "The updated file @file{main.c} can now be recompiled with the following " "command:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -c main2.c\n" msgstr "" #. type: cindex #, no-wrap msgid "updated source files, recompiling" msgstr "" #. type: Plain text msgid "" "This produces a new object file @file{main.o}. There is no need to create a " "new object file for @file{hello_fn.c}, since that file and the related files " "that it depends on, such as header files, have not changed." msgstr "" #. type: cindex #, no-wrap msgid "linking, updated object files" msgstr "" #. type: Plain text msgid "" "The new object file can be relinked with the @code{hello} function to create " "a new executable file:" msgstr "" #. type: example #, no-wrap msgid "$ gcc main2.o hello_fn.o -o hello\n" msgstr "" #. type: Plain text msgid "" "The resulting executable @file{hello} now uses the new @code{main} function " "to produce the following output:" msgstr "" #. type: example #, no-wrap msgid "" "$ ./hello\n" "Hello, everyone!\n" msgstr "" #. type: Plain text msgid "" "Note that only the file @file{main.c} has been recompiled, and then relinked " "with the existing object file for the @code{hello} function. If the file " "@file{hello_fn.c} had been modified instead, we could have recompiled " "@file{hello_fn.c} to create a new object file @file{hello_fn.o} and relinked " "this with the existing file @file{main.o}.@footnote{If the prototype of a " "function has changed, it is necessary to modify and recompile all of the " "other source files which use it.}" msgstr "" #. type: Plain text msgid "" "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 files in a project can be automated with the standard Unix " "program @code{make}." msgstr "" #. type: cindex #, no-wrap msgid "makefile, example of" msgstr "" #. type: cindex #, no-wrap msgid "GNU Make" msgstr "" #. type: Plain text msgid "" "For those unfamiliar with @code{make}, this section provides a simple " "demonstration of its use. Make is a program in its own right and can be " "found on all Unix systems. To learn more about the GNU version of " "@code{make} you will need to consult the @cite{GNU Make} manual by Richard " "M. Stallman and Roland McGrath (@pxref{Further reading})." msgstr "" #. type: cindex #, no-wrap msgid "target, in makefile" msgstr "" #. type: cindex #, no-wrap msgid "dependency, in makefile" msgstr "" #. type: cindex #, no-wrap msgid "command, in makefile" msgstr "" #. type: Plain text msgid "" "Make reads a description of a project from a @dfn{makefile} (by default, " "called @file{Makefile} in the current directory). A makefile specifies a " "set of compilation rules in terms of @dfn{targets} (such as executables) and " "their @dfn{dependencies} (such as object files and source files) in the " "following format:" msgstr "" #. type: example #, no-wrap msgid "" "@i{target}: @i{dependencies}\n" " @i{command}\n" msgstr "" #. type: cindex #, no-wrap msgid "tab, in makefiles" msgstr "" #. type: cindex #, no-wrap msgid "separator, in makefiles" msgstr "" #. type: Plain text msgid "" "For each target, make checks the modification time of the corresponding " "dependency files to determine whether the target needs to be rebuilt using " "the corresponding command. Note that the @code{@i{command}} lines in a " "makefile must be indented with a single @key{TAB} character, not spaces." msgstr "" #. type: cindex #, no-wrap msgid "implicit rules, in makefile" msgstr "" #. type: cindex #, no-wrap msgid "rules, in makefile" msgstr "" #. type: cindex #, no-wrap msgid "@code{CFLAGS}, make variable" msgstr "" #. type: cindex #, no-wrap msgid "@code{CC}, make variable" msgstr "" #. type: cindex #, no-wrap msgid "@code{CXX}, make variable" msgstr "" #. type: cindex #, no-wrap msgid "@code{CXXFLAGS}, make variable" msgstr "" #. type: cindex #, no-wrap msgid "@code{CPPFLAGS}, make variable" msgstr "" #. type: cindex #, no-wrap msgid "variables, in make" msgstr "" #. type: Plain text msgid "" "GNU Make contains many default rules, referred to as @dfn{implicit} rules, " "to simplify the construction of makefiles. For example, these specify that " "@file{.o} files can be obtained from @file{.c} files by compilation, and " "that an executable can be made by linking together @file{.o} files. " "Implicit rules are defined in terms of @dfn{make variables}, such as " "@code{CC} (the C compiler) and @code{CFLAGS} (the compilation options for C " "programs), which can be set using @code{@i{VARIABLE}=@i{VALUE}} lines in the " "makefile. For C++ the equivalent variables are @code{CXX} and " "@code{CXXFLAGS}, while the make variable @code{CPPFLAGS} sets the " "preprocessor options. The implicit and user-defined rules are automatically " "chained together as necessary by GNU Make." msgstr "" #. type: Plain text msgid "A simple @file{Makefile} for the project above can be written as follows:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude c1makefile2\n" msgstr "" #. type: Plain text msgid "" "The file can be read like this: using the C compiler @command{gcc}, with " "compilation option @option{-Wall}, build the target executable @code{main} " "from the object files @file{main.o} and @file{hello_fn.o} (these, in turn, " "will be built via implicit rules from @file{main.c} and @file{hello_fn.c}). " "The target @code{clean} has no dependencies and simply removes all the " "compiled files.@footnote{This assumes that there is no file called " "@file{clean} in the current directory---see the discussion of ``phony " "targets'' in the GNU Make manual for details.} The option @option{-f} " "(force) on the @command{rm} command suppresses any error messages if the " "files do not exist." msgstr "" #. type: Plain text msgid "" "To use the makefile, type @command{make}. When called with no arguments, " "the first target in the makefile is built, producing the executable " "@file{main}:" msgstr "" #. type: example #, no-wrap msgid "" "$ make\n" "gcc -Wall -c -o main.o main.c\n" "gcc -Wall -c -o hello_fn.o hello_fn.c\n" "gcc main.o hello_fn.o -o main\n" "$ ./main\n" "Hello, world!\n" msgstr "" #. type: Plain text msgid "" "To rebuild the executable after modifying a source file, simply type " "@command{make} again. By checking the timestamps of the target and " "dependency files, make identifies the files which have changed and " "regenerates the corresponding intermediate files needed to update the " "targets:" msgstr "" #. type: example #, no-wrap msgid "" "$ emacs main.c @r{(edit the file)}\n" "$ make\n" "gcc -Wall -c -o main.o main.c\n" "gcc main.o hello_fn.o -o main\n" "$ ./main\n" "Hello, everyone!\n" msgstr "" #. type: Plain text msgid "Finally, to remove the generated files, type @command{make clean}:" msgstr "" #. type: example #, no-wrap msgid "" "$ make clean\n" "rm -f main main.o hello_fn.o\n" msgstr "" #. type: Plain text msgid "" "A more sophisticated makefile would usually contain additional targets for " "installation (@code{make install}) and testing (@code{make check})." msgstr "" #. type: Plain text msgid "" "The examples in the rest of this book are small enough not to need " "makefiles, but the use of make is recommended for any larger programs." msgstr "" #. type: cindex #, no-wrap msgid "linking, with external libraries" msgstr "" #. type: cindex #: #, no-wrap msgid "libraries, linking with" msgstr "" #. type: cindex #, no-wrap msgid "@code{sqrt}, example of linking with" msgstr "" #. type: cindex #, no-wrap msgid "C math library" msgstr "" #. type: cindex #, no-wrap msgid "library, C math library" msgstr "" #. type: cindex #, no-wrap msgid "math library" msgstr "" #. type: cindex #, no-wrap msgid "system libraries" msgstr "" #. type: cindex #, no-wrap msgid "external libraries, linking with" msgstr "" #. type: Plain text msgid "" "A library is a collection of precompiled object files which can be linked " "into programs. The most common use of libraries is to provide system " "functions, such as the square root function @code{sqrt} found in the C math " "library." msgstr "" #. type: cindex #, no-wrap msgid "libraries, stored in archive files" msgstr "" #. type: cindex #, no-wrap msgid "archive file, explanation of" msgstr "" #. type: cindex #, no-wrap msgid "@code{.a}, archive file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{a}, archive file extension" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.a} archive file" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.a} archive file" msgstr "" #. type: cindex #, no-wrap msgid "archive file, @code{.a} extension" msgstr "" #. type: cindex #, no-wrap msgid "GNU archiver, @code{ar}" msgstr "" #. type: cindex #: #, no-wrap msgid "@code{ar}, GNU archiver" msgstr "" #. type: Plain text msgid "" "Libraries are typically stored in special @dfn{archive files} with the " "extension @file{.a}, referred to as @dfn{static libraries}. They are " "created from object files with a separate tool, the GNU archiver @code{ar}, " "and used by the linker to resolve references to functions at compile-time. " "We will see later how to create libraries using the @command{ar} command " "(@pxref{Compiler-related tools}). For simplicity, only static libraries are " "covered in this section---dynamic linking at runtime using @dfn{shared " "libraries} will be described in the next chapter." msgstr "" #. type: cindex #: #, no-wrap msgid "system libraries, location of" msgstr "" #. type: cindex #, no-wrap msgid "C standard library" msgstr "" #. type: cindex #: #, no-wrap msgid "C library, standard" msgstr "" #. type: cindex #, no-wrap msgid "standard library, C" msgstr "" #. type: cindex #, no-wrap msgid "library, C standard library" msgstr "" #. type: Plain text msgid "" "The standard system libraries are usually found in the directories " "@file{/usr/lib} and @file{/lib}.@footnote{On systems supporting both 64 and " "32-bit executables the 64-bit versions of the libraries will often be stored " "in @file{/usr/lib64} and @file{/lib64}, with the 32-bit versions in " "@file{/usr/lib} and @file{/lib}. Libraries may sometimes be also found in " "an architecture-specific directory, such as @file{/usr/lib/i386-linux-gnu/}} " "For example, the C math library is typically stored in the file " "@file{/usr/lib/libm.a} on Unix-like systems. The corresponding prototype " "declarations for the functions in this library are given in the header file " "@file{/usr/include/math.h}. The C standard library itself is stored in " "@file{/usr/lib/libc.a} and contains functions specified in the ANSI/ISO C " "standard, such as @samp{printf}---this library is linked by default for " "every C program." msgstr "" #. type: Plain text msgid "" "Here is an example program which makes a call to the external function " "@code{sqrt} in the math library @file{libm.a}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude calc.c\n" msgstr "" #. type: Plain text msgid "" "Trying to create an executable from this source file alone causes the " "compiler to give an error at the link stage:" msgstr "" #. type: cindex #: #, no-wrap msgid "undefined reference error" msgstr "" #. type: cindex #, no-wrap msgid "reference, undefined due to missing library" msgstr "" #. type: cindex #, no-wrap msgid "libraries, link error due to undefined reference" msgstr "" #. type: group #, no-wrap msgid "" "$ gcc -Wall calc.c -o calc\n" "/tmp/ccbR6Ojm.o: In function `main':\n" "/tmp/ccbR6Ojm.o(.text+0x19): undefined reference \n" " to `sqrt'\n" msgstr "" #. type: Plain text msgid "" "The problem is that the reference to the @code{sqrt} function cannot be " "resolved without the external math library @file{libm.a}. The function " "@code{sqrt} is not defined in the program or the default library " "@file{libc.a}, and the compiler does not link to the file @file{libm.a} " "unless it is explicitly selected." msgstr "" #. type: cindex #, no-wrap msgid "@file{/tmp} directory, temporary files" msgstr "" #. type: cindex #, no-wrap msgid "temporary files, written to @file{/tmp}" msgstr "" #. type: cindex #, no-wrap msgid "object files, temporary" msgstr "" #. type: Plain text msgid "" "Incidentally, the file mentioned in the error message @file{/tmp/ccbR60jm.o} " "is a temporary object file created by the compiler from @file{calc.c}, in " "order to carry out the linking process." msgstr "" #. type: Plain text msgid "" "To enable the compiler to link the @code{sqrt} function to the main program " "@file{calc.c} we need to supply the library @file{libm.a}. One obvious but " "cumbersome way to do this is to specify it explicitly on the command line:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall calc.c /usr/lib/libm.a -o calc\n" msgstr "" #. type: Plain text msgid "" "The library @file{libm.a} contains object files for all the mathematical " "functions, such as @code{sin}, @code{cos}, @code{exp}, @code{log} and " "@code{sqrt}. The linker searches through these to find the object file " "containing the @code{sqrt} function." msgstr "" #. type: Plain text msgid "" "Once the object file for the @code{sqrt} function has been found, the main " "program can be linked and a complete executable produced:" msgstr "" #. type: example #, no-wrap msgid "" "$ ./calc \n" "The square root of 2.0 is 1.414214\n" msgstr "" #. type: Plain text msgid "" "The executable file includes the machine code for the main function and the " "machine code for the @code{sqrt} function, copied from the corresponding " "object file in the library @file{libm.a}." msgstr "" #. type: cindex #, no-wrap msgid "linking, with library using @option{-l}" msgstr "" #. type: cindex #, no-wrap msgid "@option{-l} option, linking with libraries" msgstr "" #. type: cindex #, no-wrap msgid "@option{-lm} option, link with math library" msgstr "" #. type: cindex #, no-wrap msgid "@option{l} option, linking with libraries" msgstr "" #. type: cindex #, no-wrap msgid "math library, linking with @option{-lm}" msgstr "" #. type: Plain text msgid "" "To avoid the need to specify long paths on the command line, the compiler " "provides a short-cut option @samp{-l} for linking against libraries. For " "example, the following command," msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall calc.c -lm -o calc\n" msgstr "" #. type: Plain text msgid "" "is equivalent to the original command above using the full library name " "@file{/usr/lib/libm.a}." msgstr "" #. type: Plain text msgid "" "In general, the compiler option @option{-l@var{NAME}} will attempt to link " "object files with a library file @file{lib@var{NAME}.a} in the standard " "library directories. Additional directories can specified with command-line " "options and environment variables, to be discussed shortly. A large program " "will typically use many @option{-l} options to link libraries such as the " "math library, graphics libraries and networking libraries." msgstr "" #. type: subsection #: #, no-wrap msgid "Link order of libraries" msgstr "" #. type: cindex #: #, no-wrap msgid "libraries, link order" msgstr "" #. type: cindex #, no-wrap msgid "link order, of libraries" msgstr "" #. type: cindex #, no-wrap msgid "link order, from left to right" msgstr "" #. type: Plain text msgid "" "The traditional behavior of linkers is to search for external functions from " "left to right in the libraries specified on the command line. This means " "that a library containing the definition of a function should appear after " "any source files or object files which use it. This includes libraries " "specified with the short-cut @option{-l} option, as shown in the following " "command:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall calc.c -lm -o calc @r{(correct order)}\n" msgstr "" #. type: Plain text msgid "" "With some linkers the opposite ordering (placing the @option{-lm} option " "before the file which uses it) would result in an error," msgstr "" #. type: example #, no-wrap msgid "" "$ cc -Wall -lm calc.c -o calc @r{(incorrect order)}\n" "main.o: In function `main':\n" "main.o(.text+0xf): undefined reference to `sqrt'\n" msgstr "" #. type: cindex #, no-wrap msgid "error, undefined reference due to library link order" msgstr "" #. type: cindex #, no-wrap msgid "linking, undefined reference error due to library link order" msgstr "" #. type: Plain text msgid "" "because there is no library or object file containing @code{sqrt} after " "@file{calc.c}. The option @option{-lm} should appear after the file " "@file{calc.c}." msgstr "" #. type: Plain text msgid "" "When several libraries are being used, the same convention should be " "followed for the libraries themselves. A library which calls an external " "function defined in another library should appear before the library " "containing the function." msgstr "" #. type: cindex #, no-wrap msgid "ordering of libraries" msgstr "" #. type: Plain text msgid "" "For example, a program @file{data.c} using the GNU Linear Programming " "library @file{libglpk.a}, which in turn uses the math library @file{libm.a}, " "should be compiled as," msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall data.c -lglpk -lm\n" msgstr "" #. type: Plain text msgid "" "since the object files in @file{libglpk.a} use functions defined in " "@file{libm.a}." msgstr "" #. type: Plain text msgid "" "Most current linkers will search all libraries, regardless of order, but " "since some do not do this it is best to follow the convention of ordering " "libraries from left to right." msgstr "" #. type: Plain text msgid "" "This is worth keeping in mind if you ever encounter unexpected problems with " "undefined references, and all the necessary libraries appear to be present " "on the command line." msgstr "" #. type: cindex #, no-wrap msgid "header file, missing" msgstr "" #. type: cindex #, no-wrap msgid "declaration, missing" msgstr "" #. type: cindex #, no-wrap msgid "missing header files" msgstr "" #. type: cindex #, no-wrap msgid "library header files, using" msgstr "" #. type: Plain text msgid "" "When using a library it is essential to include the appropriate header " "files, in order to declare the function arguments and return values with the " "correct types. Without declarations, the arguments of a function can be " "passed with the wrong type, causing corrupted results." msgstr "" #. type: Plain text msgid "" "The following example shows another program which makes a function call to " "the C standard library. In this case, the function @code{strtod} is used to " "convert a string @code{\"123\"} to a floating-point number:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude badconv.c\n" msgstr "" #. type: Plain text msgid "" "However, the program contains an error---the @code{#include} statement for " "the required header file @file{stdlib.h} is missing, so the prototype " "@code{double strtod (const char * string, char * tail)} given there will not " "be seen by the compiler." msgstr "" #. type: Plain text msgid "" "Compiling the program without any warning options will produce an executable " "file which gives incorrect results:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc badconv.c -lm\n" "$ ./a.out\n" "Value is 966656.000000 @r{(incorrect result, should be 123.0)}\n" msgstr "" #. type: Plain text msgid "" "The results are corrupted because the arguments and return value of the call " "to @code{strtod} are passed with incorrect types.@footnote{The actual output " "shown above may differ, depending on the specific platform and environment.} " "This can be detected by turning on the warning option @option{-Wall}:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall badconv.c -lm\n" "badconv.c: In function `main':\n" "badconv.c:6: warning: implicit declaration of \n" " function `strtod'\n" msgstr "" #. type: cindex #: #, no-wrap msgid "implicit declaration of function" msgstr "" #. type: cindex #, no-wrap msgid "header file, missing header causes implicit declaration" msgstr "" #. type: cindex #, no-wrap msgid "missing header file, causes implicit declaration" msgstr "" #. type: Plain text msgid "" "This example shows again the importance of using the warning option " "@option{-Wall} to detect serious problems that could otherwise easily be " "overlooked." msgstr "" #. type: cindex #, no-wrap msgid "compilation, options" msgstr "" #. type: cindex #, no-wrap msgid "options, compilation" msgstr "" #. type: Plain text msgid "" "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." msgstr "" #. type: section #: #, no-wrap msgid "Setting search paths" msgstr "" #. type: section #: #, no-wrap msgid "Shared libraries and static libraries" msgstr "" #. type: section #: #, no-wrap msgid "C language standards" msgstr "" #. type: node #: #, no-wrap msgid "Warning options in -Wall" msgstr "" #. type: section #: #, no-wrap msgid "Additional warning options" msgstr "" #. type: section #: #, no-wrap msgid "Recommended warning options" msgstr "" #. type: cindex #, no-wrap msgid "search paths" msgstr "" #. type: cindex #, no-wrap msgid "paths, search" msgstr "" #. type: Plain text msgid "" "In the last chapter, we saw how to link to a program with functions in the C " "math library @file{libm.a}, using the short-cut option @option{-lm} and the " "header file @file{math.h}." msgstr "" #. type: Plain text msgid "" "A common problem when compiling a program using library header files is the " "error:" msgstr "" #. type: cindex #: #, no-wrap msgid "No such file or directory, header file not found" msgstr "" #. type: cindex #, no-wrap msgid "header file, not found" msgstr "" #. type: example #, no-wrap msgid "@var{FILE.h}: No such file or directory\n" msgstr "" #. type: Plain text msgid "" "This occurs if a header file is not present in the standard include file " "directories used by @code{gcc}. A similar problem can occur for libraries:" msgstr "" #. type: cindex #: #, no-wrap msgid "cannot find @var{library} error" msgstr "" #. type: cindex #: #, no-wrap msgid "link error, cannot find library" msgstr "" #. type: example #, no-wrap msgid "/usr/bin/ld: cannot find @var{library}\n" msgstr "" #. type: Plain text msgid "" "This happens if a library used for linking is not present in the standard " "library directories used by @code{gcc}." msgstr "" #. type: Plain text msgid "By default, @code{gcc} searches the following directories for header files:" msgstr "" #. type: cindex #, no-wrap msgid "ld: cannot find library error" msgstr "" #. type: cindex #, no-wrap msgid "default directories, linking and header files" msgstr "" #. type: cindex #, no-wrap msgid "linking, default directories" msgstr "" #. type: cindex #, no-wrap msgid "header file, default directories" msgstr "" #. type: example #, no-wrap msgid "" "/usr/local/include/\n" "/usr/include/\n" msgstr "" #. type: Plain text msgid "and the following directories for libraries:" msgstr "" #. type: example #, no-wrap msgid "" "/usr/local/lib/\n" "/usr/lib/\n" msgstr "" #. type: Plain text msgid "" "The list of directories for header files is often referred to as the " "@dfn{include path}, and the list of directories for libraries as the " "@dfn{library search path} or @dfn{link path}." msgstr "" #. type: cindex #, no-wrap msgid "libraries, on 64-bit platforms" msgstr "" #. type: cindex #, no-wrap msgid "64-bit platforms, additional library directories" msgstr "" #. type: Plain text msgid "" "The directories on these paths are searched in order, from first to last in " "the two lists above.@footnote{The default search paths may also include " "additional system-dependent or site-specific directories, and directories in " "the GCC installation itself. For example, on 64-bit platforms additional " "@file{lib64} directories may also be searched by default.} For example, a " "header file found in @file{/usr/local/include} takes precedence over a file " "with the same name in @file{/usr/include}. Similarly, a library found in " "@file{/usr/local/lib} takes precedence over a library with the same name in " "@file{/usr/lib}." msgstr "" #. type: cindex #, no-wrap msgid "@option{-L} option, library search path" msgstr "" #. type: cindex #, no-wrap msgid "@option{L} option, library search path" msgstr "" #. type: cindex #, no-wrap msgid "@option{-I} option, include path" msgstr "" #. type: cindex #, no-wrap msgid "@option{I} option, include path" msgstr "" #. type: cindex #, no-wrap msgid "libraries, extending search path with @option{-L}" msgstr "" #. type: cindex #, no-wrap msgid "include path, extending with @option{-I}" msgstr "" #. type: cindex #, no-wrap msgid "header file, include path---extending with @option{-I}" msgstr "" #. type: Plain text msgid "" "When additional libraries are installed in other directories it is necessary " "to extend the search paths, in order for the libraries to be found. The " "compiler options @option{-I} and @option{-L} add new directories to the " "beginning of the include path and library search path respectively." msgstr "" #. type: subsection #: #, no-wrap msgid "Search path example" msgstr "" #. type: subsection #: #, no-wrap msgid "Environment variables" msgstr "" #. type: subsection #: #, no-wrap msgid "Extended search paths" msgstr "" #. type: cindex #, no-wrap msgid "search paths, example" msgstr "" #. type: cindex #, no-wrap msgid "@code{gdbm}, GNU DBM library" msgstr "" #. type: cindex #, no-wrap msgid "key-value pairs, stored with GDBM" msgstr "" #. type: cindex #, no-wrap msgid "DBM file, created with @code{gdbm}" msgstr "" #. type: Plain text msgid "" "The following example program uses a library that might be installed as an " "additional package on a system---the GNU Database Management Library " "(GDBM). The GDBM Library stores key-value pairs in a DBM file, a type of " "data file which allows values to be stored and indexed by a @dfn{key} (an " "arbitrary sequence of characters). Here is the example program " "@file{dbmain.c}, which creates a DBM file containing a key @samp{testkey} " "with the value @samp{testvalue}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude dbmain.c\n" msgstr "" #. type: Plain text msgid "" "The program uses the header file @file{gdbm.h} and the library " "@file{libgdbm.a}. If the library has been installed in the default location " "of @file{/usr/local/lib}, with the header file in @file{/usr/local/include}, " "then the program can be compiled with the following simple command:" msgstr "" #. type: example #: #, no-wrap msgid "$ gcc -Wall dbmain.c -lgdbm\n" msgstr "" #. type: Plain text msgid "" "Both these directories are part of the default @code{gcc} include and link " "paths." msgstr "" #. type: Plain text msgid "" "However, if GDBM has been installed in a different location, trying to " "compile the program will give the following error:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall dbmain.c -lgdbm \n" "dbmain.c:1: gdbm.h: No such file or directory\n" msgstr "" #. type: Plain text msgid "" "For example, if version 1.8.3 of the GDBM package is installed under the " "directory @file{/opt/gdbm-1.8.3} the location of the header file would be," msgstr "" #. type: example #, no-wrap msgid "/opt/gdbm-1.8.3/include/gdbm.h\n" msgstr "" #. type: Plain text msgid "" "which is not part of the default @code{gcc} include path. Adding the " "appropriate directory to the include path with the command-line option " "@option{-I} allows the program to be compiled, but not linked:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -I/opt/gdbm-1.8.3/include dbmain.c -lgdbm \n" "/usr/bin/ld: cannot find -lgdbm\n" "collect2: ld returned 1 exit status\n" msgstr "" #. type: Plain text msgid "" "The directory containing the library is still missing from the link path. " "It can be added to the link path using the following option:" msgstr "" #. type: example #, no-wrap msgid "-L/opt/gdbm-1.8.3/lib/\n" msgstr "" #. type: Plain text msgid "The following command line allows the program to be compiled and linked:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -I/opt/gdbm-1.8.3/include \n" " -L/opt/gdbm-1.8.3/lib dbmain.c -lgdbm\n" msgstr "" #. type: Plain text msgid "" "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 " "environment variables that affect the @option{-I} and @option{-L} options." msgstr "" #. type: Plain text msgid "" "Note that you should never place the absolute paths of header files in " "@code{#include} statements in your source code, as this will prevent the " "program from compiling on other systems. The @option{-I} option or the " "@env{INCLUDE_PATH} variable described below should always be used to set the " "include path for header files." msgstr "" #. type: cindex #, no-wrap msgid "environment variables, for default search paths" msgstr "" #. type: Plain text msgid "" "The search paths for header files and libraries can also be controlled " "through environment variables in the shell. These may be set automatically " "for each session using the appropriate login file, such as " "@file{.bash_profile} in the case of GNU Bash." msgstr "" #. type: cindex #: #, no-wrap msgid "@code{bash} profile file, login settings" msgstr "" #. type: cindex #, no-wrap msgid "include path, setting with environment variables" msgstr "" #. type: cindex #, no-wrap msgid "C include path" msgstr "" #. type: cindex #, no-wrap msgid "C++ include path" msgstr "" #. type: cindex #, no-wrap msgid "@env{C_INCLUDE_PATH}" msgstr "" #. type: cindex #, no-wrap msgid "@env{CPLUS_INCLUDE_PATH}" msgstr "" #. type: Plain text msgid "" "Additional directories can be added to the include path using the " "environment variable @env{C_INCLUDE_PATH} (for C header files) or " "@env{CPLUS_INCLUDE_PATH} (for C++ header files). For example, the following " "commands will add @file{/opt/gdbm-1.8.3/include} to the include path when " "compiling C programs:" msgstr "" #. type: example #, no-wrap msgid "" "$ C_INCLUDE_PATH=/opt/gdbm-1.8.3/include \n" "$ export C_INCLUDE_PATH\n" msgstr "" #. type: Plain text msgid "and similarly for C++ programs:" msgstr "" #. type: example #, no-wrap msgid "" "$ CPLUS_INCLUDE_PATH=/opt/gdbm-1.8.3/include \n" "$ export CPLUS_INCLUDE_PATH\n" msgstr "" #. type: Plain text msgid "" "This directory will be searched after any directories specified on the " "command line with the option @option{-I}, and before the standard default " "directories (such as @file{/usr/local/include} and @file{/usr/include}). " "The shell command @code{export} is needed to make the environment variable " "available to programs outside the shell itself, such as the compiler---it is " "only needed once for each variable in each shell session, and can also be " "set in the appropriate login file.@footnote{In GNU Bash, the shorter form " "@code{export @var{VARIABLE}=@var{VALUE}} is also allowed.}" msgstr "" #. type: Plain text msgid "" "Similarly, additional directories can be added to the link path using the " "environment variable @env{LIBRARY_PATH}. For example, the following " "commands will add @file{/opt/gdbm-1.8.3/lib} to the link path:" msgstr "" #. type: cindex #, no-wrap msgid "link path, setting with environment variable" msgstr "" #. type: example #, no-wrap msgid "" "$ LIBRARY_PATH=/opt/gdbm-1.8.3/lib\n" "$ export LIBRARY_PATH\n" msgstr "" #. type: Plain text msgid "" "This directory will be searched after any directories specified on the " "command line with the option @option{-L}, and before the standard default " "directories (such as @file{/usr/local/lib} and @file{/usr/lib})." msgstr "" #. type: Plain text msgid "" "With the environment variable settings given above the program " "@file{dbmain.c} can be compiled without the @option{-I} and @option{-L} " "options," msgstr "" #. type: Plain text msgid "" "because the default paths now use the directories specified in the " "environment variables @env{C_INCLUDE_PATH} and @env{LIBRARY_PATH}. The same " "compilation command with @code{g++} would use the environment variables " "@env{CPLUS_INCLUDE_PATH} and @env{LIBRARY_PATH}." msgstr "" #. type: cindex #, no-wrap msgid "multiple directories, on include and link paths" msgstr "" #. type: cindex #, no-wrap msgid "extended search paths, for include and link directories" msgstr "" #. type: cindex #, no-wrap msgid "search paths, extended" msgstr "" #. type: Plain text msgid "" "Following the standard Unix convention for search paths, several directories " "can be specified together in an environment variable as a colon separated " "list:" msgstr "" #. type: example #, no-wrap msgid "@var{DIR1}:@var{DIR2}:@var{DIR3}:...\n" msgstr "" #. type: Plain text msgid "" "The directories are then searched in order from left to right. A single dot " "@samp{.} can be used to specify the current directory.@footnote{The current " "directory can also be specified using an empty path element. For example, " "@code{:@var{DIR1}:@var{DIR2}} is equivalent to " "@code{.:@var{DIR1}:@var{DIR2}}.}" msgstr "" #. type: Plain text msgid "" "For example, the following settings create default include and link paths " "for packages installed in the current directory @file{.} and the " "@file{include} and @file{lib} directories under @file{/opt/gdbm-1.8.3} and " "@file{/net} respectively:" msgstr "" #. type: example #, no-wrap msgid "" "$ C_INCLUDE_PATH=.:/opt/gdbm-1.8.3/include:/net/include\n" "$ LIBRARY_PATH=.:/opt/gdbm-1.8.3/lib:/net/lib\n" msgstr "" #. type: Plain text msgid "" "For C++ programs, use the environment variable @env{CPLUS_INCLUDE_PATH} " "instead of @env{C_INCLUDE_PATH}." msgstr "" #. type: Plain text msgid "" "To specify multiple search path directories on the command line, the options " "@option{-I} and @option{-L} can be repeated. For example, the following " "command," msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -I. -I/opt/gdbm-1.8.3/include -I/net/include\n" " -L. -L/opt/gdbm-1.8.3/lib -L/net/lib .....\n" msgstr "" #. type: Plain text msgid "is equivalent to the environment variable settings given above." msgstr "" #. type: Plain text msgid "" "When environment variables and command-line options are used together the " "compiler searches the directories in the following order:" msgstr "" #. type: item #, no-wrap msgid "command-line options @option{-I} and @option{-L}, from left to right" msgstr "" #. type: item #, no-wrap msgid "" "directories specified by environment variables, such as @env{C_INCLUDE_PATH} " "(for C programs), @env{CPLUS_INCLUDE_PATH} (for C++ programs) and " "@env{LIBRARY_PATH}" msgstr "" #. type: item #, no-wrap msgid "default system directories" msgstr "" #. type: Plain text msgid "" "In day-to-day usage, directories are usually added to the search paths with " "the options @option{-I} and @option{-L}." msgstr "" #. type: cindex #, no-wrap msgid "shared libraries" msgstr "" #. type: cindex #, no-wrap msgid "static libraries" msgstr "" #. type: Plain text msgid "" "Although the example program above has been successfully compiled and " "linked, a final step is needed before being able to load and run the " "executable file." msgstr "" #. type: Plain text msgid "" "If an attempt is made to start the executable directly, the following error " "will occur on most systems:" msgstr "" #. type: cindex #: #, no-wrap msgid "error while loading shared libraries" msgstr "" #. type: cindex #: #, no-wrap msgid "cannot open shared object file" msgstr "" #. type: cindex #, no-wrap msgid "shared libraries, error while loading" msgstr "" #. type: cindex #, no-wrap msgid "libraries, error while loading shared library" msgstr "" #. type: example #, no-wrap msgid "" "$ ./a.out\n" "./a.out: error while loading shared libraries:\n" "libgdbm.so.3: cannot open shared object file:\n" "No such file or directory\n" msgstr "" #. type: Plain text msgid "" "This is because the GDBM package provides a @dfn{shared library}. This type " "of library requires special treatment---it must be loaded from disk before " "the executable will run." msgstr "" #. type: Plain text msgid "" "External libraries are usually provided in two forms: @dfn{static libraries} " "and @dfn{shared libraries}. Static libraries are the @file{.a} files seen " "earlier. When a program is linked against a static library, the machine " "code from the object files for any external functions used by the program is " "copied from the library into the final executable." msgstr "" #. type: cindex #, no-wrap msgid "@code{.so}, shared object file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{so}, shared object file extension" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.so} shared object file" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.so} shared object file" msgstr "" #. type: cindex #, no-wrap msgid "shared object file, @code{.so} extension" msgstr "" #. type: cindex #, no-wrap msgid "dynamically linked library, see shared libraries" msgstr "" #. type: cindex #, no-wrap msgid "DLL (dynamically linked library), see shared libraries" msgstr "" #. type: Plain text msgid "" "Shared libraries are handled with a more advanced form of linking, which " "makes the executable file smaller. They use the extension @file{.so}, which " "stands for @dfn{shared object}." msgstr "" #. type: cindex #, no-wrap msgid "loader function" msgstr "" #. type: cindex #, no-wrap msgid "dynamic loader" msgstr "" #. type: cindex #, no-wrap msgid "linking, dynamic (shared libraries)" msgstr "" #. type: Plain text msgid "" "An executable file linked against a shared library contains only a small " "table of the functions it requires, instead of the complete machine code " "from the object files for the external functions. Before the executable " "file starts running, the machine code for the external functions is copied " "into memory from the shared library file on disk by the operating system---a " "process referred to as @dfn{dynamic linking}." msgstr "" #. type: cindex #, no-wrap msgid "shared libraries, advantages of" msgstr "" #. type: cindex #, no-wrap msgid "disk space, reduced usage by shared libraries" msgstr "" #. type: Plain text msgid "" "Dynamic linking makes executable files smaller and saves disk space, because " "one copy of a library can be shared between multiple programs. Most " "operating systems also provide a virtual memory mechanism which allows one " "copy of a shared library in physical memory to be used by all running " "programs, saving memory as well as disk space." msgstr "" #. type: Plain text msgid "" "Furthermore, shared libraries make it possible to update a library without " "recompiling the programs which use it (provided the interface to the library " "does not change)." msgstr "" #. type: Plain text msgid "" "Because of these advantages @code{gcc} compiles programs to use shared " "libraries by default on most systems, if they are available. Whenever a " "static library @file{lib@var{NAME}.a} would be used for linking with the " "option @option{-l@var{NAME}} the compiler first checks for an alternative " "shared library with the same name and a @file{.so} extension." msgstr "" #. type: Plain text msgid "" "In this case, when the compiler searches for the @file{libgdbm} library in " "the link path, it finds the following two files in the directory " "@file{/opt/gdbm-1.8.3/lib}:" msgstr "" #. type: example #, no-wrap msgid "" "$ cd /opt/gdbm-1.8.3/lib\n" "$ ls libgdbm.*\n" "libgdbm.a libgdbm.so\n" msgstr "" #. type: Plain text msgid "" "Consequently, the @file{libgdbm.so} shared object file is used in preference " "to the @file{libgdbm.a} static library." msgstr "" #. type: cindex #, no-wrap msgid "@option{-rpath} option, set run-time shared library search path" msgstr "" #. type: cindex #, no-wrap msgid "@option{rpath} option, set run-time shared library search path" msgstr "" #. type: Plain text msgid "" "However, when the executable file is started its loader function must find " "the shared library in order to load it into memory. By default the loader " "searches for shared libraries only in a predefined set of system " "directories, such as @file{/usr/local/lib} and @file{/usr/lib}. If the " "library is not located in one of these directories it must be added to the " "load path.@footnote{Note that the directory containing the shared library " "can, in principle, be stored (``hard-coded'') in the executable itself using " "the linker option @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.}" msgstr "" #. type: cindex #, no-wrap msgid "@env{LD_LIBRARY_PATH}, shared library load path" msgstr "" #. type: cindex #, no-wrap msgid "shared libraries, setting load path" msgstr "" #. type: Plain text msgid "" "The simplest way to set the load path is through the environment variable " "@env{LD_LIBRARY_PATH}. For example, the following commands set the load " "path to @file{/opt/gdbm-1.8.3/lib} so that @file{libgdbm.so} can be found:" msgstr "" #. type: example #, no-wrap msgid "" "$ LD_LIBRARY_PATH=/opt/gdbm-1.8.3/lib\n" "$ export LD_LIBRARY_PATH\n" "$ ./a.out\n" "Storing key-value pair... done.\n" msgstr "" #. type: Plain text msgid "" "The executable now runs successfully, prints its message and creates a DBM " "file called @file{test} containing the key-value pair @samp{testkey} and " "@samp{testvalue}." msgstr "" #. type: cindex #, no-wrap msgid "environment variables, setting permanently" msgstr "" #. type: cindex #, no-wrap msgid "shell variables, setting permanently" msgstr "" #. type: cindex #, no-wrap msgid "login file, setting environment variables in" msgstr "" #. type: cindex #, no-wrap msgid "profile file, setting environment variables in" msgstr "" #. type: Plain text msgid "" "To save typing, the @env{LD_LIBRARY_PATH} environment variable can be set " "automatically for each session using the appropriate login file, such as " "@file{.bash_profile} for the GNU Bash shell." msgstr "" #. type: Plain text msgid "" "Several shared library directories can be placed in the load path, as a " "colon separated list " "@code{@var{DIR1}:@var{DIR2}:@var{DIR3}:...:@var{DIRN}}. For example, the " "following command sets the load path to use the @file{lib} directories under " "@file{/opt/gdbm-1.8.3} and @file{/opt/gtk-1.4}:" msgstr "" #. type: cindex #, no-wrap msgid "environment variables, extending an existing path" msgstr "" #. type: cindex #, no-wrap msgid "paths, extending environment variable" msgstr "" #. type: example #, no-wrap msgid "" "$ LD_LIBRARY_PATH=/opt/gdbm-1.8.3/lib:/opt/gtk-1.4/lib\n" "$ export LD_LIBRARY_PATH\n" msgstr "" #. type: Plain text msgid "" "If the load path contains existing entries, it can be extended using the " "syntax @code{LD_LIBRARY_PATH=@var{NEWDIRS}:$LD_LIBRARY_PATH}. For example, " "the following command adds the directory @file{/opt/gsl-1.5/lib} to the load " "path shown above:" msgstr "" #. type: example #, no-wrap msgid "" "$ LD_LIBRARY_PATH=/opt/gsl-1.5/lib:$LD_LIBRARY_PATH\n" "$ echo $LD_LIBRARY_PATH\n" "/opt/gsl-1.5/lib:/opt/gdbm-1.8.3/lib:/opt/gtk-1.4/lib\n" msgstr "" #. type: Plain text msgid "" "It is possible for the system administrator to set the @env{LD_LIBRARY_PATH} " "variable for all users, by adding it to a default login script, such as " "@file{/etc/profile}. On GNU systems, a system-wide path can also be defined " "in the loader configuration file @file{/etc/ld.so.conf}." msgstr "" #. type: cindex #, no-wrap msgid "loader configuration file, @code{ld.so.conf}" msgstr "" #. type: cindex #, no-wrap msgid "@code{ld.so.conf}, loader configuration file" msgstr "" #. type: cindex #, no-wrap msgid "@option{-static} option, force static linking" msgstr "" #. type: cindex #, no-wrap msgid "@option{static} option, force static linking" msgstr "" #. type: cindex #, no-wrap msgid "static linking, forcing with @option{-static}" msgstr "" #. type: Plain text msgid "" "Alternatively, static linking can be forced with the @option{-static} option " "to @code{gcc} to avoid the use of shared libraries:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -static -I/opt/gdbm-1.8.3/include/ \n" " -L/opt/gdbm-1.8.3/lib/ dbmain.c -lgdbm\n" msgstr "" #. type: Plain text msgid "" "This creates an executable linked with the static library @file{libgdbm.a} " "which can be run without setting the environment variable " "@env{LD_LIBRARY_PATH} or putting shared libraries in the default " "directories:" msgstr "" #. type: example #, no-wrap msgid "" "$ ./a.out\n" "Storing key-value pair... done.\n" msgstr "" #. type: Plain text msgid "" "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 @file{libgdbm.a}," msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -I/opt/gdbm-1.8.3/include \n" " dbmain.c /opt/gdbm-1.8.3/lib/libgdbm.a\n" msgstr "" #. type: Plain text msgid "" "and the command below will link with the shared library file " "@file{libgdbm.so}:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -I/opt/gdbm-1.8.3/include \n" " dbmain.c /opt/gdbm-1.8.3/lib/libgdbm.so\n" msgstr "" #. type: Plain text msgid "" "In the latter case it is still necessary to set the library load path when " "running the executable." msgstr "" #. type: cindex #, no-wrap msgid "C language, dialects of" msgstr "" #. type: cindex #, no-wrap msgid "dialects of C language" msgstr "" #. type: cindex #, no-wrap msgid "ANSI/ISO C, compared with GNU C extensions" msgstr "" #. type: cindex #, no-wrap msgid "ISO C, compared with GNU C extensions" msgstr "" #. type: cindex #, no-wrap msgid "GNU C extensions, compared with ANSI/ISO C" msgstr "" #. type: cindex #, no-wrap msgid "@option{-ansi} option, disable language extensions" msgstr "" #. type: cindex #, no-wrap msgid "@option{ansi} option, disable language extensions" msgstr "" #. type: cindex #, no-wrap msgid "" "@option{-pedantic} option, conform to the ANSI standard (with " "@option{-ansi})" msgstr "" #. type: cindex #: #, no-wrap msgid "@option{pedantic} option" msgstr "" #. type: cindex #: #, no-wrap msgid "@option{-std} option, select specific language standard" msgstr "" #. type: cindex #: #, no-wrap msgid "@option{std} option, select specific language standard" msgstr "" #. type: Plain text msgid "" "By default, @code{gcc} compiles programs using the GNU dialect of the C " "language, referred to as @dfn{GNU C}. This dialect incorporates the " "official ANSI/ISO standard for the C language with several useful GNU " "extensions, such as nested functions and variable-size arrays. Most " "ANSI/ISO programs will compile under GNU C without changes." msgstr "" #. type: Plain text msgid "" "There are several options which control the dialect of C used by " "@code{gcc}. The most commonly-used options are @option{-ansi} and " "@option{-pedantic}. The specific dialects of the C language for each " "standard can also be selected with the @option{-std} option." msgstr "" #. type: subsection #: #, no-wrap msgid "ANSI/ISO" msgstr "" #. type: subsection #: #, no-wrap msgid "Strict ANSI/ISO" msgstr "" #. type: subsection #: #, no-wrap msgid "Selecting specific standards" msgstr "" #. type: cindex #, no-wrap msgid "ANSI/ISO C, controlled with @option{-ansi} option" msgstr "" #. type: cindex #, no-wrap msgid "ISO C, controlled with @option{-ansi} option" msgstr "" #. type: Plain text msgid "" "Occasionally a valid ANSI/ISO program may be incompatible with the " "extensions in GNU C. To deal with this situation, the compiler option " "@option{-ansi} disables those GNU extensions which are in conflict with the " "ANSI/ISO standard. On systems using the GNU C Library (@code{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." msgstr "" #. type: Plain text msgid "" "For example, here is a valid ANSI/ISO C program which uses a variable called " "@code{asm}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude ansi.c\n" msgstr "" #. type: Plain text msgid "" "The variable name @code{asm} is valid under the ANSI/ISO standard, but this " "program will not compile in GNU C because @code{asm} is a GNU C keyword " "extension (it allows native assembly instructions to be used in C " "functions). Consequently, it cannot be used as a variable name without " "giving a compilation error:" msgstr "" #. type: cindex #, no-wrap msgid "keywords, additional in GNU C" msgstr "" #. type: cindex #, no-wrap msgid "parse error due to language extensions" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall ansi.c\n" "ansi.c: In function 'main':\n" "ansi.c:6:14: error: expected identifier or '(' before 'asm'\n" "ansi.c:7:39: error: expected expression before 'asm'\n" msgstr "" #. type: Plain text msgid "" "In contrast, using the @option{-ansi} option disables the @code{asm} keyword " "extension, and allows the program above to be compiled correctly:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -ansi ansi.c\n" "$ ./a.out \n" "the string asm is '6502'\n" msgstr "" #. type: Plain text msgid "" "For reference, the non-standard keywords and macros defined by the GNU C " "extensions are @code{asm}, @code{inline}, @code{typeof}, @code{unix} and " "@code{vax}. More details can be found in the GCC Reference Manual " "``@cite{Using GCC}'' (@pxref{Further reading})." msgstr "" #. type: cindex #: #, no-wrap msgid "@code{asm} extension keyword" msgstr "" #. type: cindex #, no-wrap msgid "@code{typeof}, GNU C extension keyword" msgstr "" #. type: cindex #, no-wrap msgid "@code{unix}, GNU C extension keyword" msgstr "" #. type: cindex #, no-wrap msgid "@code{vax}, GNU C extension keyword" msgstr "" #. type: Plain text msgid "" "The next example shows the effect of the @option{-ansi} option on systems " "using the GNU C Library, such as GNU/Linux systems. The program below " "prints the value of pi, @math{\\pi=3.14159...}, from the preprocessor " "definition @code{M_PI} in the header file @file{math.h}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude pi.c\n" msgstr "" #. type: Plain text msgid "" "The constant @code{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 @option{-ansi} option:" msgstr "" #. type: cindex #, no-wrap msgid "undeclared identifier error for C library, when using @option{-ansi} option" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -ansi pi.c\n" "pi.c: In function 'main':\n" "pi.c:7:38: error: 'M_PI' undeclared (first use in this\n" " function)\n" "pi.c:7:38: note: each undeclared identifier is reported \n" "only once for each function it appears in\n" msgstr "" #. type: Plain text msgid "" "The program can be compiled without the @option{-ansi} option. In this case " "both the language and library extensions are enabled by default:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall pi.c\n" "$ ./a.out \n" "the value of pi is 3.141593\n" msgstr "" #. type: Plain text msgid "" "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 @code{_GNU_SOURCE}, which enable extensions " "in the GNU C Library:@footnote{The @option{-D} option for defining macros " "will be explained in detail in the next chapter.}" msgstr "" #. type: cindex #, no-wrap msgid "@code{_GNU_SOURCE} macro, enables extensions to GNU C Library" msgstr "" #. type: cindex #, no-wrap msgid "" "@code{GNU_SOURCE} macro (@code{_GNU_SOURCE}), enables extensions to GNU C " "Library" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -ansi -D_GNU_SOURCE pi.c\n" "$ ./a.out \n" "the value of pi is 3.141593\n" msgstr "" #. type: cindex #, no-wrap msgid "feature test macros, GNU C Library" msgstr "" #. type: cindex #, no-wrap msgid "GNU C Library, feature test macros" msgstr "" #. type: cindex #, no-wrap msgid "POSIX extensions, GNU C Library" msgstr "" #. type: cindex #, no-wrap msgid "BSD extensions, GNU C Library" msgstr "" #. type: cindex #, no-wrap msgid "XOPEN extensions, GNU C Library" msgstr "" #. type: cindex #, no-wrap msgid "SVID extensions, GNU C Library" msgstr "" #. type: Plain text msgid "" "The GNU C Library provides a number of these macros (referred to as " "@dfn{feature test macros}) which allow control over the support for POSIX " "extensions (@w{@code{_POSIX_C_SOURCE}}), BSD extensions " "(@w{@code{_BSD_SOURCE}}), SVID extensions (@w{@code{_SVID_SOURCE}}), XOPEN " "extensions (@w{@code{_XOPEN_SOURCE}}) and GNU extensions " "(@w{@code{_GNU_SOURCE}})." msgstr "" #. type: Plain text msgid "" "The @w{@code{_GNU_SOURCE}} macro enables all the extensions together, with " "the POSIX extensions taking precedence over the others in cases where they " "conflict. Further information about feature test macros can be found in the " "@cite{GNU C Library Reference Manual} (@pxref{Further reading})." msgstr "" #. type: cindex #, no-wrap msgid "ANSI/ISO C, pedantic diagnostics option" msgstr "" #. type: cindex #, no-wrap msgid "strict ANSI/ISO C, @option{-pedantic} option" msgstr "" #. type: Plain text msgid "" "The command-line option @option{-pedantic} in combination with " "@option{-ansi} will cause @code{gcc} to reject all GNU C extensions, not " "just those that are incompatible with the ANSI/ISO standard. This helps you " "to write portable programs which follow the ANSI/ISO standard." msgstr "" #. type: Plain text msgid "" "Here is a program which uses variable-size arrays, a GNU C extension. The " "array @code{x[n]} is declared with a length specified by the integer " "variable @code{n}." msgstr "" #. type: cindex #, no-wrap msgid "variable-size arrays" msgstr "" #. type: cindex #, no-wrap msgid "arrays, variable-size" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude gnuarray.c\n" msgstr "" #. type: Plain text msgid "" "This program will compile with @option{-ansi}, because support for variable " "length arrays does not interfere with the compilation of valid ANSI/ISO " "programs---it is a backwards-compatible extension:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -ansi gnuarray.c\n" msgstr "" #. type: Plain text msgid "" "However, compiling with @option{-ansi -pedantic} reports warnings about " "violations of the ANSI/ISO standard:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -ansi -pedantic gnuarray.c\n" "gnuarray.c: In function `main':\n" "gnuarray.c:5: warning: ISO C90 forbids variable-size \n" " array `x'\n" msgstr "" #. type: Plain text msgid "" "Note that an absence of warnings from @option{-ansi -pedantic} does not " "guarantee 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 @option{-ansi -pedantic} reports." msgstr "" #. type: cindex #, no-wrap msgid "@code{c89}/@code{c99}, selected with @option{-std}" msgstr "" #. type: cindex #, no-wrap msgid "@code{gnu89}/@code{gnu99}, selected with @option{-std}" msgstr "" #. type: cindex #, no-wrap msgid "@code{iso9899:1990}/@code{iso9899:1999}, selected with @option{-std}" msgstr "" #. type: cindex #, no-wrap msgid "selecting specific language standards, with @option{-std}" msgstr "" #. type: cindex #, no-wrap msgid "language standards, selecting with @option{-std}" msgstr "" #. type: Plain text msgid "" "The specific language standard used by GCC can be controlled with the " "@option{-std} option. The following C language standards are supported:" msgstr "" #. type: item #, no-wrap msgid "@option{-std=c89} or @option{-std=iso9899:1990}" msgstr "" #. type: table msgid "" "The original ANSI/ISO C language standard (ANSI X3.159-1989, ISO/IEC " "9899:1990). GCC incorporates the corrections in the two ISO Technical " "Corrigenda to the original standard." msgstr "" #. type: option{#1} #, no-wrap msgid "-std=iso9899:199409" msgstr "" #. type: table msgid "" "The ISO C language standard with ISO Amendment 1, published in 1994. This " "amendment was mainly concerned with internationalization, such as adding " "support for multibyte characters to the C library." msgstr "" #. type: item #, no-wrap msgid "@option{-std=c99} or @option{-std=iso9899:1999}" msgstr "" #. type: table msgid "The revised ISO C language standard, published in 1999 (ISO/IEC 9899:1999)." msgstr "" #. type: Plain text msgid "" "The C language standards with GNU extensions can be selected with the " "options @option{-std=gnu89} and @option{-std=gnu99}." msgstr "" #. type: section #, no-wrap msgid "Warning options in @code{-Wall}" msgstr "" #. type: cindex #, no-wrap msgid "warning options, in detail" msgstr "" #. type: Plain text msgid "" "As described earlier (@pxref{Compiling a simple C program}), the warning " "option @option{-Wall} enables warnings for many common errors, and should " "always be used. It combines a large number of other, more specific, warning " "options which can also be selected individually. Here is a summary of these " "options:" msgstr "" #. type: item #, no-wrap msgid "@option{-Wcomment} @r{(included in @option{-Wall})}" msgstr "" #. type: cindex #, no-wrap msgid "comments, nested" msgstr "" #. type: cindex #, no-wrap msgid "nested comments, warning of" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wcomment} option, warn about nested comments" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wcomment} option, warn about nested comments" msgstr "" #. type: cindex #, no-wrap msgid "@option{comment} warning option, warn about nested comments" msgstr "" #. type: table msgid "" "This option warns about nested comments. Nested comments typically arise " "when a section of code containing comments is later @dfn{commented out}:" msgstr "" #. type: example #, no-wrap msgid "" "/* commented out \n" "double x = 1.23 ; /* x-position */\n" "*/\n" msgstr "" #. type: table msgid "" "Nested comments can be a source of confusion---the safe way to ``comment " "out'' a section of code containing comments is to surround it with the " "preprocessor directive @code{#if 0 ... #endif}:" msgstr "" #. type: cindex #, no-wrap msgid "@code{#if}, preprocessor directive" msgstr "" #. type: example #, no-wrap msgid "" "/* commented out */\n" "#if 0 \n" "double x = 1.23 ; /* x-position */\n" "#endif\n" msgstr "" #. type: item #, no-wrap msgid "@option{-Wformat} @r{(included in @option{-Wall})}" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wformat} option, warn about incorrect format strings" msgstr "" #. type: cindex #, no-wrap msgid "format strings, incorrect usage warning" msgstr "" #. type: cindex #, no-wrap msgid "@code{printf}, incorrect usage warning" msgstr "" #. type: cindex #: #, no-wrap msgid "@code{scanf}, incorrect usage warning" msgstr "" #. type: table msgid "" "This option warns about the incorrect use of format strings in functions " "such as @code{printf} and @code{scanf}, where the format specifier does not " "agree with the type of the corresponding function argument." msgstr "" #. type: item #, no-wrap msgid "@option{-Wunused} @r{(included in @option{-Wall})}" msgstr "" #. type: cindex #: #, no-wrap msgid "unused variable warning" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wunused} option, unused variable warning" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wunused} option, unused variable warning" msgstr "" #. type: table msgid "" "This option warns about unused variables. When a variable is declared but " "not used this can be the result of another variable being accidentally " "substituted in its place. If the variable is genuinely not needed it can be " "removed from the source code." msgstr "" #. type: item #, no-wrap msgid "@option{-Wimplicit} @r{(included in @option{-Wall})}" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wimplicit} option, warn about missing declarations" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wimplicit} option, warn about missing declarations" msgstr "" #. type: cindex #, no-wrap msgid "missing prototypes warning" msgstr "" #. type: cindex #, no-wrap msgid "prototypes, missing" msgstr "" #. type: table msgid "" "This option warns about any functions that are used without being declared. " "The most common reason for a function to be used without being declared is " "forgetting to include a header file." msgstr "" #. type: item #, no-wrap msgid "@option{-Wreturn-type} @r{(included in @option{-Wall})}" msgstr "" #. type: cindex #, no-wrap msgid "return type, invalid" msgstr "" #. type: cindex #, no-wrap msgid "empty @code{return}, incorrect use of" msgstr "" #. type: cindex #, no-wrap msgid "void @code{return}, incorrect use of" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wreturn-type} option, warn about incorrect return types" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wreturn-type} option, warn about incorrect return types" msgstr "" #. type: table msgid "" "This option warns about functions that are defined without a return type but " "not declared @code{void}. It also catches empty @code{return} statements in " "functions that are not declared @code{void}." msgstr "" #. type: table msgid "For example, the following program does not use an explicit return value:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude main4.c\n" msgstr "" #. type: table msgid "" "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 @code{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 @code{return 0}." msgstr "" #. type: Plain text msgid "" "The complete set of warning options included in @option{-Wall} can be found " "in the GCC Reference Manual ``@cite{Using GCC}'' (@pxref{Further reading}). " "The options included in @option{-Wall} have the common characteristic 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 @option{-Wall} can be taken as an indication of a " "potentially serious problem." msgstr "" #. type: cindex #, no-wrap msgid "additional warning options" msgstr "" #. type: cindex #, no-wrap msgid "warning options, additional" msgstr "" #. type: Plain text msgid "" "GCC provides many other warning options that are not included in " "@option{-Wall} but are often useful. Typically these produce warnings for " "source code which may be technically valid but is very likely to cause " "problems. The criteria for these options are based on experience of common " "errors---they are not included in @option{-Wall} because they only indicate " "possibly problematic or ``suspicious'' code." msgstr "" #. type: Plain text msgid "" "Since these warnings can be issued for valid code it is not necessary to " "compile with them all the time. It is more appropriate to use them " "periodically and review the results, checking for anything unexpected, or to " "enable them for some programs or files." msgstr "" #. type: option{#1} #, no-wrap msgid "-W" msgstr "" #. type: cindex #, no-wrap msgid "common errors, not included with @option{-Wall}" msgstr "" #. type: cindex #, no-wrap msgid "@option{-W} option, enable additional warnings" msgstr "" #. type: cindex #, no-wrap msgid "@option{W} option, enable additional warnings" msgstr "" #. type: cindex #, no-wrap msgid "warnings, additional with @option{-W}" msgstr "" #. type: cindex #, no-wrap msgid "warning option, @option{-W} additional warnings" msgstr "" #. type: table msgid "" "This is a general option similar to @option{-Wall} which warns about a " "selection of common programming errors, such as functions which can return " "without a value (also known as ``falling off the end of the function " "body''), and comparisons between signed and unsigned values. For example, " "the following function tests whether an unsigned integer is negative (which " "is impossible, of course):" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude w.c\n" msgstr "" #. type: table #: msgid "Compiling this function with @option{-Wall} does not produce a warning," msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -c w.c\n" msgstr "" #. type: table msgid "but does give a warning with @option{-W}:" msgstr "" #. type: cindex #, no-wrap msgid "comparison of expression always true/false warning" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -W -c w.c\n" "w.c: In function 'foo':\n" "w.c:4:3: warning: comparison of unsigned \n" "expression < 0 is always false [-Wtype-limits]\n" msgstr "" #. type: table msgid "" "In practice, the options @option{-W} and @option{-Wall} are normally used " "together." msgstr "" #. type: option{#1} #, no-wrap msgid "-Wconversion" msgstr "" #. type: cindex #, no-wrap msgid "type conversions, warning of" msgstr "" #. type: cindex #, no-wrap msgid "conversions between types, warning of" msgstr "" #. type: cindex #, no-wrap msgid "unsigned variable converted to signed, warning of" msgstr "" #. type: cindex #, no-wrap msgid "signed variable converted to unsigned, warning of" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wconversion} option, warn about type conversions" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wconversion} option, warn about type conversions" msgstr "" #. type: table msgid "" "This option warns about implicit type conversions that could cause " "unexpected results, such as conversions between floating-point and integer " "types, between signed and unsigned types and between types of different " "width (e.g. long and short integers). Conversions can occur in expressions " "and assignments, and in calls to functions if the types of the arguments do " "not match those specified in the prototype." msgstr "" #. type: table msgid "" "For example, the integer absolute value function @code{int abs(int i)} is " "easily confused with the corresponding floating-point function @code{double " "fabs(double x)}. This can lead to incorrect results, as shown in the " "following program:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude wabs.c\n" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall wabs.c\n" "$ ./a.out\n" "x = -3.14 |x| = 3 @r{(incorrect)}\n" msgstr "" #. type: table msgid "but does give a warning with @option{-Wconversion}:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -Wconversion wabs.c\n" "wabs.c: In function 'main':\n" "wabs.c:8:3: warning: conversion to 'int' from \n" "'double' may alter its value [-Wconversion]\n" msgstr "" #. type: table msgid "" "The @option{-Wconversion} option also catches errors such as the assignment " "of a negative value to an unsigned variable, as in the following code," msgstr "" #. type: example #, no-wrap msgid "unsigned int x = -1;\n" msgstr "" #. type: cindex #, no-wrap msgid "casts, used to avoid conversion warnings" msgstr "" #. type: cindex #, no-wrap msgid "unsigned integer, casting" msgstr "" #. type: cindex #, no-wrap msgid "signed integer, casting" msgstr "" #. type: table msgid "" "This is technically allowed by the ANSI/ISO C standard (with the negative " "integer being converted to a positive integer, according to the machine " "representation) but could be a simple programming error. If you need to " "perform such a conversion you can use an explicit cast, such as " "@code{(unsigned int)-1}, to avoid any warnings from this option. On " "two's-complement machines the cast of @math{-1} gives the maximum number " "that can be represented by an unsigned integer." msgstr "" #. type: option{#1} #, no-wrap msgid "-Wshadow" msgstr "" #. type: cindex #, no-wrap msgid "shadowing of variables" msgstr "" #. type: cindex #, no-wrap msgid "variable shadowing" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wshadow} option, warn about shadowed variables" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wshadow} option, warn about shadowed variables" msgstr "" #. type: table msgid "" "This option warns about the redeclaration of a variable name in a scope " "where it has already been declared. This is referred to as variable " "@dfn{shadowing}, and causes confusion about which occurrence of the variable " "corresponds to which value." msgstr "" #. type: table msgid "" "The following function declares a local variable @code{y} that shadows the " "declaration in the body of the function:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude shadow.c\n" msgstr "" #. type: table msgid "" "This is valid ANSI/ISO C, where the return value is 1. The shadowing of the " "variable @code{y} might make it seem (incorrectly) that the return value is " "@code{x}, when looking at the line @code{y = x} (especially in a large and " "complicated function)." msgstr "" #. type: table msgid "" "Shadowing can also occur for function names. For example, the following " "program attempts to define a variable @code{sin} which shadows the standard " "function @code{sin(x)}." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude shadow2.c\n" msgstr "" #. type: table msgid "This error will be detected by the @option{-Wshadow} option." msgstr "" #. type: option{#1} #, no-wrap msgid "-Wcast-qual" msgstr "" #. type: cindex #, no-wrap msgid "qualifiers, warning about overriding by casts" msgstr "" #. type: cindex #, no-wrap msgid "@code{const}, warning about overriding by casts" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wcast-qual} option, warn about casts removing qualifiers" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wcast-qual} option, warn about casts removing qualifiers" msgstr "" #. type: table msgid "" "This option warns about pointers that are cast to remove a type qualifier, " "such as @code{const}. For example, the following function discards the " "@code{const} qualifier from its input argument, allowing it to be " "overwritten:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude castqual.c\n" msgstr "" #. type: table msgid "" "The modification of the original contents of @code{str} is a violation of " "its @code{const} property. This option will warn about the improper cast of " "the variable @code{str} which allows the string to be modified." msgstr "" #. type: option{#1} #, no-wrap msgid "-Wwrite-strings" msgstr "" #. type: cindex #, no-wrap msgid "writable string constants, disabling" msgstr "" #. type: cindex #, no-wrap msgid "constant strings, compile-time warnings" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wwrite-strings} option, warning for modified string constants" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wwrite-strings} option, warning for modified string constants" msgstr "" #. type: table msgid "" "This option implicitly gives all string constants defined in the program a " "@code{const} qualifier, causing a compile-time warning if there is an " "attempt to overwrite them. The result of modifying a string constant is not " "defined by the ANSI/ISO standard, and the use of writable string constants " "is deprecated in GCC." msgstr "" #. type: cindex #, no-wrap msgid "K&R dialect of C, warnings of different behavior" msgstr "" #. type: cindex #, no-wrap msgid "Traditional C (K&R), warnings of different behavior" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wtraditional} option, warn about traditional C" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wtraditional} option, warn about traditional C" msgstr "" #. type: option{#1} #, no-wrap msgid "-Wtraditional" msgstr "" #. type: table msgid "" "This option warns about parts of the code which would be interpreted " "differently by an ANSI/ISO compiler and a ``traditional'' pre-ANSI " "compiler.@footnote{The traditional form of the C language was described in " "the original C reference manual ``@cite{The C Programming Language (First " "Edition)}'' by Kernighan and Ritchie.} When maintaining legacy software it " "may be necessary to investigate whether the traditional or ANSI/ISO " "interpretation was intended in the original code for warnings generated by " "this option." msgstr "" #. type: cindex #, no-wrap msgid "warnings, promoting to errors" msgstr "" #. type: cindex #, no-wrap msgid "compilation, stopping on warning" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Werror} option, convert warnings to errors" msgstr "" #. type: cindex #, no-wrap msgid "@option{Werror} option, convert warnings to errors" msgstr "" #. type: Plain text msgid "" "The options above produce diagnostic warning messages, but allow the " "compilation to continue and produce an object file or executable. For large " "programs it can be desirable to catch all the warnings by stopping the " "compilation whenever a warning is generated. The @option{-Werror} option " "changes the default behavior by converting warnings into errors, stopping " "the compilation whenever a warning occurs." msgstr "" #. type: Plain text msgid "" "The following options are a good choice for finding problems in C and C++ " "programs:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -ansi -pedantic -Wall -W -Wconversion \n" " -Wshadow -Wcast-qual -Wwrite-strings\n" msgstr "" #. type: Plain text msgid "" "While this list is not exhaustive, regular use of these options will catch " "many common errors." msgstr "" #. type: cindex #, no-wrap msgid "@code{cpp}, C preprocessor" msgstr "" #. type: cindex #, no-wrap msgid "preprocessor, using" msgstr "" #. type: Plain text msgid "" "This chapter describes the use of the GNU C preprocessor @code{cpp}, which " "is part of the GCC package. The preprocessor expands macros in source files " "before they are compiled. It is automatically called whenever GCC processes " "a C or C++ program.@footnote{In recent versions of GCC the preprocessor is " "integrated into the compiler, although a separate @command{cpp} command is " "also provided.}" msgstr "" #. type: section #: #, no-wrap msgid "Defining macros" msgstr "" #. type: section #: #, no-wrap msgid "Macros with values" msgstr "" #. type: section #: #, no-wrap msgid "Preprocessing source files" msgstr "" #. type: cindex #, no-wrap msgid "defining macros" msgstr "" #. type: cindex #, no-wrap msgid "macros, defining in preprocessor" msgstr "" #. type: cindex #, no-wrap msgid "@code{#define}, preprocessor directive" msgstr "" #. type: cindex #, no-wrap msgid "@code{#ifdef}, preprocessor directive" msgstr "" #. type: Plain text msgid "" "The following program demonstrates the most common use of the C " "preprocessor. It uses the preprocessor conditional @code{#ifdef} to check " "whether a macro is defined:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude dtest.c\n" msgstr "" #. type: Plain text msgid "" "When the macro is defined, the preprocessor includes the corresponding code " "up to the closing @code{#endif} command. In this example, the macro which " "is tested is called @code{TEST}, and the conditional part of the source code " "is a @code{printf} statement which prints the message ``@code{Test mode}''." msgstr "" #. type: Plain text msgid "" "The @code{gcc} option @option{-D@var{NAME}} defines a preprocessor macro " "@code{NAME} from the command line. If the program above is compiled with " "the command-line option @option{-DTEST}, the macro @code{TEST} will be " "defined and the resulting executable will print both messages:" msgstr "" #. type: cindex #, no-wrap msgid "@option{-D} option, define macro" msgstr "" #. type: cindex #, no-wrap msgid "@option{D} option, define macro" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -DTEST dtest.c\n" "$ ./a.out\n" "Test mode\n" "Running...\n" msgstr "" #. type: Plain text msgid "" "If the same program is compiled without the @option{-D} option then the " "``@code{Test mode}'' message is omitted from the source code after " "preprocessing, and the final executable does not include the code for it:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall dtest.c\n" "$ ./a.out\n" "Running...\n" msgstr "" #. type: cindex #, no-wrap msgid "namespace, reserved prefix for preprocessor" msgstr "" #. type: Plain text msgid "" "Macros are generally undefined, unless specified on the command line with " "the option @option{-D}, or in a source file (or library header file) with " "@code{#define}. Some macros are automatically defined by the " "compiler---these typically use a reserved namespace beginning with a " "double-underscore prefix @samp{__}." msgstr "" #. type: Plain text msgid "" "The complete set of predefined macros can be listed by running the GNU " "preprocessor @code{cpp} with the option @option{-dM} on an empty file:" msgstr "" #. type: cindex #, no-wrap msgid "predefined macros" msgstr "" #. type: cindex #, no-wrap msgid "macros, predefined" msgstr "" #. type: cindex #, no-wrap msgid "@option{-dM} option, list predefined macros" msgstr "" #. type: cindex #, no-wrap msgid "@option{dM} option, list predefined macros" msgstr "" #. type: example #, no-wrap msgid "" "$ cpp -dM /dev/null\n" "#define __i586 1\n" "#define __WINT_MAX__ 4294967295U\n" "#define __ORDER_LITTLE_ENDIAN__ 1234\n" "#define __SIZE_MAX__ 4294967295U\n" ".......\n" msgstr "" #. type: Plain text msgid "" "Note that this list includes a small number of system-specific macros " "defined by @code{gcc} which do not use the double-underscore prefix. These " "non-standard macros can be disabled with the @option{-ansi} option of " "@code{gcc}." msgstr "" #. type: cindex #, no-wrap msgid "system-specific predefined macros" msgstr "" #. type: cindex #, no-wrap msgid "value, of macro" msgstr "" #. type: cindex #, no-wrap msgid "macros, defined with value" msgstr "" #. type: Plain text msgid "" "In addition to being defined, a macro can also be given a value. This value " "is inserted into the source code at each point where the macro occurs. The " "following program uses a macro @code{NUM}, to represent a number which will " "be printed:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude dtestval.c\n" msgstr "" #. type: Plain text msgid "" "Note that macros are not expanded inside strings---only the occurrence of " "@code{NUM} outside the string is substituted by the preprocessor." msgstr "" #. type: Plain text msgid "" "To define a macro with a value, the @option{-D} command-line option can be " "used in the form @option{-D@var{NAME}=@var{VALUE}}. For example, the " "following command line defines @code{NUM} to be 100 when compiling the " "program above:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -DNUM=100 dtestval.c\n" "$ ./a.out \n" "Value of NUM is 100\n" msgstr "" #. type: Plain text msgid "" "This example uses a number, but a macro can take values of any form. " "Whatever the value of the macro is, it is inserted directly into the source " "code at the point where the macro name occurs. For example, the following " "definition expands the occurrences of @code{NUM} to @code{2+2} during " "preprocessing:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -DNUM=\"2+2\" dtestval.c\n" "$ ./a.out \n" "Value of NUM is 4\n" msgstr "" #. type: Plain text msgid "" "After the preprocessor has made the substitution @code{NUM @expansion{} 2+2} " "this is equivalent to compiling the following program:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude dtestval2.c\n" msgstr "" #. type: Plain text msgid "" "Note that it is a good idea to surround macros by parentheses whenever they " "are part of an expression. For example, the following program uses " "parentheses to ensure the correct precedence for the multiplication " "@code{10*NUM}:" msgstr "" #. type: cindex #, no-wrap msgid "precedence, when using preprocessor" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude dtestval3.c\n" msgstr "" #. type: Plain text msgid "" "With these parentheses, it produces the expected result when compiled with " "the same command line as above:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -DNUM=\"2+2\" dtestval3.c\n" "$ ./a.out \n" "Ten times NUM is 40\n" msgstr "" #. type: Plain text msgid "" "Without parentheses, the program would produce the value @code{22} from the " "literal form of the expression @code{10*2+2 = 22}, instead of the desired " "value @code{10*(2+2) = 40}." msgstr "" #. type: Plain text msgid "" "When a macro is defined with @option{-D} alone, @code{gcc} uses a default " "value of @code{1}. For example, compiling the original test program with " "the option @option{-DNUM} generates an executable which produces the " "following output:" msgstr "" #. type: cindex #, no-wrap msgid "default value, of macro defined with @option{-D}" msgstr "" #. type: cindex #, no-wrap msgid "macros, default value of" msgstr "" #. type: cindex #, no-wrap msgid "preprocessor macros, default value of" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -DNUM dtestval.c\n" "$ ./a.out \n" "Value of NUM is 1\n" msgstr "" #. type: cindex #, no-wrap msgid "quotes, for defining empty macro" msgstr "" #. type: Plain text msgid "" "A macro can be defined with an empty value using quotes on the command line, " "@code{-D@var{NAME}=\"\"}. Such a macro is still treated as @i{defined} by " "conditionals such as @code{#ifdef}, but expands to nothing." msgstr "" #. type: cindex #, no-wrap msgid "empty macro, compared with undefined macro" msgstr "" #. type: cindex #, no-wrap msgid "undefined macro, compared with empty macro" msgstr "" #. type: Plain text msgid "" "A macro containing quotes can be defined using shell-escaped quote " "characters. For example, the command-line option @code{-DMESSAGE='\"Hello, " "World!\"'} defines a macro @code{MESSAGE} which expands to the sequence of " "characters @code{\"Hello, World!\"}. The outer shell-quotes @code{'...'} " "protect the C-quotes of the string @code{\"Hello, World!\"}. For an " "explanation of the different types of quoting and escaping used in the shell " "see the ``@cite{GNU Bash Reference Manual}'', @ref{Further reading}." msgstr "" #. type: cindex #: #, no-wrap msgid "shell quoting" msgstr "" #. type: cindex #, no-wrap msgid "@option{-E} option, preprocess source files" msgstr "" #. type: cindex #, no-wrap msgid "@option{E} option, preprocess source files" msgstr "" #. type: cindex #, no-wrap msgid "preprocessing source files, @option{-E} option" msgstr "" #. type: Plain text msgid "" "It is possible to see the effect of the preprocessor on source files " "directly, using the @option{-E} option of @code{gcc}. For example, the file " "below defines and uses a macro @code{TEST}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude test.c\n" msgstr "" #. type: Plain text msgid "" "If this file is called @file{test.c} the effect of the preprocessor can be " "seen with the following command line:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -E test.c\n" "# 1 \"test.c\"\n" "# 1 \"\"\n" "# 1 \"\"\n" "# 1 \"test.c\"\n" "\n" msgstr "" #. type: example #, no-wrap msgid "const char str[] = \"Hello, World!\";\n" msgstr "" #. type: Plain text msgid "" "The @option{-E} option causes @code{gcc} to run the preprocessor, display " "the expanded output, and then exit without compiling the resulting source " "code. The value of the macro @code{TEST} is substituted directly into the " "output, producing the sequence of characters @code{const char str[] = " "\"Hello, World!\" ;}." msgstr "" #. type: cindex #, no-wrap msgid "line numbers, recorded in preprocessed files" msgstr "" #. type: Plain text msgid "" "The preprocessor also inserts lines recording the source file and line " "numbers in the form @code{# @var{line-number} \"@var{source-file}\"}, to aid " "in debugging and allow the compiler to issue error messages referring to " "this information. These lines do not affect the program itself." msgstr "" #. type: Plain text msgid "" "The ability to see the preprocessed source files can be useful for examining " "the effect of system header files, and finding declarations of system " "functions. The following program includes the header file @file{stdio.h} to " "obtain the declaration of the function @code{printf}:" msgstr "" #. type: Plain text msgid "" "It is possible to see the declarations from the included header file by " "preprocessing the file with @code{gcc -E}:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -E hello.c\n" msgstr "" #. type: Plain text msgid "On a GNU system, this produces output similar to the following:" msgstr "" #. type: example #, no-wrap msgid "" "# 1 \"hello.c\"\n" "# 1 \"/usr/include/stdio.h\" 1 3\n" " \n" msgstr "" #. type: example #, no-wrap msgid "" "extern FILE *stdin;\t\t \n" "extern FILE *stdout;\t\t \n" "extern FILE *stderr;\t\t \n" " \n" msgstr "" #. type: example #, no-wrap msgid "" "extern int fprintf (FILE * __stream, \n" " const char * __format, ...) ;\n" "extern int printf (const char * __format, ...) ;\n" "\n" msgstr "" #. type: example #, no-wrap msgid "" " @r{@i{[ ... additional declarations ... ]}}\n" "\n" msgstr "" #. type: example #, no-wrap msgid "" "# 1 \"hello.c\" 2\n" "\n" msgstr "" #. type: example #, no-wrap msgid "" "int\n" "main (void)\n" "@{\n" " printf (\"Hello, world!\\n\");\n" " return 0;\n" "@}\n" msgstr "" #. type: Plain text msgid "" "The preprocessed system header files usually generate a lot of output. This " "can be redirected to a file, or saved more conveniently using the @code{gcc} " "@option{-save-temps} option:" msgstr "" #. type: cindex #, no-wrap msgid "@option{-save-temps} option, keeps intermediate files" msgstr "" #. type: cindex #, no-wrap msgid "@option{save-temps} option, keeps intermediate files" msgstr "" #. type: cindex #, no-wrap msgid "preprocessed files, keeping" msgstr "" #. type: cindex #, no-wrap msgid "intermediate files, keeping" msgstr "" #. type: cindex #, no-wrap msgid "temporary files, keeping" msgstr "" #. type: example #, no-wrap msgid "$ gcc -c -save-temps hello.c\n" msgstr "" #. type: Plain text msgid "" "After running this command, the preprocessed output will be available in the " "file @file{hello.i}. The @option{-save-temps} option also saves @file{.s} " "assembly files and @file{.o} object files in addition to preprocessed " "@file{.i} files." msgstr "" #. type: cindex #, no-wrap msgid "debugging, compilation flags" msgstr "" #. type: cindex #, no-wrap msgid "@option{-g} option, enable debugging" msgstr "" #. type: cindex #, no-wrap msgid "@option{g} option, enable debugging" msgstr "" #. type: cindex #, no-wrap msgid "compilation, for debugging" msgstr "" #. type: Plain text msgid "" "Normally, an executable file does not contain any references to the original " "program source code, such as variable names or line-numbers---the executable " "file is simply the sequence of machine code instructions produced by the " "compiler. This is insufficient for debugging, since there is no easy way to " "find the cause of an error if the program crashes." msgstr "" #. type: code{#1} #, no-wrap msgid "gdb" msgstr "" #. type: cindex #, no-wrap msgid "debugging, with @code{gdb}" msgstr "" #. type: cindex #, no-wrap msgid "GNU debugger, @code{gdb}" msgstr "" #. type: cindex #, no-wrap msgid "symbol table" msgstr "" #. type: cindex #, no-wrap msgid "executable, symbol table stored in" msgstr "" #. type: Plain text msgid "" "GCC provides the @option{-g} @dfn{debug option} to store additional " "debugging information in object files and executables. This debugging " "information allows errors to be traced back from a specific machine " "instruction to the corresponding line in the original source file. The " "execution of a program compiled with @option{-g} can also be followed in a " "debugger, such as the GNU Debugger @code{gdb} (for more information, see " "``@cite{Debugging with GDB: The GNU Source-Level Debugger}'', @ref{Further " "reading}). Using a debugger allows the values of variables to be examined " "while the program is running." msgstr "" #. type: Plain text msgid "" "The debug compilation option works by storing the names and source code " "line-numbers of functions and variables in a @dfn{symbol table} in the " "object file or executable." msgstr "" #. type: section #: #, no-wrap msgid "Examining core files" msgstr "" #. type: section #: #, no-wrap msgid "Displaying a backtrace" msgstr "" #. type: section #: #, no-wrap msgid "Setting a breakpoint" msgstr "" #. type: section #: #, no-wrap msgid "Stepping through the program" msgstr "" #. type: section #: #, no-wrap msgid "Modifying variables" msgstr "" #. type: section #: #, no-wrap msgid "Continuing execution" msgstr "" #. type: node #: #, no-wrap msgid "More information about GDB" msgstr "" #. type: cindex #: #, no-wrap msgid "core file, examining" msgstr "" #. type: cindex #, no-wrap msgid "crashes, saved in core file" msgstr "" #. type: cindex #, no-wrap msgid "program crashes, saved in core file" msgstr "" #. type: cindex #, no-wrap msgid "examining core files" msgstr "" #. type: Plain text msgid "" "In addition to allowing programs to be run under the debugger, an important " "benefit of the @option{-g} option is the ability to examine the cause of a " "program crash from a ``core dump''." msgstr "" #. type: cindex #, no-wrap msgid "termination, abnormal (@code{core dumped})" msgstr "" #. type: Plain text msgid "" "When a program exits abnormally (i.e. crashes) the operating system can " "write out a @dfn{core file} (usually named @file{core}) which contains the " "in-memory state of the program at the time it crashed. This file is often " "referred to as a @dfn{core dump}.@footnote{The terminology dates back to the " "time of magnetic core memory.} Combined with information from the symbol " "table produced by @option{-g}, the core dump can be used to find the line " "where the program stopped, and the values of its variables at that point." msgstr "" #. type: cindex #: #, no-wrap msgid "deployment, options for" msgstr "" #. type: Plain text msgid "" "This is useful both during the development of software and after " "deployment---it allows problems to be investigated when a program has " "crashed ``in the field''." msgstr "" #. type: Plain text msgid "" "Here is a simple program containing an invalid memory access bug, which we " "will use to produce a core file:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude null.c\n" msgstr "" #. type: cindex #, no-wrap msgid "dereferencing, null pointer" msgstr "" #. type: cindex #: #, no-wrap msgid "null pointer" msgstr "" #. type: Plain text msgid "" "The program attempts to dereference a null pointer @code{p}, which is an " "invalid operation. On most systems, this will cause a " "crash. @footnote{Historically, a null pointer corresponded to memory " "location 0, which is typically restricted to the operating system kernel. " "In practice this is not always how a null pointer works, but the result is " "usually the same.}" msgstr "" #. type: Plain text msgid "" "In order to be able to find the cause of the crash later, we will need to " "compile the program with the @option{-g} option:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -g null.c\n" msgstr "" #. type: Plain text msgid "" "Note that a null pointer will only cause a problem at run-time, so the " "option @option{-Wall} does not produce any warnings." msgstr "" #. type: Plain text msgid "" "Running the executable file on an x86 GNU/Linux system will cause the " "operating system to terminate the program abnormally:" msgstr "" #. type: cindex #: #, no-wrap msgid "segmentation fault" msgstr "" #. type: example #, no-wrap msgid "" "$ ./a.out \n" "Segmentation fault (core dumped)\n" msgstr "" #. type: Plain text msgid "" "Whenever the error message @samp{core dumped} is displayed, the operating " "system should produce a file called @file{core} in the current " "directory.@footnote{Some systems, such as FreeBSD and Solaris, can also be " "configured to write core files in specific directories, " "e.g. @file{/var/coredumps/}, using the @code{sysctl} or @code{coreadm} " "commands.} 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 " "@dfn{segmentation 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." msgstr "" #. type: cindex #, no-wrap msgid "core file, not produced" msgstr "" #. type: cindex #: #, no-wrap msgid "@command{ulimit} command" msgstr "" #. type: Plain text msgid "" "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 @cite{GNU Bash} shell the command @code{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:" msgstr "" #. type: cindex #, no-wrap msgid "@code{tcsh}, limit command" msgstr "" #. type: example #, no-wrap msgid "" "$ ulimit -c\n" "0\n" msgstr "" #. type: Plain text msgid "" "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:@footnote{This example uses the @code{ulimit} command in the GNU " "Bash shell. On other systems the usage of the @code{ulimit} command may " "vary, or have a different name (the @code{tcsh} shell uses the @code{limit} " "command instead). The size limit for core files can also be set to a " "specific value in kilobytes.}" msgstr "" #. type: example #, no-wrap msgid "$ ulimit -c unlimited\n" msgstr "" #. type: Plain text msgid "" "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 @file{.bash_profile} for the GNU Bash shell." msgstr "" #. type: cindex #, no-wrap msgid "@code{bash} profile file" msgstr "" #. type: cindex #, no-wrap msgid "@code{gdb}, debugging core file with" msgstr "" #. type: Plain text msgid "" "Core files can be loaded into the GNU Debugger @code{gdb} with the following " "command:" msgstr "" #. type: example #, no-wrap msgid "$ gdb @var{EXECUTABLE-FILE} @var{CORE-FILE}\n" msgstr "" #. type: Plain text msgid "" "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 " "corresponding executable. In this example, we can load the executable and " "core file with the command:" msgstr "" #. type: example #, no-wrap msgid "$ gdb a.out core\n" msgstr "" #. type: Plain text msgid "" "The debugger immediately begins printing diagnostic information, and shows a " "listing of the line where the program crashed (line 13):" msgstr "" #. type: example #, no-wrap msgid "" "$ gdb a.out core\n" "Core was generated by `./a.out'.\n" "Program terminated with signal 11, Segmentation fault.\n" "Reading symbols from /lib/libc.so.6...done.\n" "Loaded symbols for /lib/libc.so.6\n" "Reading symbols from /lib/ld-linux.so.2...done.\n" "Loaded symbols for /lib/ld-linux.so.2\n" "#0 0x080483ed in foo (p=0x0) at null.c:13\n" "13 int y = *p;\n" "(gdb)\n" msgstr "" #. type: Plain text msgid "" "The final line @code{(gdb)} is the GNU Debugger prompt---it indicates that " "further commands can be entered at this point.@footnote{The details of the " "diagnostic output may vary slightly depending on which version of @code{gdb} " "you are using.}" msgstr "" #. type: Plain text msgid "" "To investigate the cause of the crash, we display the value of the pointer " "@code{p} using the debugger @code{print} command:" msgstr "" #. type: cindex #, no-wrap msgid "@code{print} debugger command" msgstr "" #. type: example #: #, no-wrap msgid "" "(gdb) print p\n" "$1 = (int *) 0x0\n" msgstr "" #. type: Plain text msgid "" "This shows that @code{p} is a null pointer (@code{0x0}) of type @samp{int " "*}, so we know that dereferencing it with the expression @code{*p} in this " "line has caused the crash." msgstr "" #. type: cindex #, no-wrap msgid "displaying a backtrace" msgstr "" #. type: cindex #, no-wrap msgid "backtrace, displaying" msgstr "" #. type: cindex #, no-wrap msgid "stack backtrace, displaying" msgstr "" #. type: cindex #, no-wrap msgid "@code{backtrace}, debugger command" msgstr "" #. type: Plain text msgid "" "The debugger can also show the function calls and arguments up to the " "current point of execution---this is called a @dfn{stack backtrace} and is " "displayed with the command @code{backtrace}:" msgstr "" #. type: example #, no-wrap msgid "" "(gdb) backtrace\n" "#0 0x080483ed in foo (p=0x0) at null.c:13\n" "#1 0x080483d9 in main () at null.c:7\n" msgstr "" #. type: Plain text msgid "" "In this case, the backtrace shows that the crash occurred at line 13 after " "the function @code{foo} was called from @code{main} with an argument of " "@code{p=0x0} at line 7 in @file{null.c}. It is possible to move to " "different levels in the stack trace, and examine their variables, using the " "debugger commands @code{up} and @code{down}." msgstr "" #. type: cindex #, no-wrap msgid "@code{break}, command in @code{gdb}" msgstr "" #. type: cindex #, no-wrap msgid "breakpoints, defined" msgstr "" #. type: cindex #, no-wrap msgid "stopping execution, with breakpoints in @code{gdb}" msgstr "" #. type: Plain text msgid "" "A @dfn{breakpoint} stops the execution of a program and returns control to " "the debugger, where its variables and memory can be examined before " "continuing. Breakpoints can be set for specific functions, lines or memory " "locations with the @code{break} command." msgstr "" #. type: Plain text msgid "" "To set a breakpoint on a specific function, use the command @code{break " "@var{function-name}}. For example, the following command sets a breakpoint " "at the start of the @code{main} function in the program above:" msgstr "" #. type: example #, no-wrap msgid "" "$ gdb a.out\n" "(gdb) break main\n" "Breakpoint 1 at 0x80483c6: file null.c, line 6.\n" msgstr "" #. type: Plain text msgid "" "The debugger will now take control of the program when the function " "@code{main} is called. Since the @code{main} function is the first function " "to be executed in a C program the program will stop immediately when it is " "run:" msgstr "" #. type: example #, no-wrap msgid "" "(gdb) run\n" "Starting program: a.out \n" "Breakpoint 1, main () at null.c:6\n" "6 int *p = 0; /* null pointer */\n" "(gdb)\n" msgstr "" #. type: Plain text msgid "" "The display shows the line that will be executed next (the line number is " "shown on the left). The breakpoint stops the program @emph{before} the line " "is executed, so at this stage the pointer @code{p} is undefined and has not " "yet been set to zero." msgstr "" #. type: cindex #, no-wrap msgid "@code{step}, command in @code{gdb}" msgstr "" #. type: cindex #, no-wrap msgid "@code{next}, command in @code{gdb}" msgstr "" #. type: Plain text msgid "" "To move forward and execute the line displayed above, use the command " "@code{step}:" msgstr "" #. type: example #, no-wrap msgid "" "(gdb) step\n" "7 return foo (p);\n" msgstr "" #. type: Plain text msgid "" "After executing line 6, the debugger displays the next line to be executed. " "The pointer @code{p} will now have been set to zero (null):" msgstr "" #. type: Plain text msgid "" "The command @code{step} will follow the execution of the program " "interactively through any functions that are called in the current line. If " "you want to move forward without tracing these calls, use the command " "@code{next} instead." msgstr "" #. type: cindex #, no-wrap msgid "@code{set}, command in @code{gdb}" msgstr "" #. type: Plain text msgid "" "To temporarily fix the null pointer bug discovered above, we can change the " "value of @code{p} in the running program using the @code{set variable} " "command." msgstr "" #. type: Plain text msgid "" "Variables can be set to a specific value, or to the result of an expression, " "which may include function calls. This powerful feature allows functions in " "a program to be tested interactively through the debugger." msgstr "" #. type: Plain text msgid "" "In this case we will interactively allocate some memory for the pointer " "@code{p} using the function @code{malloc}, storing the value 255 in the " "resulting location:" msgstr "" #. type: example #, no-wrap msgid "" "(gdb) set variable p = malloc(sizeof(int))\n" "(gdb) print p\n" "$2 = (int *) 0x40013f98 @r{(address allocated by @code{malloc})}\n" "(gdb) set variable *p = 255\n" "(gdb) print *p\n" "$3 = 255\n" msgstr "" #. type: Plain text msgid "" "If we now continue stepping through the program with the new value of " "@code{p} the previous segmentation fault will not occur:" msgstr "" #. type: example #, no-wrap msgid "" "(gdb) step\n" "foo (p=0x40013f98) at null.c:13\n" "13 int y = *p;\n" "(gdb) step\n" "14 return y;\n" msgstr "" #. type: cindex #, no-wrap msgid "@code{finish}, command in @code{gdb}" msgstr "" #. type: cindex #, no-wrap msgid "@code{continue}, command in @code{gdb}" msgstr "" #. type: Plain text msgid "" "The command @code{finish} continues execution up to the end of the current " "function, displaying the return value:" msgstr "" #. type: example #, no-wrap msgid "" "(gdb) finish\n" "Run till exit from #0 0x08048400 in foo (p=0x40013f98) \n" "at null.c:15\n" "0x080483d9 in main () at null.c:7\n" "7 return foo (p);\n" "Value returned is $13 = 255\n" msgstr "" #. type: cindex #, no-wrap msgid "exit code, displayed in @code{gdb}" msgstr "" #. type: Plain text msgid "" "To continue execution until the program exits (or hits the next breakpoint) " "use the command @code{continue}," msgstr "" #. type: example #, no-wrap msgid "" "(gdb) continue\n" "Continuing.\n" "Program exited with code 0377.\n" msgstr "" #. type: Plain text msgid "Note that the exit code is shown in octal (0377 base 8 = 255 in base 10)." msgstr "" #. type: section #, no-wrap msgid "More information" msgstr "" #. type: cindex #, no-wrap msgid "Emacs, @code{gdb} mode" msgstr "" #. type: cindex #, no-wrap msgid "@code{gdb}, Emacs mode" msgstr "" #. type: cindex #, no-wrap msgid "@code{gdb}, graphical interface" msgstr "" #. type: cindex #, no-wrap msgid "Insight, graphical interface for @code{gdb}" msgstr "" #. type: Plain text msgid "" "For simplicity, the examples in this chapter demonstrate how to use " "@code{gdb} on the command-line. There are more powerful ways to debug a " "program interactively using tools such as Emacs @sc{gdb} mode (@kbd{M-x " "gdb}), @sc{ddd} or @sc{insight}, graphical interfaces to @code{gdb}. Links " "to these programs can be found on the publisher's webpage for this " "book.@footnote{@uref{http://www.network-theory.co.uk/gcc/intro/}}" msgstr "" #. type: Plain text msgid "" "A complete description of all the commands available in @code{gdb} can be " "found in the manual ``@cite{Debugging with GDB: The GNU Source-Level " "Debugger}'' (@pxref{Further reading})." msgstr "" #. type: cindex #, no-wrap msgid "optimization, explanation of" msgstr "" #. type: cindex #, no-wrap msgid "compiling with optimization" msgstr "" #. type: Plain text msgid "" "GCC is an @dfn{optimizing} compiler. It provides a wide range of options " "which aim to increase the speed, or reduce the size, of the executable files " "it generates." msgstr "" #. type: Plain text msgid "" "Optimization is a complex process. For each high-level command in the " "source code there are usually many possible combinations of machine " "instructions that can be used to achieve the appropriate final result. The " "compiler must consider these possibilities and choose among them." msgstr "" #. type: Plain text msgid "" "In general, different code must be generated for different processors, as " "they use incompatible assembly and machine languages. Each type of " "processor also has its own characteristics---some CPUs provide a large " "number of @dfn{registers} for holding intermediate results of calculations, " "while others must store and fetch intermediate results from memory. " "Appropriate code must be generated in each case." msgstr "" #. type: Plain text msgid "" "Furthermore, different amounts of time are needed for different " "instructions, depending on how they are ordered. GCC takes all these " "factors into account and tries to produce the fastest executable for a given " "system when compiling with optimization." msgstr "" #. type: section #: #, no-wrap msgid "Source-level optimization" msgstr "" #. type: section #: #, no-wrap msgid "Speed-space tradeoffs" msgstr "" #. type: section #: #, no-wrap msgid "Scheduling" msgstr "" #. type: section #: #, no-wrap msgid "Optimization levels" msgstr "" #. type: node #: #, no-wrap msgid "Optimization examples" msgstr "" #. type: section #: #, no-wrap msgid "Optimization and debugging" msgstr "" #. type: section #: #, no-wrap msgid "Optimization and compiler warnings" msgstr "" #. type: cindex #, no-wrap msgid "source-level optimization" msgstr "" #. type: Plain text msgid "" "The first form of optimization used by GCC occurs at the source-code level, " "and does not require any knowledge of the machine instructions. There are " "many source-level optimization techniques---this section describes two " "common types: @dfn{common subexpression elimination} and @dfn{function " "inlining}." msgstr "" #. type: subsection #, no-wrap msgid "Common subexpression elimination" msgstr "" #. type: cindex #, no-wrap msgid "common subexpression elimination, optimization" msgstr "" #. type: cindex #, no-wrap msgid "optimization, common subexpression elimination" msgstr "" #. type: cindex #, no-wrap msgid "subexpression elimination, optimization" msgstr "" #. type: cindex #, no-wrap msgid "elimination, of common subexpressions" msgstr "" #. type: Plain text msgid "" "One method of source-level optimization which is easy to understand involves " "computing an expression in the source code with fewer instructions, by " "reusing already-computed results. For example, the following assignment:" msgstr "" #. type: example #, no-wrap msgid "x = cos(v)*(1+sin(u/2)) + sin(w)*(1-sin(u/2))\n" msgstr "" #. type: Plain text msgid "" "can be rewritten with a temporary variable @code{t} to eliminate an " "unnecessary extra evaluation of the term @code{sin(u/2)}:" msgstr "" #. type: example #, no-wrap msgid "" "t = sin(u/2)\n" "x = cos(v)*(1+t) + sin(w)*(1-t)\n" msgstr "" #. type: Plain text msgid "" "This rewriting is called @dfn{common subexpression elimination} (CSE), and " "is performed automatically when optimization is turned " "on.@footnote{Temporary values introduced by the compiler during common " "subexpression elimination are only used internally, and do not affect real " "variables. The name of the temporary variable @samp{t} shown above is only " "used as an illustration.} Common subexpression elimination is powerful, " "because it simultaneously increases the speed and reduces the size of the " "code." msgstr "" #. type: subsection #, no-wrap msgid "Function inlining" msgstr "" #. type: cindex #, no-wrap msgid "function inlining, example of optimization" msgstr "" #. type: cindex #, no-wrap msgid "inlining, example of optimization" msgstr "" #. type: Plain text msgid "" "Another type of source-level optimization, called @dfn{function inlining}, " "increases the efficiency of frequently-called functions." msgstr "" #. type: Plain text msgid "" "Whenever a function is used, a certain amount of extra time is required for " "the CPU to carry out the call: it must store the function arguments in the " "appropriate registers and memory locations, jump to the start of the " "function (bringing the appropriate virtual memory pages into physical memory " "or the CPU cache if necessary), begin executing the code, and then return to " "the original point of execution when the function call is complete. This " "additional work is referred to as @dfn{function-call overhead}. Function " "inlining eliminates this overhead by replacing calls to a function by the " "code of the function itself (known as placing the code @dfn{in-line})." msgstr "" #. type: cindex #, no-wrap msgid "function-call overhead" msgstr "" #. type: cindex #, no-wrap msgid "overhead, from function call" msgstr "" #. type: Plain text msgid "" "In most cases, function-call overhead is a negligible fraction of the total " "run-time of a program. It can become significant only when there are " "functions which contain relatively few instructions, and these functions " "account for a substantial fraction of the run-time---in this case the " "overhead then becomes a large proportion of the total run-time." msgstr "" #. type: Plain text msgid "" "Inlining is always favorable if there is only one point of invocation of a " "function. It is also unconditionally better if the invocation of a function " "requires more instructions (memory) than moving the body of the function " "in-line. This is a common situation for simple accessor functions in C++, " "which can benefit greatly from inlining. Moreover, inlining may facilitate " "further optimizations, such as common subexpression elimination, by merging " "several separate functions into a single large function." msgstr "" #. type: Plain text msgid "" "The following function @code{sq(x)} is a typical example of a function that " "would benefit from being inlined. It computes @math{x^2}, the square of its " "argument @math{x}:" msgstr "" #. type: example #, no-wrap msgid "" "double\n" "sq (double x)\n" "@{\n" " return x * x;\n" "@}\n" msgstr "" #. type: Plain text msgid "" "This function is small, so the overhead of calling it is comparable to the " "time taken to execute the single multiplication carried out by the function " "itself. If this function is used inside a loop, such as the one below, then " "the function-call overhead would become substantial:" msgstr "" #. type: example #, no-wrap msgid "" "for (i = 0; i < 1000000; i++)\n" " @{\n" " sum += sq (i + 0.5);\n" " @}\n" msgstr "" #. type: Plain text msgid "" "Optimization with inlining replaces the inner loop of the program with the " "body of the function, giving the following code:" msgstr "" #. type: example #, no-wrap msgid "" "for (i = 0; i < 1000000; i++)\n" " @{\n" " double t = (i + 0.5); /* temporary variable */\n" " sum += t * t;\n" " @}\n" msgstr "" #. type: Plain text msgid "" "Eliminating the function call and performing the multiplication " "@dfn{in-line} allows the loop to run with maximum efficiency." msgstr "" #. type: Plain text msgid "" "GCC selects functions for inlining using a number of heuristics, such as the " "function being suitably small. As an optimization, inlining is carried out " "only within each object file. The @code{inline} keyword can be used to " "request explicitly that a specific function should be inlined wherever " "possible, including its use in other files.@footnote{In this case, the " "definition of the inline function must be made available to the other files " "(e.g. in a header file).} The GCC Reference Manual ``@cite{Using GCC}'' " "provides full details of the @code{inline} keyword, and its use with the " "@code{static} and @code{extern} qualifiers to control the linkage of " "explicitly inlined functions (@pxref{Further reading})." msgstr "" #. type: cindex #, no-wrap msgid "speed-space tradeoffs, in optimization" msgstr "" #. type: cindex #, no-wrap msgid "optimization, speed-space tradeoffs" msgstr "" #. type: cindex #, no-wrap msgid "tradeoffs, between speed and space in optimization" msgstr "" #. type: cindex #, no-wrap msgid "space vs speed, tradeoff in optimization" msgstr "" #. type: Plain text msgid "" "While some forms of optimization, such as common subexpression elimination, " "are able to increase the speed and reduce the size of a program " "simultaneously, other types of optimization produce faster code at the " "expense of increasing the size of the executable. This choice between speed " "and memory is referred to as a @dfn{speed-space tradeoff}. Optimizations " "with a speed-space tradeoff can also be used in reverse to make an " "executable smaller, at the expense of making it run slower." msgstr "" #. type: subsection #, no-wrap msgid "Loop unrolling" msgstr "" #. type: cindex #: #, no-wrap msgid "loop unrolling, optimization" msgstr "" #. type: cindex #: #, no-wrap msgid "optimization, loop unrolling" msgstr "" #. type: cindex #: #, no-wrap msgid "unrolling, of loops (optimization)" msgstr "" #. type: Plain text msgid "" "A prime example of an optimization with a speed-space tradeoff is @dfn{loop " "unrolling}. This form of optimization increases the speed of loops by " "eliminating the ``end of loop'' condition on each iteration. For example, " "the following loop from 0 to 7 tests the condition @code{i < 8} on each " "iteration:" msgstr "" #. type: example #, no-wrap msgid "" "for (i = 0; i < 8; i++)\n" " @{\n" " y[i] = i;\n" " @}\n" msgstr "" #. type: Plain text msgid "" "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." msgstr "" #. type: Plain text msgid "" "A more efficient way to write the same code is simply to @dfn{unroll the " "loop} and execute the assignments directly:" msgstr "" #. type: example #, no-wrap msgid "" "y[0] = 0;\n" "y[1] = 1;\n" "y[2] = 2;\n" "y[3] = 3;\n" "y[4] = 4;\n" "y[5] = 5;\n" "y[6] = 6;\n" "y[7] = 7;\n" msgstr "" #. type: Plain text msgid "" "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)." msgstr "" #. type: Plain text msgid "" "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," msgstr "" #. type: example #, no-wrap msgid "" "for (i = 0; i < n; i++)\n" " @{\n" " y[i] = i;\n" " @}\n" msgstr "" #. type: Plain text msgid "can be rewritten by the compiler as follows:" msgstr "" #. type: example #, no-wrap msgid "" "for (i = 0; i < (n % 2); i++)\n" " @{\n" " y[i] = i;\n" " @}\n" "\n" msgstr "" #. type: example #, no-wrap msgid "" "for ( ; i + 1 < n; i += 2) /* no initializer */\n" " @{\n" " y[i] = i;\n" " y[i+1] = i+1; \n" " @}\n" msgstr "" #. type: Plain text msgid "" "The first loop handles the case @code{i = 0} when @code{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 @code{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." msgstr "" #. type: cindex #, no-wrap msgid "scheduling, stage of optimization" msgstr "" #. type: cindex #, no-wrap msgid "instruction scheduling, optimization" msgstr "" #. type: cindex #, no-wrap msgid "pipelining, explanation of" msgstr "" #. type: Plain text msgid "" "The lowest level of optimization is @dfn{scheduling}, in which the compiler " "determines the best ordering of individual instructions. Most CPUs allow " "one or more new instructions to start executing before others have " "finished. Many CPUs also support @dfn{pipelining}, where multiple " "instructions execute in parallel on the same CPU." msgstr "" #. type: Plain text msgid "" "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)." msgstr "" #. type: cindex #, no-wrap msgid "optimization, compiling with @option{-O}" msgstr "" #. type: cindex #, no-wrap msgid "optimization, levels of" msgstr "" #. type: cindex #, no-wrap msgid "levels of optimization" msgstr "" #. type: cindex #, no-wrap msgid "@option{O} option, optimization level" msgstr "" #. type: Plain text msgid "" "In order to control compilation-time and compiler memory usage, and the " "trade-offs between speed and space for the resulting executable, GCC " "provides a range of general optimization levels, numbered from 0--3, as well " "as individual options for specific types of optimization." msgstr "" #. type: Plain text msgid "" "An optimization level is chosen with the command line option " "@option{-O@var{LEVEL}}, where @code{@var{LEVEL}} is a number from 0 to 3. " "The effects of the different optimization levels are described below:" msgstr "" #. type: item #, no-wrap msgid "@option{-O0} or @r{no @option{-O} option} (default)" msgstr "" #. type: cindex #, no-wrap msgid "@option{-O0} option, optimization level zero" msgstr "" #. type: cindex #, no-wrap msgid "unoptimized code (@option{-O0})" msgstr "" #. type: table msgid "" "At this optimization level GCC does not perform any optimization and " "compiles the source code in the most straightforward way possible. Each " "command in the source code is converted directly to the corresponding " "instructions in the executable file, without rearrangement. This is the " "best option to use when debugging a program and is the default if no " "optimization level option is specified." msgstr "" #. type: item #, no-wrap msgid "@option{-O1} @r{or} @option{-O}" msgstr "" #. type: cindex #, no-wrap msgid "@option{-O1} option, optimization level one" msgstr "" #. type: table msgid "" "This level turns on the most common forms of optimization that do not " "require any speed-space tradeoffs. With this option the resulting " "executables should be smaller and faster than with @option{-O0}. The more " "expensive optimizations, such as instruction scheduling, are not used at " "this level." msgstr "" #. type: table msgid "" "Compiling with the option @option{-O1} can often take less time than " "compiling with @option{-O0}, due to the reduced amounts of data that need to " "be processed after simple optimizations." msgstr "" #. type: option{#1} #, no-wrap msgid "-O2" msgstr "" #. type: cindex #, no-wrap msgid "@option{-O2} option, optimization level two" msgstr "" #. type: table msgid "" "This option turns on further optimizations, in addition to those used by " "@option{-O1}. These additional optimizations include instruction " "scheduling. Only optimizations that do not require any speed-space " "tradeoffs are used, so the executable should not increase in size. The " "compiler will take longer to compile programs and require more memory than " "with @option{-O1}. This option is generally the best choice for deployment " "of a program, because it provides maximum optimization without increasing " "the executable size. It is the default optimization level for releases of " "GNU packages." msgstr "" #. type: option{#1} #, no-wrap msgid "-O3" msgstr "" #. type: cindex #, no-wrap msgid "@option{-O3} option, optimization level three" msgstr "" #. type: table msgid "" "This option turns on more expensive optimizations, such as function " "inlining, in addition to all the optimizations of the lower levels " "@option{-O2} and @option{-O1}. The @option{-O3} optimization level may " "increase the speed of the resulting executable, but can also increase its " "size. Under some circumstances where these optimizations are not favorable, " "this option might actually make a program slower." msgstr "" #. type: option{#1} #, no-wrap msgid "-funroll-loops" msgstr "" #. type: cindex #, no-wrap msgid "@option{-funroll-loops} option, optimization by loop unrolling" msgstr "" #. type: cindex #, no-wrap msgid "@option{funroll-loops} option, optimization by loop unrolling" msgstr "" #. type: table msgid "" "This option turns on loop-unrolling, and is independent of the other " "optimization options. It will increase the size of an executable. Whether " "or not this option produces a beneficial result has to be examined on a " "case-by-case basis." msgstr "" #. type: option{#1} #, no-wrap msgid "-Os" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Os} option, optimization for size" msgstr "" #. type: cindex #, no-wrap msgid "optimization for size, @option{-Os}" msgstr "" #. type: cindex #, no-wrap msgid "size, optimization for, @option{-Os}" msgstr "" #. type: table msgid "" "This option selects optimizations which reduce the size of an executable. " "The aim of this option is to produce the smallest possible executable, for " "systems constrained by memory or disk space. In some cases a smaller " "executable will also run faster, due to better cache usage." msgstr "" #. type: Plain text msgid "" "It is important to remember that the benefit of optimization at the highest " "levels must be weighed against the cost. The cost of optimization includes " "greater complexity in debugging, and increased time and memory requirements " "during compilation. For most purposes it is satisfactory to use " "@option{-O0} for debugging, and @option{-O2} for development and deployment." msgstr "" #. type: section #, no-wrap msgid "Examples" msgstr "" #. type: cindex #, no-wrap msgid "optimization, example of" msgstr "" #. type: Plain text msgid "" "The following program will be used to demonstrate the effects of different " "optimization levels:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude optim.c\n" msgstr "" #. type: cindex #, no-wrap msgid "benchmarking, with @code{time} command" msgstr "" #. type: cindex #, no-wrap msgid "@code{time} command, measuring run-time" msgstr "" #. type: cindex #, no-wrap msgid "run-time, measuring with @code{time} command" msgstr "" #. type: Plain text msgid "" "The main program contains a loop calling the @code{powern} function. This " "function computes the @i{n}-th power of a floating point number by repeated " "multiplication---it has been chosen because it is suitable for both inlining " "and loop-unrolling. The run-time of the program can be measured using the " "@code{time} command in the GNU Bash shell." msgstr "" #. type: Plain text msgid "" "Here are some results for the program above, compiled on a 566@dmn{MHz} " "Intel Celeron with 16@dmn{KB} L1-cache and 128@dmn{KB} L2-cache, using GCC " "3.3.1 on a GNU/Linux system:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -O0 optim.c -lm\n" "$ time ./a.out \n" "real 0m13.388s\n" "user 0m13.370s\n" "sys 0m0.010s\n" "\n" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -O1 optim.c -lm\n" "$ time ./a.out\n" "real 0m10.030s\n" "user 0m10.030s\n" "sys 0m0.000s\n" "\n" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -O2 optim.c -lm\n" "$ time ./a.out\n" "real 0m8.388s\n" "user 0m8.380s\n" "sys 0m0.000s\n" "\n" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -O3 optim.c -lm\n" "$ time ./a.out\n" "real 0m6.742s\n" "user 0m6.730s\n" "sys 0m0.000s\n" "\n" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -O3 -funroll-loops optim.c -lm\n" "$ time ./a.out\n" "real 0m5.412s\n" "user 0m5.390s\n" "sys 0m0.000s\n" msgstr "" #. type: Plain text msgid "" "The relevant entry in the output for comparing the speed of the resulting " "executables is the @samp{user} time, which gives the actual CPU time spent " "running the process. The other rows, @samp{real} and @samp{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." msgstr "" #. type: Plain text msgid "" "From the results it can be seen in this case that increasing the " "optimization level with @option{-O1}, @option{-O2} and @option{-O3} produces " "an increasing speedup, relative to the unoptimized code compiled with " "@option{-O0}. The additional option @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." msgstr "" #. type: Plain text msgid "" "Note that for a small program such as this there can be considerable " "variation between systems and compiler versions. For example, on a Mobile " "2.0@dmn{GHz} Intel Pentium 4M system the trend of the results using the same " "version of GCC is similar except that the performance with @option{-O2} is " "slightly worse than with @option{-O1}. This illustrates an important point: " "optimizations may not necessarily make a program faster in every case." msgstr "" #. type: cindex #, no-wrap msgid "debugging, with optimization" msgstr "" #. type: cindex #, no-wrap msgid "optimization, with debugging" msgstr "" #. type: Plain text msgid "" "With GCC it is possible to use optimization in combination with the " "debugging option @option{-g}. Many other compilers do not allow this." msgstr "" #. type: Plain text msgid "" "When using debugging and optimization together, the internal rearrangements " "carried out by the optimizer can make it difficult to see what is going on " "when examining an optimized program in the debugger. For example, temporary " "variables are often eliminated, and the ordering of statements may be " "changed." msgstr "" #. type: Plain text msgid "" "However, when a program crashes unexpectedly, any debugging information is " "better than none---so the use of @option{-g} is recommended for optimized " "programs, both for development and deployment. The debugging option " "@option{-g} is enabled by default for releases of GNU packages, together " "with the optimization option @option{-O2}." msgstr "" #. type: cindex #, no-wrap msgid "optimization, and compiler warnings" msgstr "" #. type: cindex #, no-wrap msgid "warnings, and optimization" msgstr "" #. type: Plain text msgid "" "When optimization is turned on, GCC can produce additional warnings that do " "not appear when compiling without optimization." msgstr "" #. type: cindex #, no-wrap msgid "data-flow analysis" msgstr "" #. type: Plain text msgid "" "As part of the optimization process, the compiler examines the use of all " "variables and their initial values---this is referred to as @dfn{data-flow " "analysis}. It forms the basis for other optimization strategies, such as " "instruction scheduling. A side-effect of data-flow analysis is that the " "compiler can detect the use of uninitialized variables." msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wuninitialized} option, warn about uninitialized variables" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wuninitialized} option, warn about uninitialized variables" msgstr "" #. type: Plain text msgid "" "The @option{-Wuninitialized} option (which is included in @option{-Wall}) " "warns about variables that are read without being initialized. It only " "works when the program is compiled with optimization, so that data-flow " "analysis is enabled. The following function contains an example of such a " "variable:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude uninit.c\n" msgstr "" #. type: Plain text msgid "" "The function works correctly for most arguments, but has a bug when @code{x} " "is zero---in this case the return value of the variable @code{s} will be " "undefined." msgstr "" #. type: Plain text msgid "" "Compiling the program with the @option{-Wall} option alone does not produce " "any warnings, because data-flow analysis is not carried out without " "optimization:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -c uninit.c \n" msgstr "" #. type: Plain text msgid "" "To produce a warning, the program must be compiled with @option{-Wall} and " "optimization simultaneously. In practice, the optimization level " "@option{-O2} is needed to give good warnings:" msgstr "" #. type: cindex #, no-wrap msgid "uninitialized variable, warning of" msgstr "" #. type: cindex #, no-wrap msgid "variable, warning of uninitialized use" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -O2 -c uninit.c\n" "uninit.c: In function 'sign':\n" "uninit.c:11:3: warning: 's' may be used uninitialized \n" " in this function [-Wuninitialized]\n" msgstr "" #. type: Plain text msgid "" "This correctly detects the possibility of the variable @code{s} being used " "without being defined." msgstr "" #. type: Plain text msgid "" "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." msgstr "" #. type: cindex #, no-wrap msgid "C++, @code{g++} as a true compiler" msgstr "" #. type: cindex #, no-wrap msgid "translators, from C++ to C, compared with @code{g++}" msgstr "" #. type: Plain text msgid "" "This chapter describes how to use GCC to compile programs written in C++, " "and the command-line options specific to that language." msgstr "" #. type: Plain text msgid "" "The GNU C++ compiler provided by GCC is a true C++ compiler---it compiles " "C++ source code directly into assembly language. Some other C++ " "``compilers'' are translators which convert C++ programs into C, and then " "compile the resulting C program using an existing C compiler. A true C++ " "compiler, such as GCC, is able to provide better support for error " "reporting, debugging and optimization." msgstr "" #. type: section #: #, no-wrap msgid "Compiling a simple C++ program" msgstr "" #. type: section #: #, no-wrap msgid "C++ compilation options" msgstr "" #. type: section #: #, no-wrap msgid "Using the C++ standard library" msgstr "" #. type: section #: #, no-wrap msgid "Templates" msgstr "" #. type: cindex #, no-wrap msgid "C++, compiling a simple program with @code{g++}" msgstr "" #. type: cindex #, no-wrap msgid "@code{g++}, compiling C++ programs" msgstr "" #. type: cindex #, no-wrap msgid "compiling C++ programs with @code{g++}" msgstr "" #. type: cindex #, no-wrap msgid "simple C++ program, compiling" msgstr "" #. type: Plain text msgid "" "The procedure for compiling a C++ program is the same as for a C program, " "but uses the command @code{g++} instead of @code{gcc}. Both compilers are " "part of the GNU Compiler Collection." msgstr "" #. type: cindex #, no-wrap msgid "Hello World program, in C++" msgstr "" #. type: Plain text msgid "" "To demonstrate the use of @code{g++}, here is a version of the @dfn{Hello " "World} program written in C++:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude hello.cc\n" msgstr "" #. type: Plain text msgid "The program can be compiled with the following command line:" msgstr "" #. type: example #, no-wrap msgid "$ g++ -Wall hello.cc -o hello\n" msgstr "" #. type: cindex #, no-wrap msgid "@code{.cc}, C++ file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{cc}, C++ file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{.cpp}, C++ file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{cpp}, C++ file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{.cxx}, C++ file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{cxx}, C++ file extension" msgstr "" #. type: cindex #: #, no-wrap msgid "extension, @code{.C}, C++ file" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.cc}, C++ file" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.cpp}, C++ file" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.cxx}, C++ file" msgstr "" #. type: cindex #: #, no-wrap msgid "file extension, @code{.C}, C++ file" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.cc}, C++ file" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.cpp}, C++ file" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.cxx}, C++ file" msgstr "" #. type: cindex #, no-wrap msgid "C++, file extensions" msgstr "" #. type: Plain text msgid "" "The C++ frontend of GCC uses many of the same the same options as the C " "compiler @code{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 @file{.cc}, @file{.cpp}, @file{.cxx} or @file{.C} rather than the " "@file{.c} extension used for C programs." msgstr "" #. type: cindex #, no-wrap msgid "@option{-ansi} option, used with @code{g++}" msgstr "" #. type: cindex #, no-wrap msgid "@option{ansi} option, used with @code{g++}" msgstr "" #. type: cindex #, no-wrap msgid "ISO C++, controlled with @option{-ansi} option" msgstr "" #. type: cindex #, no-wrap msgid "running an executable file, C++" msgstr "" #. type: Plain text msgid "" "The resulting executable can be run in exactly same way as the C version, " "simply by typing its filename:" msgstr "" #. type: Plain text msgid "" "The executable produces the same output as the C version of the program, " "using @code{std::cout} instead of the C @code{printf} function. All the " "options used in the @code{gcc} commands in previous chapters apply to " "@code{g++} without change, as do the procedures for compiling and linking " "files and libraries (using @code{g++} instead of @code{gcc}, of course). " "One natural difference is that the @option{-ansi} option requests compliance " "with the C++ standard, instead of the C standard, when used with @code{g++}." msgstr "" #. type: Plain text msgid "" "Note that programs using C++ object files must always be linked with " "@code{g++}, in order to supply the appropriate C++ libraries. Attempting to " "link a C++ object file with the C compiler @code{gcc} will cause ``undefined " "reference'' errors for C++ standard library functions:" msgstr "" #. type: cindex #, no-wrap msgid "undefined reference to C++ function, due to linking with @code{gcc}" msgstr "" #. type: example #, no-wrap msgid "" "$ g++ -Wall -c hello.cc\n" "$ gcc hello.o @r{(should use @code{g++})}\n" "hello.o: In function `main':\n" "hello.o(.text+0x1b): undefined reference to `std::cout'\n" ".....\n" "hello.o(.eh_frame+0x11): \n" " undefined reference to `__gxx_personality_v0'\n" msgstr "" #. type: Plain text msgid "" "Undefined references to internal run-time library functions, such as " "@code{__gxx_personality_v0}, are also a symptom of linking C++ object files " "with @code{gcc} instead of @code{g++}.@footnote{Since these functions are " "internal, the error shown in this example will be different in other " "versions of the compiler.} Linking the same object file with @code{g++} " "supplies all the necessary C++ libraries and will produce a working " "executable:" msgstr "" #. type: example #, no-wrap msgid "" "$ g++ hello.o\n" "$ ./a.out\n" "Hello, world!\n" msgstr "" #. type: cindex #, no-wrap msgid "@code{__gxx_personality_v0}, undefined reference error" msgstr "" #. type: cindex #, no-wrap msgid "@code{gxx_personality_v0}, undefined reference error" msgstr "" #. type: cindex #, no-wrap msgid "@code{gcc}, used inconsistently with @code{g++}" msgstr "" #. type: cindex #, no-wrap msgid "undefined reference error for @code{__gxx_personality_v0}" msgstr "" #. type: Plain text msgid "" "A point that sometimes causes confusion is that @code{gcc} will actually " "compile C++ source code when it detects a C++ file extension, but cannot " "then link the resulting object files." msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -c hello.cc @r{(succeeds, even for C++)}\n" "$ gcc hello.o\n" "hello.o: In function `main':\n" "hello.o(.text+0x1b): undefined reference to `std::cout'\n" msgstr "" #. type: Plain text msgid "" "To avoid this problem, use @code{g++} consistently for C++ programs and " "@code{gcc} for C programs." msgstr "" #. type: Plain text msgid "" "Most GCC options can be used for both C and C++ programs, but there are also " "a few options which are specific to each language. This section describes " "some of the additional options, and enhancements to existing options, that " "are available in @command{g++}." msgstr "" #. type: item #, no-wrap msgid "@option{-Wall} and @option{-W}" msgstr "" #. type: table msgid "" "When compiling with @code{g++}, the options @option{-Wall} and @option{-W} " "include extra warnings specific to C++ (the warnings relate to member " "functions and virtual classes). The use of these options is always " "recommended while developing a program." msgstr "" #. type: option{#1} #, no-wrap msgid "-fno-default-inline" msgstr "" #. type: cindex #, no-wrap msgid "@option{-fno-default-inline} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{fno-default-inline} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{no-default-inline} option" msgstr "" #. type: table msgid "" "This option disables the default inlining of member functions defined in the " "bodies of C++ classes. GCC normally inlines all such functions when " "optimization is turned on, even if they do not explicitly use the " "@code{inline} keyword. Select this option if you prefer to control inlining " "yourself, or want to set a breakpoint on member functions that would " "otherwise be inlined (since it is not possible to set a breakpoint on an " "inlined function)." msgstr "" #. type: option{#1} #, no-wrap msgid "-Weffc++" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Weffc++} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{Weffc++} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{effc++} warning option" msgstr "" #. type: table msgid "" "This option warns about C++ code which breaks some of the programming " "guidelines given in the books ``@cite{Effective C++}'' and ``@cite{More " "Effective C++}'' by Scott Meyers. For example, a warning will be given if a " "class which uses dynamically allocated memory does not define a copy " "constructor and an assignment operator. Note that the standard library " "header files do not follow these guidelines, so you may wish to use this " "option as an occasional test for possible problems in your own code rather " "than compiling with it all the time." msgstr "" #. type: option{#1} #, no-wrap msgid "-Wold-style-cast" msgstr "" #. type: cindex #, no-wrap msgid "@option{-Wold-style-cast} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{Wold-style-cast} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{old-style-cast} warning option" msgstr "" #. type: table msgid "" "This option highlights any uses of C-style casts in C++ programs. The C++ " "language provides the keywords @code{static_cast}, @code{dynamic_cast}, " "@code{reinterpret_cast} and @code{const_cast} for handling casts and these " "are often preferable (although C-style casts are still allowed)." msgstr "" #. type: cindex #: #, no-wrap msgid "C++, standard library" msgstr "" #. type: cindex #, no-wrap msgid "standard library, C++" msgstr "" #. type: cindex #, no-wrap msgid "library, C++ standard library" msgstr "" #. type: Plain text msgid "" "An implementation of the C++ standard library is provided as a part of GCC. " "The following program uses the standard library @code{string} class to " "reimplement the @dfn{Hello World} program:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude hellostr.cc\n" msgstr "" #. type: Plain text msgid "The program can be compiled and run using the same commands as above:" msgstr "" #. type: example #, no-wrap msgid "" "$ g++ -Wall hellostr.cc\n" "$ ./a.out \n" "Hello, World!\n" msgstr "" #. type: cindex #, no-wrap msgid "C++, namespace @code{std}" msgstr "" #. type: cindex #, no-wrap msgid "namespace @code{std} in C++" msgstr "" #. type: cindex #, no-wrap msgid "@code{std} namespace in C++" msgstr "" #. type: cindex #, no-wrap msgid "header file, without @code{.h} extension for C++" msgstr "" #. type: Plain text msgid "" "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 @code{std} namespace, so the directive @code{using " "namespace std} is needed to access them, unless the prefix @code{std::} is " "used throughout (as in the previous section)." msgstr "" #. type: cindex #, no-wrap msgid "templates, in C++" msgstr "" #. type: cindex #, no-wrap msgid "generic programming, in C++" msgstr "" #. type: cindex #, no-wrap msgid "C++, templates" msgstr "" #. type: Plain text msgid "" "Templates provide the ability to define C++ classes which support " "@dfn{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 @code{float} or @code{int}, the " "corresponding template code is compiled with that type substituted in the " "appropriate places." msgstr "" #. type: subsection #: #, no-wrap msgid "Using C++ standard library templates" msgstr "" #. type: subsection #: #, no-wrap msgid "Providing your own templates" msgstr "" #. type: subsection #: #, no-wrap msgid "Explicit template instantiation" msgstr "" #. type: node #: #, no-wrap msgid "The export keyword" msgstr "" #. type: cindex #, no-wrap msgid "Standard Template Library (STL)" msgstr "" #. type: cindex #, no-wrap msgid "C++, standard library templates" msgstr "" #. type: Plain text msgid "" "The C++ standard library @file{libstdc++} supplied with GCC provides a wide " "range of generic container classes such as lists and queues, in addition to " "generic algorithms such as sorting. These classes were originally part of " "the Standard Template Library (STL), which was a separate package, but are " "now included in the C++ standard library itself." msgstr "" #. type: Plain text msgid "" "The following program demonstrates the use of the template library by " "creating a list of strings with the template @code{list}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude string.cc\n" msgstr "" #. type: Plain text msgid "" "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:" msgstr "" #. type: example #, no-wrap msgid "" "$ g++ -Wall string.cc\n" "$ ./a.out \n" "List size = 2\n" msgstr "" #. type: cindex #, no-wrap msgid "@code{libstdc++}, C++ standard library" msgstr "" #. type: Plain text msgid "" "Note that the executables created by @code{g++} using the C++ standard " "library will be linked to the shared library @file{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 @file{libstdc++}, or link your program statically using the " "command-line option @option{-static}." msgstr "" #. type: cindex #, no-wrap msgid "instantiation, of templates in C++" msgstr "" #. type: cindex #, no-wrap msgid "C++, instantiation of templates" msgstr "" #. type: cindex #, no-wrap msgid "inclusion compilation model, in C++" msgstr "" #. type: cindex #, no-wrap msgid "compilation, model for templates" msgstr "" #. type: cindex #, no-wrap msgid "templates, inclusion compilation model" msgstr "" #. type: Plain text msgid "" "In addition to the template classes provided by the C++ standard library you " "can define your own templates. The recommended way to use templates with " "@code{g++} is to follow the @dfn{inclusion compilation model}, where " "template definitions are placed in header files. This is the method used by " "the C++ standard library supplied with GCC itself. The header files can " "then be included with @samp{#include} in each source file where they are " "needed." msgstr "" #. type: cindex #, no-wrap msgid "circular buffer, template example" msgstr "" #. type: cindex #, no-wrap msgid "buffer, template example" msgstr "" #. type: Plain text msgid "" "For example, the following template file creates a simple @code{Buffer} " "class which represents a circular buffer holding objects of type @code{T}." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude buffer.h\n" msgstr "" #. type: cindex #, no-wrap msgid "include guards, in header file" msgstr "" #. type: cindex #, no-wrap msgid "header file, with include guards" msgstr "" #. type: Plain text msgid "" "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 @dfn{include guards}, which test for the presence of the macro " "@w{@code{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." msgstr "" #. type: Plain text msgid "" "The program below uses the templated @code{Buffer} class to create a buffer " "of size 10, storing the floating point values @math{0.25} and @math{1.25} in " "the buffer:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude tprog.cc\n" msgstr "" #. type: Plain text msgid "" "The definitions for the template class and its functions are included in the " "source file for the program with @samp{#include \"buffer.h\"} before they " "are used. The program can then be compiled using the following command " "line:" msgstr "" #. type: example #, no-wrap msgid "" "$ g++ -Wall tprog.cc\n" "$ ./a.out \n" "stored value = 1.25\n" msgstr "" #. type: Plain text msgid "" "At the points where the template functions are used in the source file, " "@code{g++} compiles the appropriate definition from the header file and " "places the compiled function in the corresponding object file." msgstr "" #. type: cindex #, no-wrap msgid "multiply-defined symbol error, with C++" msgstr "" #. type: cindex #, no-wrap msgid "linker, GNU compared with other linkers" msgstr "" #. type: Plain text msgid "" "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 ``@dfn{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." msgstr "" #. type: cindex #, no-wrap msgid "templates, explicit instantiation" msgstr "" #. type: cindex #, no-wrap msgid "instantiation, explicit vs implicit in C++" msgstr "" #. type: cindex #, no-wrap msgid "explicit instantiation of templates" msgstr "" #. type: cindex #, no-wrap msgid "@option{-fno-implicit-templates} option, disable implicit instantiation" msgstr "" #. type: cindex #, no-wrap msgid "@option{fno-implicit-templates} option, disable implicit instantiation" msgstr "" #. type: Plain text msgid "" "To achieve complete control over the compilation of templates with " "@code{g++} it is possible to require explicit instantiation of each " "occurrence of a template, using the option " "@option{-fno-implicit-templates}. This method is not needed when using the " "GNU Linker---it is an alternative provided for systems with linkers which " "cannot eliminate duplicate definitions of template functions in object " "files." msgstr "" #. type: Plain text msgid "" "In this approach, template functions are no longer compiled at the point " "where they are used, as a result of the @option{-fno-implicit-templates} " "option. Instead, the compiler looks for an explicit instantiation of the " "template using the @code{template} keyword with a specific type to force its " "compilation (this is a GNU extension to the standard behavior). These " "instantiations are typically placed in a separate source file, which is then " "compiled to make an object file containing all the template functions " "required by a program. This ensures that each template appears in only one " "object file, and is compatible with linkers which cannot eliminate duplicate " "definitions in object files." msgstr "" #. type: Plain text msgid "" "For example, the following file @file{templates.cc} contains an explicit " "instantiation of the @code{Buffer} class used by the program " "@file{tprog.cc} given above:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude templates.cc\n" msgstr "" #. type: Plain text msgid "" "The whole program can be compiled and linked using explicit instantiation " "with the following commands:" msgstr "" #. type: example #, no-wrap msgid "" "$ g++ -Wall -fno-implicit-templates -c tprog.cc\n" "$ g++ -Wall -fno-implicit-templates -c templates.cc\n" "$ g++ tprog.o templates.o\n" "$ ./a.out \n" "stored value = 1.25\n" msgstr "" #. type: Plain text msgid "" "The object code for all the template functions is contained in the file " "@file{templates.o}. There is no object code for template functions in " "@file{tprog.o} when it is compiled with the @option{-fno-implicit-templates} " "option." msgstr "" #. type: Plain text msgid "" "If the program is modified to use additional types, then further explicit " "instantiations can be added to the file @file{templates.cc}. For example, " "the following code adds instantiations for Buffer objects containing " "@code{double} and @code{int} values:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude templates2.cc\n" msgstr "" #. type: cindex #, no-wrap msgid "C++, creating libraries with explicit instantiation" msgstr "" #. type: cindex #, no-wrap msgid "libraries, creating with explicit instantiation in C++" msgstr "" #. type: Plain text msgid "" "The disadvantage of explicit instantiation is that it is necessary to know " "which template types are needed by the program. For a complicated program " "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." msgstr "" #. type: Plain text msgid "" "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 @file{templates.cc} " "above). For example, the object file created from the template " "instantiations above contains the machine code needed for Buffer classes " "with @samp{float}, @samp{double} and @samp{int} types, and could be " "distributed in a library." msgstr "" #. type: subsection #, no-wrap msgid "The @code{export} keyword" msgstr "" #. type: cindex #, no-wrap msgid "@code{export} keyword, not supported in GCC" msgstr "" #. type: cindex #, no-wrap msgid "templates, @code{export} keyword" msgstr "" #. type: Plain text msgid "" "At the time of writing, GCC does not support the new C++ @code{export} " "keyword (GCC 3.4.4)." msgstr "" #. type: Plain text msgid "" "This keyword was proposed as a way of separating the interface of templates " "from their implementation. However it adds its own complexity to the " "linking process, which can detract from any advantages in practice." msgstr "" #. type: Plain text msgid "" "The @code{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." msgstr "" #. type: cindex #, no-wrap msgid "platform-specific options" msgstr "" #. type: cindex #, no-wrap msgid "machine-specific options" msgstr "" #. type: cindex #, no-wrap msgid "options, platform-specific" msgstr "" #. type: cindex #, no-wrap msgid "@option{-m} option, platform-specific settings" msgstr "" #. type: cindex #, no-wrap msgid "@option{m} option, platform-specific settings" msgstr "" #. type: Plain text msgid "" "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 @option{-m} option on the command line, and work with all " "the GCC language frontends, such as @code{gcc} and @code{g++}." msgstr "" #. type: Plain text msgid "" "The following sections describe some of the options available for common " "platforms. A complete list of all platform-specific options can be found in " "the GCC Reference Manual, ``@cite{Using GCC}'' (@pxref{Further reading}). " "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." msgstr "" #. type: section #: #, no-wrap msgid "Intel and AMD x86 options" msgstr "" #. type: section #: #, no-wrap msgid "DEC Alpha options" msgstr "" #. type: section #: #, no-wrap msgid "SPARC options" msgstr "" #. type: section #: #, no-wrap msgid "POWER/PowerPC options" msgstr "" #. type: section #: #, no-wrap msgid "Multi-architecture support" msgstr "" #. type: section #: #, no-wrap msgid "Floating-point issues" msgstr "" #. type: section #: #, no-wrap msgid "Portability of signed and unsigned types" msgstr "" #. type: cindex #, no-wrap msgid "Intel x86, platform-specific options" msgstr "" #. type: cindex #, no-wrap msgid "AMD x86, platform-specific options" msgstr "" #. type: cindex #, no-wrap msgid "x86, platform-specific options" msgstr "" #. type: Plain text msgid "" "The features of the widely used Intel and AMD x86 families of processors " "(386, 486, Pentium, etc) can be controlled with GCC platform-specific " "options." msgstr "" #. type: Plain text msgid "" "On these platforms, GCC produces executable code which is compatible with " "all the processors in the x86 family by default---going all the way back to " "the 386. However, it is also possible to compile for a specific processor " "to obtain better performance.@footnote{Also referred to as ``targeting'' a " "specific processor.}" msgstr "" #. type: cindex #, no-wrap msgid "Pentium, platform-specific options" msgstr "" #. type: cindex #, no-wrap msgid "Athlon, platform-specific options" msgstr "" #. type: Plain text msgid "" "For example, recent versions of GCC have specific support for newer " "processors such as the Pentium 4 and AMD Athlon. These can be selected with " "the following option for the Pentium 4," msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -march=pentium4 hello.c\n" msgstr "" #. type: cindex #, no-wrap msgid "@option{-march} option, compile for specific CPU" msgstr "" #. type: cindex #, no-wrap msgid "@option{march} option, compile for specific CPU" msgstr "" #. type: Plain text msgid "and for the Athlon:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -march=athlon hello.c\n" msgstr "" #. type: Plain text msgid "" "A complete list of supported CPU types can be found in the GCC Reference " "Manual." msgstr "" #. type: Plain text msgid "" "Code produced with a specific @option{-march=@var{CPU}} option will be " "faster but will not run on other processors in the x86 family. If you plan " "to distribute executable files for general use on Intel and AMD processors " "they should be compiled without any @option{-march} options." msgstr "" #. type: cindex #, no-wrap msgid "@option{-mtune} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{mtune} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{tune} machine-specific option" msgstr "" #. type: Plain text msgid "" "As an alternative, the @option{-mcpu=@var{CPU}} option provides a compromise " "between speed and portability---it generates code that is tuned for a " "specific processor, in terms of instruction scheduling, but does not use any " "instructions which are not available on other CPUs in the x86 " "family.@footnote{In recent versions of GCC this option has been renamed to " "@option{-mtune}. The older form @option{-mcpu} will continue to work.} The " "resulting code will be compatible with all the CPUs, and have a speed " "advantage on the CPU specified by @option{-mcpu}. The executables generated " "by @option{-mcpu} cannot achieve the same performance as @option{-march}, " "but may be more convenient in practice." msgstr "" #. type: subsection #: #, no-wrap msgid "x86 extensions" msgstr "" #. type: subsection #: #, no-wrap msgid "x86 64-bit processors" msgstr "" #. type: cindex #, no-wrap msgid "SSE extensions" msgstr "" #. type: cindex #, no-wrap msgid "MMX extensions" msgstr "" #. type: cindex #: #, no-wrap msgid "illegal instruction error" msgstr "" #. type: cindex #, no-wrap msgid "@option{-msse} and related options" msgstr "" #. type: cindex #, no-wrap msgid "@option{msse} and related options" msgstr "" #. type: Plain text msgid "" "GCC can take advantage of the additional instructions in the MMX, SSE, SSE2, " "SSE3 and 3dnow extensions of recent Intel and AMD processors. The options " "@option{-mmmx}, @option{-msse}, @option{-msse2}, @option{-msse3} and " "@option{-m3dnow} enable the use of these extra instructions, allowing " "multiple words of data to be processed in parallel. The resulting " "executables will only run on processors supporting the appropriate " "extensions---on other systems they will crash with an @code{Illegal " "instruction} error (or similar).@footnote{On GNU/Linux systems, the command " "@code{cat /proc/cpuinfo} will display information about the CPU.}" msgstr "" #. type: cindex #, no-wrap msgid "floating point arithmetic, with SSE extensions" msgstr "" #. type: cindex #, no-wrap msgid "@option{-mfpmath} option, for floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "@option{mfpmath} option, for floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "@option{fpmath} option, for floating-point arithmetic" msgstr "" #. type: Plain text msgid "" "The option @option{-mfpmath=sse} instructs GCC to use the SSE extensions for " "floating-point arithmetic where possible. For this option to take effect, " "the SSE or SSE2 extensions must first be enabled with @option{-msse} or " "@option{-msse2}." msgstr "" #. type: Plain text msgid "" "Note that the plain SSE extensions only support single precision " "operations---double precision arithmetic is part of SSE2. Since most C and " "C++ programs declare floating-point variables as @code{double} rather than " "@code{float}, the combined options @code{-msse2 -mfpmath=sse} are usually " "needed. On 64-bit processors these options are enabled by default." msgstr "" #. type: cindex #, no-wrap msgid "64-bit processor-specific options, AMD64 and Intel" msgstr "" #. type: cindex #, no-wrap msgid "AMD64, 64-bit processor specific options" msgstr "" #. type: Plain text msgid "" "AMD has enhanced the 32-bit x86 instruction set to a 64-bit instruction set " "called x86-64, which is implemented in their AMD64 " "processors.@footnote{Intel has added support for this instruction set as the " "``Intel 64-bit enhancements'' on their Xeon CPUs.} On AMD64 systems GCC " "generates 64-bit code by default. The option @option{-m32} allows 32-bit " "code to be generated instead." msgstr "" #. type: cindex #, no-wrap msgid "@option{-mcmodel} option, for AMD64" msgstr "" #. type: cindex #, no-wrap msgid "@option{mcmodel} option, for AMD64" msgstr "" #. type: Plain text msgid "" "The AMD64 processor has several different memory models for programs running " "in 64-bit mode. The default model is the small code model, which allows " "code and data up to 2@dmn{GB} in size. The medium code model allows " "unlimited data sizes and can be selected with @option{-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@dmn{GB} are not encountered " "in practice." msgstr "" #. type: cindex #, no-wrap msgid "red-zone, on AMD64" msgstr "" #. type: cindex #, no-wrap msgid "kernel mode, on AMD64" msgstr "" #. type: Plain text msgid "" "A special kernel code model @option{-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 @option{-mcmodel=kernel -mno-red-zone}." msgstr "" #. type: cindex #, no-wrap msgid "Alpha, platform-specific options" msgstr "" #. type: cindex #, no-wrap msgid "DEC Alpha, platform-specific options" msgstr "" #. type: Plain text msgid "" "The DEC Alpha processor has default settings which maximize floating-point " "performance, at the expense of full support for IEEE arithmetic features." msgstr "" #. type: cindex #, no-wrap msgid "IEEE options, on DEC Alpha" msgstr "" #. type: cindex #, no-wrap msgid "@option{-mieee} option, floating-point support on DEC Alpha" msgstr "" #. type: cindex #, no-wrap msgid "@option{mieee} option, floating-point support on DEC Alpha" msgstr "" #. type: cindex #, no-wrap msgid "NaN, not a number, on DEC Alpha" msgstr "" #. type: cindex #, no-wrap msgid "Inf, infinity, on DEC Alpha" msgstr "" #. type: cindex #, no-wrap msgid "denormalized numbers, on DEC Alpha" msgstr "" #. type: cindex #, no-wrap msgid "underflow, on DEC Alpha" msgstr "" #. type: cindex #, no-wrap msgid "gradual underflow, on DEC Alpha" msgstr "" #. type: cindex #, no-wrap msgid "soft underflow, on DEC Alpha" msgstr "" #. type: cindex #, no-wrap msgid "zero, from underflow on DEC Alpha" msgstr "" #. type: Plain text msgid "" "Support for infinity arithmetic and gradual underflow (denormalized numbers) " "is not enabled in the default configuration on the DEC Alpha " "processor. Operations which produce infinities or underflows will generate " "floating-point exceptions (also known as @dfn{traps}), and cause the program " "to terminate, unless the operating system catches and handles the exceptions " "(which is, in general, inefficient). The IEEE standard specifies that these " "operations should produce special results to represent the quantities in the " "IEEE numeric format." msgstr "" #. type: Plain text msgid "" "In most cases the DEC Alpha default behavior is acceptable, since the " "majority of programs do not produce infinities or underflows. For " "applications which require these features, GCC provides the option " "@option{-mieee} to enable full support for IEEE arithmetic." msgstr "" #. type: Plain text msgid "" "To demonstrate the difference between the two cases the following program " "divides 1 by 0:" msgstr "" #. type: cindex #, no-wrap msgid "division by zero" msgstr "" #. type: cindex #, no-wrap msgid "zero, division by" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude alpha.c\n" msgstr "" #. type: Plain text msgid "" "In IEEE arithmetic the result of 1/0 is @code{inf} (@dfn{Infinity}). If the " "program is compiled for the Alpha processor with the default settings it " "generates an exception, which terminates the program:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall alpha.c\n" "$ ./a.out\n" "Floating point exception @r{(on an Alpha processor)}\n" msgstr "" #. type: cindex #, no-wrap msgid "floating point exception, on DEC Alpha" msgstr "" #. type: Plain text msgid "" "Using the @option{-mieee} option ensures full IEEE compliance -- the " "division 1/0 correctly produces the result @code{inf} and the program " "continues executing successfully:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -mieee alpha.c\n" "$ ./a.out \n" "x/y = inf\n" msgstr "" #. type: Plain text msgid "" "Note that programs which generate floating-point exceptions run more slowly " "when compiled with @option{-mieee}, because the exceptions are handled in " "software rather than hardware." msgstr "" #. type: cindex #, no-wrap msgid "Sun SPARC, platform-specific options" msgstr "" #. type: cindex #, no-wrap msgid "SPARC, platform-specific options" msgstr "" #. type: cindex #, no-wrap msgid "@option{-mcpu} option, compile for specific CPU" msgstr "" #. type: cindex #, no-wrap msgid "@option{mcpu} option, compile for specific CPU" msgstr "" #. type: Plain text msgid "" "On the SPARC range of processors the @option{-mcpu=@var{CPU}} option " "generates processor-specific code. The valid options for @code{@var{CPU}} " "are @code{v7}, @code{v8} (SuperSPARC), @code{Sparclite}, @code{Sparclet} and " "@code{v9} (UltraSPARC). Code produced with a specific @option{-mcpu} option " "will not run on other processors in the SPARC family, except where supported " "by the backwards-compatibility of the processor itself." msgstr "" #. type: cindex #, no-wrap msgid "UltraSPARC, 32-bit mode vs 64-bit mode," msgstr "" #. type: cindex #, no-wrap msgid "word-size, on UltraSPARC" msgstr "" #. type: cindex #, no-wrap msgid "bits, 32 vs 64 on UltraSPARC" msgstr "" #. type: cindex #, no-wrap msgid "" "@option{-m32} and @option{-m64} options, compile for 32 or 64-bit " "environment" msgstr "" #. type: cindex #, no-wrap msgid "@option{m32} and @option{m64} options, compile for 32 or 64-bit environment" msgstr "" #. type: Plain text msgid "" "On 64-bit UltraSPARC systems the options @option{-m32} and @option{-m64} " "control code generation for 32-bit or 64-bit environments. The 32-bit " "environment selected by @option{-m32} uses @code{int}, @code{long} and " "pointer types with a size of 32 bits. The 64-bit environment selected by " "@option{-m64} uses a 32-bit @code{int} type and 64-bit @code{long} and " "pointer types." msgstr "" #. type: cindex #, no-wrap msgid "PowerPC and POWER, platform-specific options" msgstr "" #. type: cindex #, no-wrap msgid "AIX, platform-specific options" msgstr "" #. type: Plain text msgid "" "On systems using the POWER/PowerPC family of processors the option " "@option{-mcpu=@var{CPU}} selects code generation for specific CPU models. " "The possible values of @code{@var{CPU}} include @samp{power}, @samp{power2}, " "@samp{powerpc}, @samp{powerpc64} and @samp{common}, in addition to other " "more specific model numbers. Code generated with the option " "@option{-mcpu=common} will run on any of the processors." msgstr "" #. type: cindex #, no-wrap msgid "Altivec, on PowerPC" msgstr "" #. type: cindex #, no-wrap msgid "@option{-maltivec} option, enables use of Altivec processor on PowerPC" msgstr "" #. type: cindex #, no-wrap msgid "@option{maltivec} option, enables use of Altivec processor on PowerPC" msgstr "" #. type: Plain text msgid "" "The option @option{-maltivec} enables use of the Altivec vector processing " "instructions, if the appropriate hardware support is available." msgstr "" #. type: cindex #, no-wrap msgid "multiply and add instruction" msgstr "" #. type: cindex #, no-wrap msgid "fused multiply and add instruction" msgstr "" #. type: cindex #, no-wrap msgid "combined multiply and add instruction" msgstr "" #. type: cindex #, no-wrap msgid "@option{-mno-fused-madd} option, on PowerPC" msgstr "" #. type: cindex #, no-wrap msgid "@option{mno-fused-madd} option, on PowerPC" msgstr "" #. type: Plain text msgid "" "The POWER/PowerPC processors include a combined ``multiply and add'' " "instruction @math{a * x + b}, which performs the two operations " "simultaneously for speed---this is referred to as a @dfn{fused} multiply and " "add, and is used by GCC by default. Due to differences in the way " "intermediate values are rounded, the result of a fused instruction may not " "be exactly the same as performing the two operations separately. In cases " "where strict IEEE arithmetic is required, the use of the combined " "instructions can be disabled with the option @option{-mno-fused-madd}." msgstr "" #. type: cindex #, no-wrap msgid "TOC overflow error, on AIX" msgstr "" #. type: cindex #, no-wrap msgid "table of contents, overflow error on AIX" msgstr "" #. type: cindex #, no-wrap msgid "overflow error, for TOC on AIX" msgstr "" #. type: cindex #, no-wrap msgid "AIX, TOC overflow error" msgstr "" #. type: cindex #, no-wrap msgid "@option{-mminimal-toc} option, on AIX" msgstr "" #. type: cindex #, no-wrap msgid "@option{mminimal-toc} option, on AIX" msgstr "" #. type: Plain text msgid "" "On AIX systems, the option @option{-mminimal-toc} decreases the number of " "entries GCC puts in the global @dfn{table of contents} (TOC) in executables, " "to avoid ``TOC overflow'' errors at link time." msgstr "" #. type: cindex #, no-wrap msgid "@option{-mxl-call} option, compatibility with IBM XL compilers on AIX" msgstr "" #. type: cindex #, no-wrap msgid "@option{mxl-call} option, compatibility with IBM XL compilers on AIX" msgstr "" #. type: cindex #, no-wrap msgid "IBM XL compilers, compatibility on AIX" msgstr "" #. type: cindex #, no-wrap msgid "XL compilers, compatibility on AIX" msgstr "" #. type: cindex #, no-wrap msgid "AIX, compatibility with IBM XL compilers" msgstr "" #. type: Plain text msgid "" "The option @option{-mxl-call} makes the linking of object files from GCC " "compatible with those from IBM's XL compilers." msgstr "" #. type: cindex #, no-wrap msgid "@option{-pthread} option, on AIX" msgstr "" #. type: cindex #, no-wrap msgid "@option{pthread} option, on AIX" msgstr "" #. type: cindex #, no-wrap msgid "threads, on AIX" msgstr "" #. type: Plain text msgid "" "For applications using POSIX threads, AIX always requires the option " "@option{-pthread} when compiling, even when the program will only run in " "single-threaded mode." msgstr "" #. type: cindex #, no-wrap msgid "multi-architecture support, discussion of" msgstr "" #. type: cindex #, no-wrap msgid "MIPS64, multi-architecture support" msgstr "" #. type: cindex #, no-wrap msgid "Sparc64, multi-architecture support" msgstr "" #. type: cindex #, no-wrap msgid "PowerPC64, multi-architecture support" msgstr "" #. type: cindex #, no-wrap msgid "ARM, multi-architecture support" msgstr "" #. type: cindex #, no-wrap msgid "Thumb, alternative code format on ARM" msgstr "" #. type: Plain text msgid "" "A number of platforms can execute code for more than one architecture. For " "example, 64-bit platforms such as AMD64, MIPS64, Sparc64, and PowerPC64 " "support the execution of both 32-bit and 64-bit code. Similarly, ARM " "processors support both ARM code and a more compact code called ``Thumb''. " "GCC can be built to support multiple architectures on these platforms. By " "default, the compiler will generate 64-bit object files, but giving the " "@option{-m32} option will generate a 32-bit object file for the " "corresponding architecture.@footnote{The options @option{-maix64} and " "@option{-maix32} are used on AIX.}" msgstr "" #. type: cindex #, no-wrap msgid "Itanium, multi-architecture support" msgstr "" #. type: Plain text msgid "" "Note that support for multiple architectures depends on the corresponding " "libraries being available. On 64-bit platforms supporting both 64 and " "32-bit executables, the 64-bit libraries are often placed in @file{lib64} " "directories instead of @file{lib} directories, e.g. in @file{/usr/lib64} and " "@file{/lib64}. The 32-bit libraries are then found in the default " "@file{lib} directories as on other platforms. This allows both a 32-bit and " "a 64-bit library with the same name to exist on the same system. Other " "systems, such as the IA64/Itanium, use the directories @file{/usr/lib} and " "@file{/lib} for 64-bit libraries. GCC knows about these paths and uses the " "appropriate path when compiling 64-bit or 32-bit code." msgstr "" #. type: cindex #, no-wrap msgid "floating point, portability problems" msgstr "" #. type: cindex #, no-wrap msgid "arithmetic, floating-point" msgstr "" #. type: cindex #, no-wrap msgid "numerical differences" msgstr "" #. type: tex #, no-wrap msgid "$\\a\\ \\\\times 10^{ \\b\\ }$@comment\n" msgstr "" #. type: ifnottex msgid "\\a\\*10^\\b\\" msgstr "" #. type: tex #, no-wrap msgid "$\\a\\^{ \\b\\ }$@comment\n" msgstr "" #. type: ifnottex msgid "\\a\\^\\b\\" msgstr "" #. type: tex #, no-wrap msgid "$\\a\\^{\\\\pm \\b\\ }$@comment\n" msgstr "" #. type: ifnottex msgid "\\a\\^(+/-\\b\\)" msgstr "" #. type: cindex #, no-wrap msgid "IEEE arithmetic" msgstr "" #. type: Plain text msgid "" "The IEEE-754 standard defines the bit-level behavior of floating-point " "arithmetic operations on all modern processors. This allows numerical " "programs to be ported between different platforms with identical results, in " "principle. In practice, there are often minor variations caused by " "differences in the order of operations (depending on the compiler and " "optimization level) but these are generally not significant." msgstr "" #. type: cindex #, no-wrap msgid "x86, floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "Motorola 680x0, floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "native double-precision processors" msgstr "" #. type: cindex #, no-wrap msgid "double precision" msgstr "" #. type: cindex #, no-wrap msgid "extended precision, x86 processors" msgstr "" #. type: Plain text msgid "" "However, more noticeable discrepancies can be seen when porting numerical " "programs between x86 systems and other platforms, because the the x87 " "floating point unit (FPU) on x86 processors computes results using extended " "precision internally (the values being converted to double precision only " "when they are stored to memory). In contrast, processors such as SPARC, " "PA-RISC, Alpha, MIPS and POWER/PowerPC work with native double-precision " "values throughout.@footnote{Motorola 68k processors also use extended " "precision registers, like the x86.} The differences between these " "implementations lead to changes in rounding and underflow/overflow behavior, " "because intermediate values have a greater relative precision and exponent " "range when computed in extended precision.@footnote{For quantities held in " "the x87 extended-precision registers the relative precision is " "@scinum{5.42,-20} and the exponent range is @scirange{10,4932}. Standard " "double precision values have a relative precision of @scinum{2.22,-16} and " "an exponent range of @scirange{10,308}.} In particular, comparisons " "involving extended precision values may fail where the equivalent double " "precision values would compare equal." msgstr "" #. type: cindex #, no-wrap msgid "rounding, floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "overflow, floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "underflow, floating-point arithmetic" msgstr "" #. type: Plain text msgid "" "To avoid these incompatibilities, the x87 FPU also offers a hardware " "double-precision rounding mode. In this mode the results of each " "extended-precision floating-point operation are rounded to double precision " "in the floating-point registers by the FPU. It is important to note that " "the rounding only affects the precision, not the exponent range, so the " "result is a hybrid double-precision format with an extended range of " "exponents." msgstr "" #. type: cindex #, no-wrap msgid "FreeBSD, floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "NetBSD, floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "OpenBSD, floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "GNU/Linux, floating-point arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "Linux kernel, floating-point" msgstr "" #. type: cindex #, no-wrap msgid "@code{fldcw} set floating point mode" msgstr "" #. type: cindex #, no-wrap msgid "machine instruction, @code{asm} keyword" msgstr "" #. type: Plain text msgid "" "On BSD systems such as FreeBSD, NetBSD and OpenBSD, the hardware " "double-precision rounding mode is the default, giving the greatest " "compatibility with native double precision platforms. On x86 GNU/Linux " "systems the default mode is extended precision (with the aim of providing " "increased accuracy). To enable the double-precision rounding mode it is " "necessary to override the default setting on per-process basis using the " "@sc{fldcw} ``floating-point load control-word'' machine " "instruction.@footnote{The operating system saves and restores the control " "word when switching between processes, so that each process maintains its " "own setting.} A simple function which can be called to execute this " "instruction is shown below. It uses the GCC extension keyword @code{asm} to " "insert the specified instruction in the assembly language output:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude setfpu.c\n" msgstr "" #. type: Plain text msgid "" "The appropriate @code{mode} setting for double-precision rounding is " "@code{0x27F}. The mode value also controls the floating-point exception " "handling behavior and rounding-direction (see the Intel and AMD processor " "reference manuals for details)." msgstr "" #. type: cindex #, no-wrap msgid "floating point exception handling" msgstr "" #. type: cindex #, no-wrap msgid "exception handling, floating-point" msgstr "" #. type: Plain text msgid "" "On x86 GNU/Linux, the function above can be called at the start of any " "program to disable excess precision. This will then reproduce the results " "of native double-precision processors, in the absence of underflows and " "overflows." msgstr "" #. type: Plain text msgid "The following program demonstrates the different rounding modes:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude fptest2.c\n" msgstr "" #. type: Plain text msgid "" "On x86 GNU/Linux systems the comparison @code{c == a / b} can produce an " "unexpected result if @code{c} is taken from memory (double precision) while " "@code{a / b} is computed in extended precision, because the fraction 3/7 has " "different representations in double and extended precision." msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall fptest2.c\n" "$ ./a.out \n" "unexpecedt result\n" msgstr "" #. type: Plain text msgid "" "Setting the hardware rounding mode to double precision prevents this from " "happening:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -DDOUBLE fptest2.c\n" "$ ./a.out \n" "comparison succeeds\n" msgstr "" #. type: Plain text msgid "" "Note that the floating-point control word affects the whole environment of " "the process, including any C Library functions that are called. One " "consequence of this is that @code{long double} arithmetic is effectively " "reduced to double precision, since it relies on extended precision " "operations." msgstr "" #. type: cindex #, no-wrap msgid "long double arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "SSE/SSE2 precision" msgstr "" #. type: Plain text msgid "" "The floating point control word only affects the behavior of the x87 FPU. " "Floating point operations computed with SSE and SSE2 instructions are always " "carried out in native double precision. Thus, the combined options" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -msse2 -mfpmath=sse ...\n" msgstr "" #. type: Plain text msgid "" "are often sufficient to remove the effects of extended-precision. However, " "some operations (such as transcendental functions) are not available in the " "SSE/SSE2 extensions and will still be computed on the x87 FPU." msgstr "" #. type: cindex #, no-wrap msgid "signed @code{char} option" msgstr "" #. type: cindex #, no-wrap msgid "unsigned @code{char} option" msgstr "" #. type: cindex #, no-wrap msgid "@code{char}, portability of signed vs unsigned" msgstr "" #. type: Plain text msgid "" "The C and C++ standards allows the character type @code{char} to be signed " "or unsigned, depending on the platform and compiler. Most systems, " "including x86 GNU/Linux and Microsoft Windows, use signed @code{char}, but " "those based on PowerPC and @sc{arm} processors typically use unsigned " "@code{char}.@footnote{MacOS X (Darwin) on PowerPC uses signed @code{char}, " "for consistency with other Darwin architectures.} This can lead to " "unexpected results when porting programs between platforms which have " "different defaults for the type of @code{char}." msgstr "" #. type: Plain text msgid "" "The following code demonstrates the difference between platforms with signed " "and unsigned @code{char} types:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude signed.c\n" msgstr "" #. type: Plain text msgid "" "With an unsigned @code{char}, the variable @code{c} takes the value 255, but " "with a signed @code{char} it becomes @math{-1}." msgstr "" #. type: Plain text msgid "" "The correct way to manipulate @code{char} variables in C is through the " "portable functions declared in @file{ctype.h}, such as @code{isalpha}, " "@code{isdigit} and @code{isblank}, rather than by their numerical values. " "The behavior of non-portable conditional expressions such as @code{c > 'a'} " "depends on the signedness of the @code{char} type. If the signed or " "unsigned version of @code{char} is explicitly required at certain points in " "a program, it can be specified using the declarations @code{signed char} or " "@code{unsigned char}." msgstr "" #. type: Plain text msgid "" "For existing programs which assume that @code{char} is signed or unsigned, " "GCC provides the options @option{-fsigned-char} and @option{-funsigned-char} " "to set the default type of @code{char}. Using these options, the example " "code above compiles cleanly with @option{-Wall -W} when @code{char} is " "unsigned:" msgstr "" #. type: cindex #, no-wrap msgid "@option{-funsigned-char} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{-fsigned-char} option" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -W -funsigned-char signed.c \n" "$ ./a.out \n" "char is unsigned (c = 255)\n" msgstr "" #. type: Plain text msgid "" "However, when @code{char} is signed the value 255 wraps around to @math{-1}, " "giving a warning when compiled with @option{-Wall -W}:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -W -fsigned-char signed.c \n" "signed.c: In function `main':\n" "signed.c:7: warning: comparison is always false due to \n" " limited range of data type\n" "$ ./a.out \n" "char is signed (c = -1)\n" msgstr "" #. type: Plain text msgid "" "The warning message @cite{``comparison is always true/false due to limited " "range of data type''} is one symptom of code which assumes a definition of " "@code{char} which is different from the actual type." msgstr "" #. type: Plain text msgid "" "The most common problem with code written assuming signed @code{char} types " "occurs with the functions @code{getc}, @code{fgetc} and @code{getchar} " "(which read a character from a file). They have a return type of " "@code{int}, not @code{char}, and this allows them to use the special value " "@math{-1} (defined as @code{EOF}) to indicate an end-of-file error. " "Unfortunately, many programs have been written which incorrectly store this " "return value straight into a @code{char} variable. Here is a typical " "example:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude testgetc.c\n" msgstr "" #. type: Plain text msgid "" "This only works on platforms which default to a signed @code{char} " "type.@footnote{There is also a subtle error even on platforms with signed " "@code{char}---the @sc{ascii} character 255 is spuriously interpreted as an " "end of file condition.} On platforms which use an unsigned @code{char} the " "same code will fail, because the value @math{-1} becomes 255 when stored in " "an @code{unsigned char}. This usually causes an infinite loop because the " "end of the file cannot be recognized.@footnote{If displayed, character code " "255 often appears as @code{@\"y}.} To be portable, the program should test " "the return value as an integer before coercing it to a @code{char}, as " "follows:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude testgetc2.c\n" msgstr "" #. type: cindex #, no-wrap msgid "signed bitfield option" msgstr "" #. type: cindex #, no-wrap msgid "unsigned bitfield option" msgstr "" #. type: cindex #, no-wrap msgid "bitfields, portability of signed vs unsigned" msgstr "" #. type: cindex #, no-wrap msgid "@option{-funsigned-bitfields} option" msgstr "" #. type: cindex #, no-wrap msgid "@option{-fsigned-bitfields} option" msgstr "" #. type: Plain text msgid "" "The same considerations described in this section apply to the definitions " "of bitfields in structs, which can be signed or unsigned by default. In " "GCC, the default type of bitfields can be controlled using the options " "@option{-fsigned-bitfields} and @option{-funsigned-bitfields}." msgstr "" #. type: cindex #, no-wrap msgid "troubleshooting options" msgstr "" #. type: cindex #, no-wrap msgid "help options" msgstr "" #. type: cindex #, no-wrap msgid "command-line help option" msgstr "" #. type: Plain text msgid "" "GCC provides several help and diagnostic options to assist in " "troubleshooting problems with the compilation process. All the options " "described in this chapter work with both @code{gcc} and @code{g++}." msgstr "" #. type: section #: #, no-wrap msgid "Help for command-line options" msgstr "" #. type: section #: #, no-wrap msgid "Version numbers" msgstr "" #. type: section #: #, no-wrap msgid "Verbose compilation" msgstr "" #. type: section #: #, no-wrap msgid "Stopping a program in an infinite loop" msgstr "" #. type: section #: #, no-wrap msgid "Preventing excessive memory usage" msgstr "" #. type: cindex #, no-wrap msgid "@option{--help} option, display command-line options" msgstr "" #. type: Plain text msgid "" "To obtain a brief reminder of various command-line options, GCC provides a " "help option which displays a summary of the top-level GCC command-line " "options:" msgstr "" #. type: example #, no-wrap msgid "$ gcc --help\n" msgstr "" #. type: cindex #, no-wrap msgid "verbose help option" msgstr "" #. type: cindex #, no-wrap msgid "@option{-v} option, verbose compilation" msgstr "" #. type: cindex #, no-wrap msgid "@option{v} option, verbose compilation" msgstr "" #. type: Plain text msgid "" "To display a complete list of options for @code{gcc} and its associated " "programs, such as the GNU Linker and GNU Assembler, use the help option " "above with the verbose (@option{-v}) option:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -v --help\n" msgstr "" #. type: Plain text msgid "" "The complete list of options produced by this command is extremely " "long---you may wish to page through it using the @code{more} command, or " "redirect the output to a file for reference:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -v --help 2>&1 | more\n" msgstr "" #. type: Plain text msgid "You can find the version number of @code{gcc} using the version option:" msgstr "" #. type: cindex #, no-wrap msgid "version number of GCC, displaying" msgstr "" #. type: cindex #, no-wrap msgid "@option{--version} option, display version number" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc --version\n" "gcc (Debian 4.6.1-4) 4.6.1\n" msgstr "" #. type: Plain text msgid "" "The version number is important when investigating compilation problems, " "since older versions of GCC may be missing some features that a program " "uses. The version number has the form @var{major-version.minor-version} or " "@var{major-version.minor-version.micro-version}, where the additional third " "``micro'' version number (as shown above) is used for subsequent bug-fix " "releases in a release series." msgstr "" #. type: cindex #, no-wrap msgid "major version number, of GCC" msgstr "" #. type: cindex #, no-wrap msgid "minor version number, of GCC" msgstr "" #. type: cindex #, no-wrap msgid "patch level, of GCC" msgstr "" #. type: Plain text msgid "More details about the version can be found using @option{-v}:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -v\n" "Using built-in specs.\n" "COLLECT_GCC=gcc\n" "COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/\n" " /i486-linux-gnu/4.6.1/lto-wrapper\n" "Target: i486-linux-gnu\n" "Configured with: ../src/configure -v \n" "--with-pkgversion='Debian 4.6.1-4' \n" "--with-bugurl=file:///usr/share/doc/gcc-4.6/\n" " /README.Bugs \n" "--enable-languages=c,c++,fortran,objc,obj-c++,go \n" "--prefix=/usr --program-suffix=-4.6 \n" "--enable-shared --enable-multiarch \n" "--with-multiarch-defaults=i386-linux-gnu \n" "--enable-linker-build-id --with-system-zlib \n" "--libexecdir=/usr/lib/i386-linux-gnu \n" "--without-included-gettext --enable-threads=posix \n" "--with-gxx-include-dir=/usr/include/c++/4.6 \n" "--libdir=/usr/lib/i386-linux-gnu --enable-nls \n" "--enable-clocale=gnu --enable-libstdcxx-debug \n" "--enable-libstdcxx-time=yes --enable-plugin \n" "--enable-objc-gc --enable-targets=all \n" "--with-arch-32=i586 --with-tune=generic \n" "--enable-checking=release --build=i486-linux-gnu \n" "--host=i486-linux-gnu --target=i486-linux-gnu " "\n" "Thread model: posix\n" "gcc version 4.6.1 (Debian 4.6.1-4) \n" msgstr "" #. type: cindex #, no-wrap msgid "configuration files for GCC" msgstr "" #. type: cindex #, no-wrap msgid "@code{specs} directory, compiler configuration files" msgstr "" #. type: Plain text msgid "" "This includes information on the build flags of the compiler itself and the " "installed configuration file, @file{specs}." msgstr "" #. type: cindex #, no-wrap msgid "verbose compilation, @option{-v} option" msgstr "" #. type: Plain text msgid "" "The @option{-v} option can also be used to display detailed information " "about the exact sequence of commands used to compile and link a program. " "Here is an example which shows the verbose compilation of the @cite{Hello " "World} program:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -v -Wall hello.c Using built-in specs.\n" "COLLECT_GCC=gcc\n" "COLLECT_LTO_WRAPPER=/usr/lib/i386-linux-gnu/gcc/\n" " /i486-linux-gnu/4.6.1/lto-wrapper\n" "Target: i486-linux-gnu \n" "Configured with: ../src/configure\n" "-v --with-pkgversion='Debian 4.6.1-4'\n" "--with-bugurl=file:///usr/share/doc/gcc-4.6/\n" " /README.Bugs\n" "--enable-la nguages=c,c++,fortran,objc,obj-c++,go\n" "--prefix=/usr --program-suffix=-4.6 --enable-shared\n" "--enable-multiarch \n" "--with-multiarch-defaults=i386-linux-gnu \n" "--enable-linker-build-id --with-system-zlib\n" "--libexecdir=/usr/lib/i386-linux-gnu\n" "--without-included-gettext --enable-threads=posix\n" "--with-gxx-include-dir=/usr/include/c++/4.6\n" "--libdir=/usr/lib/i386-linux-gnu --enable-nls\n" "--enable-clocale=gnu --enable-libstdcxx-debug\n" "--enable-libstdcxx-time=yes --enable-plugin\n" "--enable-objc-gc --enable-targets=all\n" "--with-arch-32=i586 --with-tune=generic\n" "--enable-checking =release --build=i486-linux-gnu\n" "--host=i486-linux-gnu --target=i486-linux-gnu \n" "Thread model: posix gcc version 4.6.1 \n" " (Debian 4.6.1-4)\n" "COLLECT_GCC_OPTIONS='-v' '-Wall' '-mtune=generic'\n" "'-march=i586'\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/cc1\n" "-quiet -v hello.c -quiet -dumpbase hello.c\n" "-mtune=generic -march=i586 -auxbase hello -Wall -version\n" "-o /tmp/cchpM0t3.s \n" "GNU C (Debian 4.6.1-4) version 4.6.1\n" "(i486-linux-gnu) compiled by GNU C version 4.6.1, GMP\n" "version 5.0.1, MPFR version 3.0.1-p3, MPC version 0.9\n" "warning: GMP header version 5.0.1 differs from library\n" "version 5.0.2. \n" "GGC heuristics: --param ggc-min-expand=46 \n" "--param ggc-min-heapsize=31802\n" "ignoring nonexistent directory\n" "\"/usr/local/include/i386-linux-gnu\" \n" "ignoring nonexistent directory\n" "\"/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/../\n" " /../../../../i486-linux-gnu/include\"\n" "#include \"...\" search starts here: \n" "#include <...> search starts here:\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/include\n" "/usr/local/include\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/\n" " /include-fixed\n" "/usr/include/i386-linux-gnu /usr/include \n" "End of searchlist. \n" "GNU C (Debian 4.6.1-4) version 4.6.1\n" "(i486-linux-gnu) compiled by GNU C version 4.6.1, GMP\n" "version 5.0.1, MPFR version 3.0.1-p3, MPC version 0.9\n" "warning: GMP header version 5.0.1 differs from library\n" "version 5.0.2. \n" "GGC heuristics: --param ggc-min-expand=46 \n" "--param ggc-min-heapsize=31802\n" "Compiler executable checksum:\n" "2cfae8623c84fd817bfff483158c4341\n" "COLLECT_GCC_OPTIONS='-v' '-Wall' '-mtune=generic'\n" "'-march=i586' as --32 -o /tmp/ccQxW8a5.o /tmp/cchpM0t3.s\n" "COMPILER_PATH=/usr/lib/i386-linux-gnu/gcc/\n" " /i486-linux-gnu/4.6.1/:\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/:\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/:\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/:\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/\n" "LIBRARY_PATH=/usr/lib/i386-linux-gnu/gcc/\n" " /i486-linux-gnu/4.6.1/:\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/\n" " /../../../:\n" "/lib/:/usr/lib/:/usr/lib/i386-linux-gnu/ \n" "COLLECT_GCC_OPTIONS='-v' '-Wall' '-mtune=generic'\n" "'-march=i586'\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/\n" " /collect2\n" "--build-id --no-add-needed --eh-frame-hdr -m elf_i386\n" "--hash-style=both -dynamic -linker /lib/ld-linux.so.2\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/\n" " /../../../crt1.o\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/\n" " /../../../crti.o\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/\n" " /crtbegin.o\n" "-L/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1\n" "-L/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/\n" " /../../.. \n" "-L/usr/lib/i386-linux-gnu/tmp/ccQxW8a5.o \n" "-lgcc --as-needed -lgcc_s --no-as-needed\n" "-lc -l gcc --as-needed -lgcc_s --no-as-needed\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/\n" " /crtend.o\n" "/usr/lib/i386-linux-gnu/gcc/i486-linux-gnu/4.6.1/\n" " /../../../crtn.o \n" msgstr "" #. type: Plain text msgid "" "The output produced by @option{-v} can be useful whenever there is a problem " "with the compilation process itself. It displays the full directory paths " "used to search for header files and libraries, the predefined preprocessor " "symbols, and the object files and libraries used for linking." msgstr "" #. type: cindex #, no-wrap msgid "infinite loop, stopping" msgstr "" #. type: cindex #, no-wrap msgid "control-C, interrupt" msgstr "" #. type: cindex #, no-wrap msgid "SIGINT signal" msgstr "" #. type: cindex #, no-wrap msgid "@code{attach}, debug running program" msgstr "" #. type: Plain text msgid "" "A program which goes into an infinite loop or ``hangs'' can be difficult to " "debug. On most systems a foreground process can be stopped by hitting " "@kbd{Control-C}, which sends it an interrupt signal (@sc{sigint}). However, " "this does not help in debugging the problem---the @sc{sigint} signal " "terminates the process without producing a core dump. A more sophisticated " "approach is to @dfn{attach} to the running process with a debugger and " "inspect it interactively." msgstr "" #. type: Plain text msgid "For example, here is a simple program with an infinite loop:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude loop.c\n" msgstr "" #. type: Plain text msgid "" "In order to attach to the program and debug it, the code should be compiled " "with the debugging option @option{-g}:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -g loop.c\n" "$ ./a.out\n" "@r{(program hangs)}\n" msgstr "" #. type: cindex #, no-wrap msgid "process id, finding" msgstr "" #. type: Plain text msgid "" "Once the executable is running we need to find its process id (@sc{pid}). " "This can be done from another session with the command @code{ps x}:" msgstr "" #. type: example #, no-wrap msgid "" "$ ps x\n" "PID TTY STAT TIME COMMAND\n" "... ..... .. .... \n" "2333 pts/0 R+ 0:16 ./a.out\n" "\n" msgstr "" #. type: Plain text msgid "" "In this case the process id is 2333, and we can now attach to it with " "@code{gdb}. The debugger should be started in the directory containing the " "executable and its source code:@footnote{Alternatively, the appropriate " "paths can be set up in @code{gdb} using the @code{file} and @code{directory} " "commands.}" msgstr "" #. type: example #, no-wrap msgid "" "$ gdb a.out\n" "GNU gdb (GDB) 7.3-debian\n" "...\n" "(gdb) attach 2333\n" "Attaching to program: a.out, process 2333\n" "Reading symbols from\n" "/lib/i386-linux-gnu/i686/cmov/libc.so.6...(no\n" "debugging symbols found)...done.\n" "Loaded symbols for\n" "/lib/i386-linux-gnu/i686/cmov/libc.so.6\n" "Reading symbols from /lib/ld-linux.so.2...(no debugging\n" "symbols found)...done.\n" "Loaded symbols for /lib/ld-linux.so.2\n" "0x080483c5 in main () at loop.c:5\n" "5 while (1) @{ i++; @};\n" "(gdb) \n" msgstr "" #. type: Plain text msgid "" "The output shows the line that was about to execute at the point when the " "debugger attached to the process. The attached program is paused but still " "``live''---it can be examined interactively and continued or terminated " "(with the @code{kill} command) if necessary:" msgstr "" #. type: example #, no-wrap msgid "" "(gdb) print i\n" "$1 = 1960534048\n" "(gdb) kill\n" "Kill the program being debugged? (y or n) y\n" "(gdb) \n" msgstr "" #. type: cindex #, no-wrap msgid "SIGQUIT signal" msgstr "" #. type: Plain text msgid "" "If you want to stop a process immediately and create a core dump, the shell " "command @code{kill -3 @var{pid}} (where @var{pid} is the process id) will " "send it a @sc{sigquit} signal. The @sc{sigquit} signal does trigger a core " "dump, unlike @sc{sigint}. Note that if core dumps were disabled when the " "process was started, no core file will be produced (@pxref{Examining core " "files})." msgstr "" #. type: cindex #, no-wrap msgid "memory usage, limiting" msgstr "" #. type: cindex #, no-wrap msgid "virtual memory usage, limiting" msgstr "" #. type: Plain text msgid "" "Sometimes a programming error will cause a process to allocate huge amounts " "of memory, consuming all the @sc{ram} on a system. To prevent this, the GNU " "Bash command @command{ulimit -v @var{limit}} can be used to restrict the " "amount of virtual memory available to each process. The limit is measured " "in kilobytes and applies to new processes started in the current shell. For " "example," msgstr "" #. type: example #, no-wrap msgid "$ ulimit -v 4096\n" msgstr "" #. type: Plain text msgid "" "will limit subsequent processes to 4 megabytes of virtual memory (4096k). " "By default the limit cannot be increased in the same session once it has " "been applied, so it is best to start a separate shell for reduced " "@code{ulimit} operations. Alternatively, you can set a @dfn{soft limit} " "(which can be undone) with the options @option{-S -v}." msgstr "" #. type: Plain text msgid "" "In addition to preventing run-away processes, limiting the amount of memory " "a program is allowed to allocate also provides a way to test how robustly " "@dfn{out of memory} conditions are handled. An artificially low limit can " "be used to simulate running out of memory---a well-written program should " "not crash in this case." msgstr "" #. type: Plain text msgid "" "The @command{ulimit} command supports other options including @option{-p}, " "which restricts the number of child processes that can be created, and " "@option{-t}, which places a limit on the number of @sc{cpu} seconds that a " "process can run for. The complete list of settings can be shown with the " "command @code{ulimit -a}. To display more information about the " "@code{ulimit} command, type @code{help ulimit} at the Bash prompt." msgstr "" #. type: cindex #, no-wrap msgid "compiler-related tools" msgstr "" #. type: cindex #, no-wrap msgid "tools, compiler-related" msgstr "" #. type: Plain text msgid "" "This chapter describes a number of tools which are useful in combination " "with GCC. These include the GNU archiver @code{ar}, for creating libraries, " "and the GNU profiling and coverage testing programs, @code{gprof} and " "@code{gcov}." msgstr "" #. type: section #: #, no-wrap msgid "Creating a library with the GNU archiver" msgstr "" #. type: node #: #, no-wrap msgid "Using the profiler gprof" msgstr "" #. type: node #: #, no-wrap msgid "Coverage testing with gcov" msgstr "" #. type: cindex #, no-wrap msgid "libraries, creating with @code{ar}" msgstr "" #. type: Plain text msgid "" "The GNU archiver @code{ar} combines a collection of object files into a " "single archive file, also known as a @dfn{library}. An archive file is " "simply a convenient way of distributing a large number of related object " "files together (as described earlier in @ref{Linking with external " "libraries})." msgstr "" #. type: Plain text msgid "" "To demonstrate the use of the GNU archiver we will create a small library " "@file{libhello.a} containing two functions @code{hello} and @code{bye}." msgstr "" #. type: Plain text msgid "" "The first object file will be generated from the source code for the " "@code{hello} function, in the file @file{hello_fn.c} seen earlier:" msgstr "" #. type: Plain text msgid "" "The second object file will be generated from the source file " "@file{bye_fn.c}, which contains the new function @code{bye}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude bye_fn.c\n" msgstr "" #. type: Plain text msgid "" "Both functions use the header file @file{hello.h}, now with a prototype for " "the function @code{bye()}:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude hello.h\n" msgstr "" #. type: Plain text msgid "" "The source code can be compiled to the object files @file{hello_fn.o} and " "@file{bye_fn.o} using the commands:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -c hello_fn.c\n" "$ gcc -Wall -c bye_fn.c\n" msgstr "" #. type: cindex #, no-wrap msgid "@option{cr} option, create/replace archive files" msgstr "" #. type: Plain text msgid "" "These object files can be combined into a static library using the following " "command line:" msgstr "" #. type: example #, no-wrap msgid "$ ar cr libhello.a hello_fn.o bye_fn.o\n" msgstr "" #. type: Plain text msgid "" "The option @option{cr} stands for ``create and replace''.@footnote{Note that " "@code{ar} does not require a prefix @samp{-} for its options.} 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 @file{libhello.a} is the " "name of the library. The remaining arguments are the names of the object " "files to be copied into the library." msgstr "" #. type: cindex #, no-wrap msgid "@option{t} option, archive table of contents" msgstr "" #. type: cindex #, no-wrap msgid "table of contents, in @code{ar} archive" msgstr "" #. type: Plain text msgid "" "The archiver @code{ar} also provides a ``table of contents'' option " "@option{t} to list the object files in an existing library:" msgstr "" #. type: example #, no-wrap msgid "" "$ ar t libhello.a\n" "hello_fn.o\n" "bye_fn.o\n" msgstr "" #. type: Plain text msgid "" "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." msgstr "" #. type: Plain text msgid "We can now write a program using the functions in the newly created library:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude main3.c\n" msgstr "" #. type: Plain text msgid "" "This file can be compiled with the following command line, as described in " "@ref{Linking with external libraries}, assuming the library " "@file{libhello.a} is stored in the current directory:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall main3.c libhello.a -o hello\n" msgstr "" #. type: Plain text msgid "" "The main program is linked against the object files found in the library " "file @file{libhello.a} to produce the final executable." msgstr "" #. type: Plain text msgid "" "The short-cut library linking option @option{-l} can also be used to link " "the program, without needing to specify the full filename of the library " "explicitly:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -L. main3.c -lhello -o hello\n" msgstr "" #. type: Plain text msgid "" "The option @option{-L.} is needed to add the current directory to the " "library search path. The resulting executable can be run as usual:" msgstr "" #. type: example #, no-wrap msgid "" "$ ./hello\n" "Hello, everyone!\n" "Goodbye!\n" msgstr "" #. type: Plain text msgid "" "It displays the output from both the @code{hello} and @code{bye} functions " "defined in the library." msgstr "" #. type: section #, no-wrap msgid "Using the profiler @code{gprof}" msgstr "" #. type: cindex #, no-wrap msgid "profiling, with @code{gprof}" msgstr "" #. type: cindex #, no-wrap msgid "@code{gprof}, GNU Profiler" msgstr "" #. type: Plain text msgid "" "The GNU profiler @code{gprof} is a useful tool for measuring the performance " "of a program---it records the number of calls to each function and the " "amount of time spent there, on a per-function basis. Functions which " "consume a large fraction of the run-time can be identified easily from the " "output of @code{gprof}. Efforts to speed up a program should concentrate " "first on those functions which dominate the total run-time." msgstr "" #. type: cindex #, no-wrap msgid "Collatz sequence" msgstr "" #. type: Plain text msgid "" "We will use @code{gprof} to examine the performance of a small numerical " "program which computes the lengths of sequences occurring in the unsolved " "@cite{Collatz conjecture} in mathematics.@footnote{American Mathematical " "Monthly, Volume 92 (1985), 3--23} The Collatz conjecture involves sequences " "defined by the rule:" msgstr "" #. type: tex #, no-wrap msgid "" "$$\n" "x_{n+1} \\leftarrow \\cases{ x_n / 2 & if $x_n$ is even\\cr\n" " 3 x_n + 1 & if $x_n$ is odd\\cr}\n" "$$\n" msgstr "" #. type: example #, no-wrap msgid "" "x_@{n+1@} <= x_@{n@} / 2 if x_@{n@} is even\n" " 3 x_@{n@} + 1 if x_@{n@} is odd\n" msgstr "" #. type: Plain text msgid "" "The sequence is iterated from an initial value @math{x_0} until it " "terminates with the value 1. According to the conjecture, all sequences do " "terminate eventually---the program below displays the longest sequences as " "@math{x_0} increases. The source file @file{collatz.c} contains three " "functions: @code{main}, @code{nseq} and @code{step}:" msgstr "" #. type: smallexample #, no-wrap msgid "@verbatiminclude collatz.c\n" msgstr "" #. type: cindex #, no-wrap msgid "@option{-pg} option, enable profiling" msgstr "" #. type: cindex #, no-wrap msgid "@option{pg} option, enable profiling" msgstr "" #. type: cindex #, no-wrap msgid "enable profiling, @option{-pg} option" msgstr "" #. type: Plain text msgid "" "To use profiling, the program must be compiled and linked with the " "@option{-pg} profiling option:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall -c -pg collatz.c\n" "$ gcc -Wall -pg collatz.o\n" msgstr "" #. type: cindex #, no-wrap msgid "instrumented executable, for profiling" msgstr "" #. type: Plain text msgid "" "This creates an @dfn{instrumented} executable which contains additional " "instructions that record the time spent in each function." msgstr "" #. type: Plain text msgid "" "If the program consists of more than one source file then the @option{-pg} " "option should be used when compiling each source file, and used again when " "linking the object files to create the final executable (as shown above). " "Forgetting to link with the option @option{-pg} is a common error, which " "prevents profiling from recording any useful information." msgstr "" #. type: Plain text msgid "The executable must be run to create the profiling data:" msgstr "" #. type: example #, no-wrap msgid "" "$ ./a.out\n" "@r{(normal program output is displayed)}\n" msgstr "" #. type: cindex #, no-wrap msgid "@code{gmon.out}, data file for @code{gprof}" msgstr "" #. type: Plain text msgid "" "While running the instrumented executable, profiling data is silently " "written to a file @file{gmon.out} in the current directory. It can be " "analyzed with @code{gprof} by giving the name of the executable as an " "argument:" msgstr "" #. type: example #, no-wrap msgid "" "$ gprof a.out \n" "Flat profile:\n" "Each sample counts as 0.01 seconds.\n" " % cumul. self self total \n" "time seconds seconds calls us/call us/call name \n" "68.59 2.14 2.14 62135400 0.03 0.03 step\n" "31.09 3.11 0.97 499999 1.94 6.22 nseq\n" " 0.32 3.12 0.01 main\n" msgstr "" #. type: Plain text msgid "" "The first column of the data shows that the program spends most of its time " "(almost 70%) in the function @code{step}, and 30% in @code{nseq}. " "Consequently efforts to decrease the run-time of the program should " "concentrate on the former. In comparison, the time spent within the " "@code{main} function itself is completely negligible (less than 1%)." msgstr "" #. type: Plain text msgid "" "The other columns in the output provide information on the total number of " "function calls made, and the time spent in each function. Additional output " "breaking down the run-time further is also produced by @code{gprof} but not " "shown here. Full details can be found in the manual ``@cite{GNU gprof---The " "GNU Profiler}'', by Jay Fenlason and Richard Stallman." msgstr "" #. type: section #, no-wrap msgid "Coverage testing with @code{gcov}" msgstr "" #. type: cindex #, no-wrap msgid "coverage testing, with @code{gcov}" msgstr "" #. type: cindex #, no-wrap msgid "@code{gcov}, GNU coverage testing tool" msgstr "" #. type: Plain text msgid "" "The GNU coverage testing tool @code{gcov} analyses the number of times each " "line of a program is executed during a run. This makes it possible to find " "areas of the code which are not used, or which are not exercised in " "testing. When combined with profiling information from @code{gprof} the " "information from coverage testing allows efforts to speed up a program to be " "concentrated on specific lines of the source code." msgstr "" #. type: Plain text msgid "" "We will use the example program below to demonstrate @code{gcov}. This " "program loops overs the integers 1 to 9 and tests their divisibility with " "the modulus (@code{%}) operator." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude cov.c\n" msgstr "" #. type: Plain text msgid "" "To enable coverage testing the program must be compiled with the following " "options:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -fprofile-arcs -ftest-coverage cov.c\n" msgstr "" #. type: cindex #, no-wrap msgid "@option{-fprofile-arcs} option, instrument branches" msgstr "" #. type: cindex #, no-wrap msgid "@option{fprofile-arcs} option, instrument branches" msgstr "" #. type: cindex #, no-wrap msgid "@option{-ftest-coverage} option, record coverage" msgstr "" #. type: cindex #, no-wrap msgid "@option{ftest-coverage} option, record coverage" msgstr "" #. type: cindex #, no-wrap msgid "instrumented executable, for coverage testing" msgstr "" #. type: cindex #, no-wrap msgid "branches, instrumenting for coverage testing" msgstr "" #. type: Plain text msgid "" "This creates an @dfn{instrumented} executable which contains additional " "instructions that record the number of times each line of the program is " "executed. The option @option{-ftest-coverage} adds instructions for " "counting the number of times individual lines are executed, while " "@option{-fprofile-arcs} incorporates instrumentation code for each branch of " "the program. Branch instrumentation records how frequently different paths " "are taken through @samp{if} statements and other conditionals. The " "executable must then be run to create the coverage data:" msgstr "" #. type: example #, no-wrap msgid "" "$ ./a.out \n" "3 is divisible by 3\n" "6 is divisible by 3\n" "9 is divisible by 3\n" msgstr "" #. type: Plain text msgid "" "The data from the run is written to several files with the extensions " "@file{.bb} @file{.bbg} and @file{.da} respectively in the current " "directory. This data can be analyzed using the @code{gcov} command and the " "name of a source file:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcov cov.c \n" " 88.89% of 9 source lines executed in file cov.c\n" "Creating cov.c.gcov\n" msgstr "" #. type: Plain text msgid "" "The @code{gcov} command produces an annotated version of the original source " "file, with the file extension @file{.gcov}, containing counts of the number " "of times each line was executed:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude cov_c_gcov\n" msgstr "" #. type: Plain text msgid "" "The line counts can be seen in the first column of the output. Lines which " "were not executed are marked with hashes @samp{######}. The command " "@samp{grep '######' *.gcov} can be used to find parts of a program which " "have not been used." msgstr "" #. type: cindex #, no-wrap msgid "compilation, internal stages of" msgstr "" #. type: cindex #, no-wrap msgid "stages of compilation, used internally" msgstr "" #. type: cindex #, no-wrap msgid "compiler, how it works internally" msgstr "" #. type: cindex #, no-wrap msgid "assembler, @code{as}" msgstr "" #. type: cindex #, no-wrap msgid "preprocessor, @code{cpp}" msgstr "" #. type: cindex #: #, no-wrap msgid "linker, @code{ld}" msgstr "" #. type: cindex #, no-wrap msgid "archiver, @code{ar}" msgstr "" #. type: Plain text msgid "" "This chapter describes in more detail how GCC transforms source files to an " "executable file. Compilation is a multi-stage process involving several " "tools, including the GNU Compiler itself (through the @code{gcc} or " "@code{g++} frontends), the GNU Assembler @code{as}, and the GNU Linker " "@code{ld}. The complete set of tools used in the compilation process is " "referred to as a @dfn{toolchain}." msgstr "" #. type: section #: #, no-wrap msgid "An overview of the compilation process" msgstr "" #. type: section #: #, no-wrap msgid "The preprocessor" msgstr "" #. type: section #: #, no-wrap msgid "The compiler" msgstr "" #. type: section #: #, no-wrap msgid "The assembler" msgstr "" #. type: section #: #, no-wrap msgid "The linker" msgstr "" #. type: Plain text msgid "" "The sequence of commands executed by a single invocation of GCC consists of " "the following stages:" msgstr "" #. type: itemize msgid "preprocessing (to expand macros)" msgstr "" #. type: itemize msgid "compilation (from source code to assembly language)" msgstr "" #. type: itemize msgid "assembly (from assembly language to machine code)" msgstr "" #. type: itemize msgid "linking (to create the final executable)" msgstr "" #. type: Plain text msgid "" "As an example, we will examine these compilation stages individually using " "the @dfn{Hello World} program @file{hello.c}:" msgstr "" #. type: Plain text msgid "" "Note that it is not necessary to use any of the individual commands " "described in this section to compile a program. All the commands are " "executed automatically and transparently by GCC internally, and can be seen " "using the @option{-v} option described earlier (@pxref{Verbose " "compilation}). The purpose of this chapter is to provide an understanding " "of how the compiler works." msgstr "" #. type: Plain text msgid "" "Although the @dfn{Hello World} program is very simple it uses external " "header files and libraries, and so exercises all the major steps of the " "compilation process." msgstr "" #. type: cindex #, no-wrap msgid "preprocessor, first stage of compilation" msgstr "" #. type: Plain text msgid "" "The first stage of the compilation process is the use of the preprocessor to " "expand macros and included header files. To perform this stage, GCC " "executes the following command:@footnote{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.}" msgstr "" #. type: cindex #, no-wrap msgid "@code{.i}, preprocessed file extension for C" msgstr "" #. type: cindex #, no-wrap msgid "@code{i}, preprocessed file extension for C" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.i} preprocessed file" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.i} preprocessed file" msgstr "" #. type: cindex #, no-wrap msgid "@code{.ii}, preprocessed file extension for C++" msgstr "" #. type: cindex #, no-wrap msgid "@code{ii}, preprocessed file extension for C++" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.ii} preprocessed file" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.ii} preprocessed file" msgstr "" #. type: example #, no-wrap msgid "$ cpp hello.c > hello.i\n" msgstr "" #. type: Plain text msgid "" "The result is a file @file{hello.i} which contains the source code with all " "macros expanded. By convention, preprocessed files are given the file " "extension @file{.i} for C programs and @file{.ii} for C++ programs. In " "practice, the preprocessed file is not saved to disk unless the " "@option{-save-temps} option is used." msgstr "" #. type: cindex #, no-wrap msgid "compiler, converting source code to assembly code" msgstr "" #. type: cindex #, no-wrap msgid "@option{-S} option, create assembly code" msgstr "" #. type: cindex #, no-wrap msgid "@option{S} option, create assembly code" msgstr "" #. type: Plain text msgid "" "The next stage of the process is the actual compilation of preprocessed " "source code to assembly language, for a specific processor. The " "command-line option @option{-S} instructs @code{gcc} to convert the " "preprocessed C source code to assembly language without creating an object " "file:" msgstr "" #. type: example #, no-wrap msgid "$ gcc -Wall -S hello.i\n" msgstr "" #. type: cindex #, no-wrap msgid "@code{.s}, assembly file extension" msgstr "" #. type: cindex #, no-wrap msgid "@code{s}, assembly file extension" msgstr "" #. type: cindex #, no-wrap msgid "extension, @code{.s} assembly file" msgstr "" #. type: cindex #, no-wrap msgid "file extension, @code{.s} assembly file" msgstr "" #. type: Plain text msgid "" "The resulting assembly language is stored in the file @file{hello.s}. Here " "is what the @dfn{Hello World} assembly language for an Intel x86 (i686) " "processor looks like:" msgstr "" #. type: example #, no-wrap msgid "" "$ cat hello.s\n" " .file \"hello.c\"\n" " .section .rodata\n" ".LC0:\n" " .string \"Hello, world!\"\n" " .text\n" " .globl main\n" " .type main, @@function\n" "main:\n" ".LFB0:\n" " .cfi_startproc\n" " pushl %ebp\n" " .cfi_def_cfa_offset 8\n" " .cfi_offset 5, -8\n" " movl %esp, %ebp\n" " .cfi_def_cfa_register 5\n" " andl $-16, %esp\n" " subl $16, %esp\n" " movl $.LC0, (%esp)\n" " call puts\n" " movl $0, %eax\n" " leave\n" " .cfi_restore 5\n" " .cfi_def_cfa 4, 4\n" " ret\n" " .cfi_endproc\n" ".LFE0:\n" " .size main, .-main\n" " .ident \"GCC: (Debian 4.6.1-4) 4.6.1\"\n" " .section .note.GNU-stack,\"\",@@progbits\n" msgstr "" #. type: Plain text msgid "" "Note that the assembly language contains a call to the external function " "@code{puts}, a simpler version of @code{printf} for strings which do not " "contain formatting characters." msgstr "" #. type: cindex #, no-wrap msgid "assembler, converting assembly language to machine code" msgstr "" #. type: Plain text msgid "" "The purpose of the assembler is to convert assembly language into machine " "code and generate an object file. When there are calls to external " "functions in the assembly source file, the assembler leaves the addresses of " "the external functions undefined, to be filled in later by the linker. The " "assembler can be invoked with the following command line:" msgstr "" #. type: example #, no-wrap msgid "$ as hello.s -o hello.o\n" msgstr "" #. type: Plain text msgid "" "As with GCC, the output file is specified with the @option{-o} option. The " "resulting file @file{hello.o} contains the machine instructions for the " "@dfn{Hello World} program, with an undefined reference to @code{puts}." msgstr "" #. type: Plain text msgid "" "The final stage of compilation is the linking of object files to create an " "executable. In practice, an executable requires many external functions " "from system and C run-time (@code{crt}) libraries. Consequently, the actual " "link commands used internally by GCC are complicated. For example, the full " "command for linking the @dfn{Hello World} program is typically something " "like this:@footnote{The precise command varies depending on the version of " "@code{gcc} and operating system. Recent versions of @code{gcc} use a " "wrapper called @code{collect2} which does additional work before calling " "@code{ld}.}" msgstr "" #. type: example #, no-wrap msgid "" "$ ld -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o\n" "/usr/lib/gcc/i486-linux-gnu/4.3/crtbegin.o " "-L/usr/lib/gcc/i486-linux-gnu/4.3\n" "hello.o -lgcc -lgcc_eh -lc /usr/lib/gcc/i486-linux-gnu/4.3/crtend.o\n" "/usr/lib/crtn.o\n" msgstr "" #. type: Plain text msgid "" "Fortunately there is never any need to type the command above directly---the " "entire linking process is handled transparently by @code{gcc} when invoked " "as follows:" msgstr "" #. type: example #, no-wrap msgid "$ gcc hello.o \n" msgstr "" #. type: Plain text msgid "" "This links the object file @file{hello.o} to the C standard library, and " "produces an executable file @file{a.out}:" msgstr "" #. type: example #, no-wrap msgid "" "$ ./a.out \n" "Hello, world!\n" msgstr "" #. type: Plain text msgid "" "An object file for a C++ program can be linked to the C++ standard library " "in the same way with a single @code{g++} command." msgstr "" #. type: cindex #, no-wrap msgid "examining compiled files" msgstr "" #. type: cindex #, no-wrap msgid "compiled files, examining" msgstr "" #. type: Plain text msgid "" "This chapter describes several useful tools for examining the contents of " "executable files and object files." msgstr "" #. type: section #: #, no-wrap msgid "Identifying files" msgstr "" #. type: section #: #, no-wrap msgid "Examining the symbol table" msgstr "" #. type: section #: #, no-wrap msgid "Finding dynamically linked libraries" msgstr "" #. type: cindex #, no-wrap msgid "@code{file} command, for identifying files" msgstr "" #. type: cindex #, no-wrap msgid "identifying files, with @code{file} command" msgstr "" #. type: cindex #, no-wrap msgid "object file, examining with @code{file} command" msgstr "" #. type: cindex #, no-wrap msgid "executable, examining with @code{file} command" msgstr "" #. type: Plain text msgid "" "When a source file has been compiled to an object file or executable the " "options used to compile it are no longer obvious. The @command{file} " "command looks at the contents of an object file or executable and determines " "some of its characteristics, such as whether it was compiled with dynamic or " "static linking." msgstr "" #. type: Plain text msgid "" "For example, here is the result of the @command{file} command for a typical " "executable:" msgstr "" #. type: example #, no-wrap msgid "" "$ file a.out \n" "a.out: ELF 32-bit LSB executable, Intel 80386, \n" " version 1 (SYSV), dynamically linked (uses shared\n" " libs), not stripped\n" msgstr "" #. type: Plain text msgid "" "The output shows that the executable file is dynamically linked, and " "compiled for the Intel 386 and compatible processors. A full explanation of " "the output is shown below:" msgstr "" #. type: item #, no-wrap msgid "ELF" msgstr "" #. type: cindex #, no-wrap msgid "ELF format" msgstr "" #. type: cindex #, no-wrap msgid "COFF format" msgstr "" #. type: table msgid "" "The internal format of the executable file (ELF stands for ``Executable and " "Linking Format'', other formats such as COFF ``Common Object File Format'' " "are used on some older operating systems (e.g. MS-DOS))." msgstr "" #. type: item #, no-wrap msgid "32-bit" msgstr "" #. type: cindex #, no-wrap msgid "word-size, determined from executable file" msgstr "" #. type: table msgid "The word size (for some platforms this would be 64-bit)." msgstr "" #. type: item #, no-wrap msgid "LSB" msgstr "" #. type: cindex #, no-wrap msgid "LSB, least significant byte" msgstr "" #. type: cindex #, no-wrap msgid "MSB, most significant byte" msgstr "" #. type: cindex #, no-wrap msgid "Motorola 680x0, word-order" msgstr "" #. type: cindex #, no-wrap msgid "word-ordering, endianness" msgstr "" #. type: cindex #, no-wrap msgid "endianness, word-ordering" msgstr "" #. type: cindex #, no-wrap msgid "big-endian, word-ordering" msgstr "" #. type: cindex #, no-wrap msgid "little-endian, word-ordering" msgstr "" #. type: table msgid "" "Compiled for a platform with @dfn{least significant byte} first " "word-ordering, such as Intel and AMD x86 processors (the alternative MSB " "@dfn{most significant byte} first is used by other processors, such as the " "Motorola 680x0)@footnote{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).}. Some processors such as " "Itanium and MIPS support both LSB and MSB orderings." msgstr "" #. type: item #, no-wrap msgid "Intel 80386" msgstr "" #. type: table msgid "The processor the executable file was compiled for." msgstr "" #. type: item #, no-wrap msgid "version 1 (SYSV)" msgstr "" #. type: cindex #, no-wrap msgid "SYSV, System V executable format" msgstr "" #. type: table msgid "This is the version of the internal format of the file." msgstr "" #. type: item #, no-wrap msgid "dynamically linked" msgstr "" #. type: table msgid "" "The executable uses shared libraries (@code{statically linked} indicates " "programs linked statically, for example using the @option{-static} option)" msgstr "" #. type: item #, no-wrap msgid "not stripped" msgstr "" #. type: cindex #, no-wrap msgid "@code{strip} command" msgstr "" #. type: table msgid "" "The executable contains a symbol table (this can be removed with the " "@command{strip} command)." msgstr "" #. type: Plain text msgid "" "The @command{file} command can also be used on object files, where it gives " "similar output. The POSIX standard@footnote{POSIX.1 (2003 edition), IEEE " "Std 1003.1-2003.} for Unix systems defines the behavior of the " "@command{file} command." msgstr "" #. type: cindex #, no-wrap msgid "symbol table, examining with @code{nm}" msgstr "" #. type: cindex #, no-wrap msgid "@code{nm} command" msgstr "" #. type: Plain text msgid "" "As described earlier in the discussion of debugging, executables and object " "files can contain a symbol table (@pxref{Compiling for debugging}). This " "table stores the location of functions and variables by name, and can be " "displayed with the @command{nm} command:" msgstr "" #. type: example #, no-wrap msgid "" "$ nm a.out\n" "08049534 d _DYNAMIC\n" "08049608 d _GLOBAL_OFFSET_TABLE_\n" "........\n" "080483e4 T main\n" " U puts@@GLIBC_2.0\n" msgstr "" #. type: Plain text msgid "" "Among the contents of the symbol table, the output shows that the start of " "the @code{main} function has the hexadecimal offset @code{080483e4}. Most " "of the symbols are for internal use by the compiler and operating system. A " "@samp{T} in the second column indicates a function that is defined in the " "object file, while a @samp{U} indicates a function which is undefined (and " "should be resolved by linking against another object file). A complete " "explanation of the output of @code{nm} can be found in the @cite{GNU " "Binutils} manual." msgstr "" #. type: cindex #, no-wrap msgid "Binutils, GNU Binary Tools" msgstr "" #. type: Plain text msgid "" "The most common use of the @command{nm} command is to check whether a " "library contains the definition of a specific function, by looking for a " "@samp{T} entry in the second column against the function name." msgstr "" #. type: cindex #, no-wrap msgid "dynamically linked libraries, examining with @code{ldd}" msgstr "" #. type: cindex #, no-wrap msgid "shared libraries, examining with @code{ldd}" msgstr "" #. type: cindex #, no-wrap msgid "@code{ldd}, dynamical loader" msgstr "" #. type: cindex #, no-wrap msgid "dependencies, of shared libraries" msgstr "" #. type: cindex #, no-wrap msgid "shared libraries, dependencies" msgstr "" #. type: cindex #, no-wrap msgid "libraries, finding shared library dependencies" msgstr "" #. type: Plain text msgid "" "When a program has been compiled using shared libraries it needs to load " "those libraries dynamically at run-time in order to call external " "functions. The command @command{ldd} examines an executable and displays a " "list of the shared libraries that it needs. These libraries are referred to " "as the shared library @dfn{dependencies} of the executable." msgstr "" #. type: Plain text msgid "" "For example, the following commands demonstrate how to find the shared " "library dependencies of the @dfn{Hello World} program:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall hello.c\n" "$ ldd a.out \n" "libc.so.6 => /lib/libc.so.6 (0x40020000)\n" "/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)\n" msgstr "" #. type: Plain text msgid "" "The output shows that the @dfn{Hello World} program depends on the C library " "@code{libc} (shared library version 6) and the dynamic loader library " "@code{ld-linux} (shared library version 2)." msgstr "" #. type: Plain text msgid "" "If the program uses external libraries, such as the math library, these are " "also displayed. For example, the @code{calc} program (which uses the " "@code{sqrt} function) generates the following output:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall calc.c -lm -o calc\n" "$ ldd calc\n" "libm.so.6 => /lib/libm.so.6 (0x40020000)\n" "libc.so.6 => /lib/libc.so.6 (0x40041000)\n" "/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)\n" msgstr "" #. type: Plain text msgid "" "The first line shows that this program depends on the math library " "@code{libm} (shared library version 6), in addition to the C library and " "dynamic loader library." msgstr "" #. type: Plain text msgid "" "The @code{ldd} command can also be used to examine shared libraries " "themselves, in order to follow a chain of shared library dependencies." msgstr "" #. type: cindex #, no-wrap msgid "error messages, common examples" msgstr "" #. type: cindex #, no-wrap msgid "common error messages" msgstr "" #. type: Plain text msgid "" "This chapter describes the most frequent error and warning messages produced " "by @code{gcc} and @code{g++}. Each case is accompanied by a description of " "the causes, an example and suggestions of possible solutions. Note that " "error messages may vary slightly between different versions of the " "compiler. Some messages may only be displayed with options such as " "@option{-Wall} and @option{-W}." msgstr "" #. type: section #: #, no-wrap msgid "Preprocessor error messages" msgstr "" #. type: section #: #, no-wrap msgid "Compiler error messages" msgstr "" #. type: section #: #, no-wrap msgid "Linker error messages" msgstr "" #. type: section #: #, no-wrap msgid "Runtime error messages" msgstr "" #. type: cindex #, no-wrap msgid "preprocessor, error messages" msgstr "" #. type: cindex #: #, no-wrap msgid "No such file or directory" msgstr "" #. type: table msgid "" "This error occurs if GCC cannot find a requested file on its search path. " "The file may have been specified on the command-line, or with a preprocessor " "@code{#include} statement. Either the filename has been spelled incorrectly " "or the directory for the file needs to be added to the include path or link " "path." msgstr "" #. type: table #: msgid "Example:" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-file.c\n" msgstr "" #. type: table msgid "" "The program above tries to include the non-existent file @file{stdoi.h} " "giving the error @samp{stdoi.h: No such file or directory}. The correct " "filename should be @file{stdio.h}." msgstr "" #. type: cindex #: #, no-wrap msgid "macro or '#include' recursion too deep" msgstr "" #. type: itemx #, no-wrap msgid "#include nested too deeply" msgstr "" #. type: cindex #, no-wrap msgid "include nested too deeply" msgstr "" #. type: table msgid "" "This error occurs if the preprocessor encounters too many nested " "@samp{#include} directives. It is usually caused by two or more files " "trying to include each other, leading to an infinite recursion." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-nest1.h\n" msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-nest2.h\n" msgstr "" #. type: table msgid "" "The solution to this problem is to ensure that files do not mutually include " "each other, or to use ``include guards'' (@pxref{Providing your own " "templates} for an example)." msgstr "" #. type: item #, no-wrap msgid "invalid preprocessing directive #..." msgstr "" #. type: cindex #, no-wrap msgid "invalid preprocessing directive" msgstr "" #. type: table msgid "" "This error indicates that the preprocessor encountered an unrecognized " "@code{#} command." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-invalidpp.c\n" msgstr "" #. type: table msgid "" "The preprocessor syntax requires @code{#elif} for the ``else if'' condition " "in @code{#if} blocks, rather than @code{#elseif}. In the example above an " "invalid directive error occurs at the incorrect usage @code{#elseif}, but " "only when @code{FOO} is defined (otherwise the preprocessor ignores " "everything up to the @code{#else} statement)." msgstr "" #. type: cindex #, no-wrap msgid "@code{#elif}, preprocessor directive" msgstr "" #. type: cindex #, no-wrap msgid "@code{#else}, preprocessor directive" msgstr "" #. type: cindex #, no-wrap msgid "compiler, error messages" msgstr "" #. type: item #, no-wrap msgid "`@var{variable}' undeclared (first use in this function)" msgstr "" #. type: cindex #, no-wrap msgid "undeclared variable" msgstr "" #. type: table msgid "" "In C and C++ variables must be declared before they can be used. This error " "message indicates that the compiler has encountered a variable name which " "does not have a corresponding declaration. It can be caused by a missing " "declaration, or a typing error in the name. Variable names are " "case-sensitive, so @code{foo} and @code{Foo} represent different variables. " "To keep the output short, only the first use of an undeclared variable is " "reported." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-undeclared.c\n" msgstr "" #. type: table msgid "" "The variable @code{j} is not declared and will trigger the error @code{`j' " "undeclared}." msgstr "" #. type: item #, no-wrap msgid "parse error before `...'" msgstr "" #. type: itemx #, no-wrap msgid "expected ';' before `...'" msgstr "" #. type: cindex #: #, no-wrap msgid "syntax error" msgstr "" #. type: cindex #, no-wrap msgid "parse error" msgstr "" #. type: table msgid "" "These error messages occur when the compiler encounters unexpected input, " "i.e. sequences of characters which do not follow the syntax of the " "language. The error messages can be triggered by a missing close bracket, " "brace or semicolon preceding the line of the error, or an invalid keyword." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-parse.c\n" msgstr "" #. type: table msgid "" "There is a missing semicolon after the first call to @code{printf}, giving a " "parse error." msgstr "" #. type: cindex #: #, no-wrap msgid "parse error at end of input" msgstr "" #. type: itemx #, no-wrap msgid "expected declaration or statement at end of input" msgstr "" #. type: table msgid "" "This error occurs if the compiler encounters the end of a file unexpectedly, " "such as when it has parsed an unbalanced number of opening and closing " "braces. It is often caused by a missing closing brace somewhere." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-eoi.c\n" msgstr "" #. type: table msgid "" "An additional closing brace is needed in this program to prevent the error " "@code{expected declaration or statement at end of input}." msgstr "" #. type: item #, no-wrap msgid "warning: implicit declaration of function `...'" msgstr "" #. type: itemx #, no-wrap msgid "warning: incompatible implicit declaration of built-in function `...'" msgstr "" #. type: table msgid "" "This warning is generated when a function is used without a prototype being " "declared. It can be caused by failing to include a header file, or " "otherwise forgetting to provide a function prototype." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-implicitdecl.c\n" msgstr "" #. type: table msgid "" "The system header file @file{stdio.h} is not included, so the prototype for " "@code{printf} is not declared. The program needs an initial line " "@code{#include }." msgstr "" #. type: cindex #: #, no-wrap msgid "unterminated string or character constant" msgstr "" #. type: itemx #, no-wrap msgid "missing terminating \" character" msgstr "" #. type: table msgid "" "This error is caused by an opening string or character quote which does not " "have a corresponding closing quote. Quotes must occur in matching pairs, " "either single quotes @code{'a'} for characters or double quotes " "@code{\"aaa\"} for strings." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-unterm.c\n" msgstr "" #. type: table msgid "" "The opening quote for the string in this program does not have a " "corresponding closing quote, so the compiler will read the rest of the file " "as part of the string." msgstr "" #. type: cindex #: #, no-wrap msgid "character constant too long" msgstr "" #. type: table msgid "" "In C and C++ character codes are written using single quotes, e.g. " "@code{'a'} gives the ASCII code for the letter a (67), and @code{'\\n'} " "gives the ASCII code for newline (10). This error occurs if single quotes " "are used to enclose more than one character." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-string2.c\n" msgstr "" #. type: table msgid "" "The program above confuses single-quotes and double-quotes. A sequence of " "characters should be written with double quotes, e.g. @code{\"Hello " "World!\"}. This same problem occurs in the following C++ program," msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-string2.cc\n" msgstr "" #. type: table msgid "" "This error can also occur if the forward slash and backslash are confused in " "an escape sequence, e.g. using @code{'/n'} instead of @code{'\\n'}. The " "sequence @code{/n} consists of two separate characters, @samp{/} and " "@samp{n}." msgstr "" #. type: table msgid "" "Note that according to the C standard there is no limit on the length of a " "character constant, but the value of a character constant that contains more " "than one character is implementation-defined. Recent versions of GCC " "provide support multi-byte character constants, and instead of an error the " "warnings @code{multiple-character character constant} or @code{warning: " "character constant too long for its type} are generated in this case." msgstr "" #. type: cindex #, no-wrap msgid "multiple-character character constant" msgstr "" #. type: item #, no-wrap msgid "warning: initialization makes integer from pointer without a cast" msgstr "" #. type: cindex #, no-wrap msgid "initialization makes integer from pointer without a cast" msgstr "" #. type: table msgid "" "This error indicates a misuse of a pointer in an integer context. " "Technically, it is possible to convert between integer and pointer types, " "but this is rarely needed outside system-level applications. More often, " "this warning is the result of using a pointer without dereferencing it " "(e.g. writing @code{int i = p} instead of @code{int i = *p})." msgstr "" #. type: table msgid "" "This warning can also occur with @code{char} and @code{char *} types, since " "@code{char} is an integer type." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-char.c\n" msgstr "" #. type: table msgid "" "The variable @code{c} has type @code{char}, while the string @code{\"\\n\"} " "evaluates to a @code{const char *} pointer (to a 2-byte region of memory " "containing the ASCII value for newline followed by a zero byte @code{'\\0'}, " "since strings are null-terminated). The ASCII code for newline can be found " "using @code{char c = '\\n';}" msgstr "" #. type: table msgid "Similar errors can occur with misuse of the macro @code{NULL}," msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-null.c\n" msgstr "" #. type: table msgid "" "In C, the macro @code{NULL} is defined as @code{((void *)0)} in " "@file{stdlib.h} and should only be used in a pointer context." msgstr "" #. type: cindex #: #, no-wrap msgid "dereferencing pointer to incomplete type" msgstr "" #. type: table msgid "" "This error occurs when a program attempts to access the elements of struct " "through a pointer without the layout of the struct being declared first. In " "C and C++ it is possible to declare pointers to structs before declaring " "their struct layout, provided the pointers are not dereferenced---this is " "known as @dfn{forward declaration}." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-derefincomplete.c\n" msgstr "" #. type: table msgid "" "This program has a forward declaration of the @code{btree} struct " "@code{data}. However, the definition of the struct is needed before the " "pointer can be dereferenced to access individual members." msgstr "" #. type: item #, no-wrap msgid "warning: unknown escape sequence `...'" msgstr "" #. type: cindex #, no-wrap msgid "unknown escape sequence" msgstr "" #. type: table msgid "" "This error is caused by an incorrect use of the escape character in a " "string. Valid escape sequences are:" msgstr "" #. type: multitable msgid "@code{\\n} newline" msgstr "" #. type: multitable msgid "@code{\\t} tab" msgstr "" #. type: multitable msgid "@code{\\b} backspace" msgstr "" #. type: multitable msgid "@code{\\r} carriage return" msgstr "" #. type: multitable msgid "@code{\\f} form feed" msgstr "" #. type: multitable msgid "@code{\\v} vertical tab" msgstr "" #. type: multitable msgid "@code{\\a} alert (bell)" msgstr "" #. type: table msgid "" "The combinations @code{\\\\}, @code{\\'}, @code{\\\"} and @code{\\?} can be " "used for individual characters. Escape sequences can also use octal codes " "@code{\\0}--@code{\\377} and hexadecimal codes @code{\\0x00}--@code{\\0xFF}." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-unknownesc.c\n" msgstr "" #. type: table msgid "" "The escape sequence @code{\\N} in the program above is invalid---the correct " "escape sequence for a newline is @code{\\n}." msgstr "" #. type: item #, no-wrap msgid "warning: suggest parentheses around assignment used as truth value" msgstr "" #. type: cindex #, no-wrap msgid "suggest parentheses around assignment used as truth value" msgstr "" #. type: table msgid "" "This warning highlights a potentially serious error, using the assignment " "operator @samp{=} instead of the comparison operator @samp{==} in the test " "of a conditional statement or other logical expression. While the " "assignment operator can be used as part of a logical value, this is rarely " "the intended behavior." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-assign.c\n" msgstr "" #. type: table msgid "" "The test above should be written as @code{if (i == 1)}, otherwise the " "variable @code{i} will be set to @code{1} by the evaluation of the if " "statement itself. The operator @samp{=} both assigns and returns the value " "of its right-hand side, causing the variable @code{i} to be modified and the " "unexpected branch taken. Similar unexpected results occur with @code{if (i " "= 0)} instead of @code{if (i == 0)}, except that in this case the body of " "the @code{if} statement would never be executed." msgstr "" #. type: table msgid "" "This warning is suppressed if the assignment is enclosed in additional " "parentheses to indicate that it is being used legitimately." msgstr "" #. type: item #, no-wrap msgid "warning: control reaches end of non-void function" msgstr "" #. type: cindex #, no-wrap msgid "control reaches end of non-void function" msgstr "" #. type: table msgid "" "A function which has been declared with a return type, such as @code{int} or " "@code{double}, should always have a @code{return} statement returning a " "value of the corresponding type at all possible end points---otherwise its " "return value is not well-defined. Functions declared @code{void} do not " "need @code{return} statements." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-control.c\n" msgstr "" #. type: table msgid "" "The program above reaches the end of the @code{display} function, which has " "a return type of @code{int}, without a @code{return} statement. An " "additional line such as @code{return 0;} is needed." msgstr "" #. type: table msgid "" "When using @code{gcc} the @code{main} function of a C program must return a " "value of type @code{int} (the exit status of the program). In C++ the " "@code{return} statement can be omitted from the @code{main} function---the " "return value of the C++ @code{main} function defaults to 0 if unspecified." msgstr "" #. type: item #, no-wrap msgid "warning: unused variable `...'" msgstr "" #. type: itemx #, no-wrap msgid "warning: unused parameter `...'" msgstr "" #. type: cindex #, no-wrap msgid "unused parameter warning" msgstr "" #. type: table msgid "" "These warnings indicate that a variable has been declared as a local " "variable or in the parameters of a function, but has not been used " "anywhere. An unused variable can be the result of a programming error, such " "as accidentally using the name of a different variable in place of the " "intended one." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-unused.c\n" msgstr "" #. type: table msgid "" "In this program the variable @code{i} and the parameter @code{p} are never " "used. Note that unused variables are reported by @option{-Wall}, while " "unused parameters are only shown with @option{-Wall -W}." msgstr "" #. type: item #, no-wrap msgid "warning: passing arg of ... as ... due to prototype" msgstr "" #. type: cindex #, no-wrap msgid "passing arg of function as another type to prototype" msgstr "" #. type: table msgid "" "This warning occurs when a function is called with an argument of a " "different type from that specified in the prototype. The option " "@option{-Wconversion} is needed to enable this warning. See the description " "of @option{-Wconversion} in @ref{Additional warning options} for an example." msgstr "" #. type: item #, no-wrap msgid "warning: assignment of read-only location" msgstr "" #. type: itemx #, no-wrap msgid "warning: cast discards qualifiers from pointer target type" msgstr "" #. type: itemx #, no-wrap msgid "warning: assignment discards qualifiers ..." msgstr "" #. type: itemx #, no-wrap msgid "warning: initialization discards qualifiers ..." msgstr "" #. type: itemx #, no-wrap msgid "warning: return discards qualifiers ..." msgstr "" #. type: cindex #, no-wrap msgid "assignment of read-only location" msgstr "" #. type: cindex #, no-wrap msgid "cast discards qualifiers from pointer target type" msgstr "" #. type: cindex #, no-wrap msgid "assignment discards qualifiers" msgstr "" #. type: cindex #, no-wrap msgid "initialization discards qualifiers" msgstr "" #. type: cindex #, no-wrap msgid "return discards qualifiers" msgstr "" #. type: table msgid "" "These warnings occur when a pointer is used incorrectly, violating a type " "qualifier such as @code{const}. Data accessed through a pointer marked as " "@code{const} should not be modified, and the pointer itself can only be " "assigned to other pointers that are also marked @code{const}." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-const.c\n" msgstr "" #. type: table msgid "" "This program attempts to modify constant data, and to discard the " "@code{const} property of the argument @code{s} in the return value." msgstr "" #. type: cindex #: #, no-wrap msgid "initializer element is not a constant" msgstr "" #. type: table msgid "" "In C, global variables can only be initialized with constants, such as " "numeric values, @code{NULL} or fixed strings. This error occurs if a " "non-constant value is used." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-init.c\n" msgstr "" #. type: table msgid "" "This program attempts to initialize two variables from other variables. In " "particular, the stream @code{stdout} is not required to be a constant by the " "C standard (although on some systems it is a constant). Note that " "non-constant initializers are allowed in C++." msgstr "" #. type: cindex #, no-wrap msgid "linker, error messages" msgstr "" #. type: item #, no-wrap msgid "file not recognized: File format not recognized" msgstr "" #. type: cindex #, no-wrap msgid "file not recognized" msgstr "" #. type: cindex #, no-wrap msgid "file format not recognized" msgstr "" #. type: table msgid "" "GCC uses the extension of a file, such as @file{.c} or @file{.cc}, to " "determine its content. If the extension is missing GCC cannot recognize the " "file type and will give this error." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-ext\n" msgstr "" #. type: table msgid "" "If the program above is saved in a file @file{hello} without any extension " "then compiling it will give the error:" msgstr "" #. type: example #, no-wrap msgid "" "$ gcc -Wall hello\n" "hello: file not recognized: File format not \n" "recognized\n" "collect2: ld returned 1 exit status\n" msgstr "" #. type: table msgid "" "The solution is to rename the file to the correct extension, in this case " "@file{hello.c}." msgstr "" #. type: item #, no-wrap msgid "undefined reference to `foo'" msgstr "" #. type: cindex #: #, no-wrap msgid "collect2: ld returned 1 exit status" msgstr "" #. type: cindex #, no-wrap msgid "ld returned 1 exit status" msgstr "" #. type: table msgid "" "This error occurs when a program uses a function or variable which is not " "defined in any of the object files or libraries supplied to the linker. It " "can be caused by a missing library or the use of an incorrect name. In the " "error message above, the program @file{collect2} is part of the linker." msgstr "" #. type: example #, no-wrap msgid "@verbatiminclude msg-undef.c\n" msgstr "" #. type: table msgid "" "If this program is compiled without linking to a library or object file " "containing the function @code{foo()} there will be an undefined reference " "error." msgstr "" #. type: item #, no-wrap msgid "/usr/lib/crt1.o(.text+0x18): undefined reference to `main'" msgstr "" #. type: cindex #, no-wrap msgid "undefined reference to 'main'" msgstr "" #. type: table msgid "" "This error is a special case of the error above, when the missing function " "is @code{main}. In C and C++, every program must have a @code{main} " "function (where execution starts). When compiling an individual source file " "without a @code{main} function, use the option @option{-c} (@pxref{Creating " "object files from source files})." msgstr "" #. type: cindex #, no-wrap msgid "runtime error messages" msgstr "" #. type: item #, no-wrap msgid "error while loading shared libraries:" msgstr "" #. type: itemx #, no-wrap msgid "cannot open shared object file: No such file or directory" msgstr "" #. type: table msgid "" "The program uses shared libraries, but the necessary shared library files " "cannot be found by the dynamic linker when the program starts. The search " "path for shared libraries is controlled by the environment variable " "@env{LD_LIBRARY_PATH} (@pxref{Shared libraries and static libraries})." msgstr "" #. type: item #, no-wrap msgid "Segmentation fault" msgstr "" #. type: itemx #, no-wrap msgid "Bus error" msgstr "" #. type: cindex #, no-wrap msgid "bus error" msgstr "" #. type: cindex #, no-wrap msgid "uninitialized pointer" msgstr "" #. type: table msgid "These runtime messages indicate a memory access error." msgstr "" #. type: table msgid "Common causes include:" msgstr "" #. type: item #, no-wrap msgid "dereferencing a null pointer or uninitialized pointer" msgstr "" #. type: item #, no-wrap msgid "out-of-bounds array access" msgstr "" #. type: item #, no-wrap msgid "incorrect use of @code{malloc}, @code{free} and related functions" msgstr "" #. type: item #, no-wrap msgid "use of @code{scanf} with invalid arguments" msgstr "" #. type: table msgid "" "There is a subtle difference between segmentation faults and bus errors. A " "segmentation fault occurs when a process tries to access memory protected by " "the operating system. A bus error occurs when valid memory is accessed in " "an incorrect way (for example, trying to read an @dfn{unaligned} value on " "architectures where values must be aligned with 4-byte offsets)." msgstr "" #. type: cindex #: #, no-wrap msgid "floating point exception" msgstr "" #. type: table msgid "" "This runtime error is caused by an arithmetic exception, such as division by " "zero, overflow, underflow or an invalid operation (e.g. taking the square " "root of @math{-1}). The operating system determines which conditions " "produce this error. On GNU systems, the functions @code{feenableexcept} and " "@code{fedisableexcept} can be used to trap or mask each type of exception." msgstr "" #. type: item #, no-wrap msgid "Illegal instruction" msgstr "" #. type: table msgid "" "This error is produced by the operating system when an illegal machine " "instruction is encountered. It occurs when code has been compiled for one " "specific architecture and run on another." msgstr "" #. type: item #, no-wrap msgid "function declaration isn't a prototype" msgstr "" #. type: item #, no-wrap msgid "comparison between signed and unsigned" msgstr "" #. type: item #, no-wrap msgid "too few arguments for format" msgstr "" #. type: item #, no-wrap msgid "... used with ... format" msgstr "" #. type: item #, no-wrap msgid "declared inside parameter list" msgstr "" #. type: item #, no-wrap msgid "may not appear in macro parameter list" msgstr "" #. type: item #, no-wrap msgid "? without following :" msgstr "" #. type: itemx #, no-wrap msgid ": without preceding ?" msgstr "" #. type: itemx #, no-wrap msgid "signed and unsigned type in conditional expression" msgstr "" #. type: item #, no-wrap msgid "conflicting types for ...." msgstr "" #. type: item #, no-wrap msgid "/* within comment" msgstr "" #. type: item #, no-wrap msgid "type defaults to `int' in declaration of ..." msgstr "" #. type: item #, no-wrap msgid "data definition has no type or storage class" msgstr "" #. type: item #, no-wrap msgid "pointer targets differ in signedness" msgstr "" #. type: item #, no-wrap msgid "storage size of ... isn't known" msgstr "" #. type: item #, no-wrap msgid "integer overflow in expression" msgstr "" #. type: item #, no-wrap msgid "no previous prototype for ..." msgstr "" #. type: item #, no-wrap msgid "redundant redeclaration of ..." msgstr "" #. type: item #, no-wrap msgid "array subscript has type char" msgstr "" #. type: item #, no-wrap msgid "array subscript is not an integer" msgstr "" #. type: item #, no-wrap msgid "cast from pointer to integer of different size" msgstr "" #. type: item #, no-wrap msgid "return type defaults to int" msgstr "" #. type: item #, no-wrap msgid "missing braces around initializer" msgstr "" #. type: item #, no-wrap msgid "unterminated comment" msgstr "" #. type: item #, no-wrap msgid "suggest explicit braces to avoid ambiguous else" msgstr "" #. type: item #, no-wrap msgid "invalid lvalue in assignment" msgstr "" #. type: item #, no-wrap msgid "function returns address of local variable" msgstr "" #. type: item #, no-wrap msgid "comparison is always false due to limited range of datatype" msgstr "" #. type: itemx #, no-wrap msgid "comparison is always true due to limited range of datatype" msgstr "" #. type: table #, no-wrap msgid "" "can be caused by signed vs unsigned char\n" "\n" msgstr "" #. type: item #, no-wrap msgid "excess elements in scalar initializer" msgstr "" #. type: item #, no-wrap msgid "excess elements in struct initializer" msgstr "" #. type: item #, no-wrap msgid "excess elements in array initializer" msgstr "" #. type: item #, no-wrap msgid "invalid operands to binary ..." msgstr "" #. type: item #, no-wrap msgid "return with a value in function returning void" msgstr "" #. type: item #, no-wrap msgid "... is a GCC extension" msgstr "" #. type: item #, no-wrap msgid "empty body in an if-statement" msgstr "" #. type: item #, no-wrap msgid "empty body in an else-statement" msgstr "" #. type: item #, no-wrap msgid "invalid storage class for function ..." msgstr "" #. type: item #, no-wrap msgid "unknown escape sequence ..." msgstr "" #. type: item #, no-wrap msgid "variable or field ... declared void" msgstr "" #. type: item #, no-wrap msgid "argument ... doesn't match prototype" msgstr "" #. type: item #, no-wrap msgid "subscripted value is neither array nor pointer" msgstr "" #. type: item #, no-wrap msgid "braces around scalar initializer" msgstr "" #. type: item #, no-wrap msgid "number of arguments doesn't match prototype" msgstr "" #. type: item #, no-wrap msgid "large integer implicitly truncated to unsigned type" msgstr "" #. type: item #, no-wrap msgid "integer constant is too large for ... type" msgstr "" #. type: item #, no-wrap msgid "overflow in implicit constant conversion" msgstr "" #. type: item #, no-wrap msgid "nested extern declaration of ..." msgstr "" #. type: item #, no-wrap msgid "parameter has incomplete type" msgstr "" #. type: item #, no-wrap msgid "return with no value, in function returning non-void" msgstr "" #. type: item #, no-wrap msgid "no return statement in function returning non-void" msgstr "" #. type: item #, no-wrap msgid "this function may return with or without a value" msgstr "" #. type: item #, no-wrap msgid "... with different width due to prototype" msgstr "" #. type: item #, no-wrap msgid "declaration of ... shadows a global declaration" msgstr "" #. type: item #, no-wrap msgid "declaration of ... shadows a previous local declaration" msgstr "" #. type: item #, no-wrap msgid "... of read-only variable" msgstr "" #. type: item #, no-wrap msgid "initializer element is not computable at load time" msgstr "" #. type: item #, no-wrap msgid "empty character constant" msgstr "" #. type: item #, no-wrap msgid "... has an incomplete type" msgstr "" #. type: item #, no-wrap msgid "integer constant is so large that it is unsigned" msgstr "" #. type: item #, no-wrap msgid "backslash and newline separated by space" msgstr "" #. type: item #, no-wrap msgid "array size missing in ..." msgstr "" #. type: item #, no-wrap msgid "unrecognized format specifier ..." msgstr "" #. type: item #, no-wrap msgid "... as unsigned due to prototype" msgstr "" #. type: item #, no-wrap msgid "... as signed due to prototype" msgstr "" #. type: item #, no-wrap msgid "overflow in constant expression" msgstr "" #. type: item #, no-wrap msgid "floating point overflow in expression" msgstr "" #. type: item #, no-wrap msgid "for loop initial declaration used outside C99 mode" msgstr "" #. type: item #, no-wrap msgid "switch quantity is not an integer" msgstr "" #. type: item #, no-wrap msgid "too many decimal points in number" msgstr "" #. type: item #, no-wrap msgid "storage size of ... isn't constant" msgstr "" #. type: item #, no-wrap msgid "as floating rather than integer due to prototype" msgstr "" #. type: item #, no-wrap msgid "invalid conversion from ... to ..." msgstr "" #. type: item #, no-wrap msgid "no matching function for call to ..." msgstr "" #. type: item #, no-wrap msgid "shadow..." msgstr "" #. type: cindex #, no-wrap msgid "getting help" msgstr "" #. type: Plain text msgid "" "If you encounter a problem not covered by this introduction, there are " "several reference manuals which describe GCC and language-related topics in " "more detail (@pxref{Further reading}). These manuals contain answers to " "common questions, and careful study of them will usually yield a solution." msgstr "" #. type: Plain text msgid "" "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." msgstr "" #. type: cindex #, no-wrap msgid "support, commercial" msgstr "" #. type: cindex #, no-wrap msgid "commercial support" msgstr "" #. type: Plain text msgid "" "A directory of free software support companies and their current rates can " "be found on the GNU Project " "website.@footnote{@uref{http://www.gnu.org/prep/service.html}} With free " "software, commercial support is available in a free market---service " "companies compete in quality and price, and users are not tied to any " "particular one. In contrast, support for proprietary software is usually " "only available from the original vendor." msgstr "" #. type: cindex #, no-wrap msgid "enhancements, to GCC" msgstr "" #. type: Plain text msgid "" "A higher-level of commercial support for GCC is available from companies " "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.@footnote{@uref{http://www.network-theory.co.uk/gcc/intro/}} These " "companies can provide services such as extending GCC to generate code for " "new CPUs or fixing bugs in the compiler." msgstr "" #. type: cindex #, no-wrap msgid "manuals, for GNU software" msgstr "" #. type: Plain text msgid "" "The definitive guide to GCC is the official reference manual, ``@cite{Using " "GCC}'', published by GNU Press:" msgstr "" #. type: cindex #, no-wrap msgid "Using GCC (Reference Manual)" msgstr "" #. type: cindex #, no-wrap msgid "GNU Compilers, Reference Manual" msgstr "" #. type: quotation msgid "" "@cite{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)" msgstr "" #. type: Plain text msgid "" "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." msgstr "" #. type: Plain text msgid "" "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 manuals:" msgstr "" #. type: cindex #, no-wrap msgid "GNU GDB Manual" msgstr "" #. type: cindex #, no-wrap msgid "GNU Make Manual" msgstr "" #. type: quotation msgid "" "@cite{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)" msgstr "" #. type: quotation msgid "" "@cite{GNU Make: A Program for Directing Recompilation} by Richard " "M. Stallman and Roland McGrath (Published by GNU Press, ISBN 1-882114-82-5)" msgstr "" #. type: Plain text msgid "" "For effective C programming it is also essential to have a good knowledge of " "the C standard library. The following manual documents all the functions in " "the GNU C Library:" msgstr "" #. type: cindex #, no-wrap msgid "GNU C Library Reference Manual" msgstr "" #. type: quotation msgid "" "@cite{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)" msgstr "" #. type: cindex #, no-wrap msgid "GNU Press, manuals" msgstr "" #. type: Plain text msgid "" "Be sure to check the website @uref{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@footnote{@uref{http://order.fsf.org/}} in addition to being " "available for order through most bookstores using the ISBNs. Manuals " "published by GNU Press raise funds for the Free Software Foundation and the " "GNU Project." msgstr "" #. type: Plain text msgid "" "Information about shell commands, environment variables and shell-quoting " "rules can be found in the following book:" msgstr "" #. type: quotation msgid "" "@uref{http://www.network-theory.co.uk/bash/manual/,@cite{The GNU Bash " "Reference Manual},@cite{The GNU Bash Reference Manual}} by Chet Ramey and " "Brian Fox (Published by Network Theory Ltd, ISBN 0-9541617-7-7)" msgstr "" #. type: Plain text msgid "" "Other GNU Manuals mentioned in this book (such as @cite{GNU gprof---The GNU " "Profiler} and @cite{The GNU Binutils Manual}) were not available in print at " "the time this book went to press. Links to online copies can be found at " "the publisher's webpage for this " "book.@footnote{@uref{http://www.network-theory.co.uk/gcc/intro/}}" msgstr "" #. type: Plain text msgid "" "The official GNU Project webpage for GCC can be found on the GNU website at " "@uref{http://www.gnu.org/software/gcc/}. This includes a list of frequently " "asked questions, as well as the GCC bug tracking database and a lot of other " "useful information about GCC." msgstr "" #. type: Plain text msgid "" "There are many books about the C and C++ languages themselves. Two of the " "standard references are:" msgstr "" #. type: cindex #, no-wrap msgid "reference books" msgstr "" #. type: cindex #, no-wrap msgid "C language, further reading" msgstr "" #. type: cindex #, no-wrap msgid "books, further reading" msgstr "" #. type: cindex #, no-wrap msgid "Kernighan and Ritchie, @cite{The C Programming Language}" msgstr "" #. type: quotation msgid "" "@cite{The C Programming Language} (ANSI edition) Brian W. Kernighan, Dennis " "Ritchie (ISBN 0-13110362-8)" msgstr "" #. type: quotation msgid "" "@cite{The C++ Programming Language} (3rd edition) Bjarne Stroustrup (ISBN " "0-20188954-4)" msgstr "" #. type: cindex #, no-wrap msgid "standards, C, C++ and IEEE arithmetic" msgstr "" #. type: cindex #, no-wrap msgid "IEEE arithmetic standard, printed form" msgstr "" #. type: cindex #, no-wrap msgid "C/C++ languages, standards in printed form" msgstr "" #. type: cindex #, no-wrap msgid "ISO standards for C/C++ languages, available as books" msgstr "" #. type: cindex #, no-wrap msgid "ANSI standards for C/C++ languages, available as books" msgstr "" #. type: Plain text msgid "" "Anyone using the C and C++ languages in a professional context should obtain " "a copy of the official language standards, which are also available as " "printed books:" msgstr "" #. type: quotation msgid "" "@cite{The C Standard: Incorporating Technical Corrigendum 1} (Published by " "Wiley, ISBN 0-470-84573-2)" msgstr "" #. type: quotation msgid "@cite{The C++ Standard} (Published by Wiley, ISBN 0-470-84674-7)" msgstr "" #. type: Plain text msgid "" "For reference, the C standard number is ISO/IEC 9899:1990, for the original " "C standard published in 1990 and implemented by GCC. A revised C standard " "ISO/IEC 9899:1999 (known as C99) was published in 1999, and this is mostly " "(but not yet fully) supported by GCC. The C++ standard is ISO/IEC 14882." msgstr "" #. type: cindex #, no-wrap msgid "IEEE-754 standard" msgstr "" #. type: Plain text msgid "" "The floating-point arithmetic standard IEEE-754 is important for any " "programs involving numerical computations. The standard is available " "commercially from the IEEE, and is also described in the following book:" msgstr "" #. type: quotation msgid "" "@cite{Numerical Computing with IEEE Floating Point Arithmetic} by Michael " "Overton (Published by SIAM, ISBN 0-89871-482-6)." msgstr "" #. type: Plain text msgid "" "The book includes many examples to illustrate the rationale for the " "standard." msgstr "" #. type: Plain text msgid "" "Many people have contributed to this book, and it is important to record " "their names here:" msgstr "" #. type: Plain text msgid "" "Thanks to Gerald Pfeifer, for his careful reviewing and numerous suggestions " "for improving the book." msgstr "" #. type: Plain text msgid "" "Thanks to Andreas Jaeger, for information on AMD64 and multi-architecture " "support, and many helpful comments." msgstr "" #. type: Plain text msgid "" "Thanks to David Edelsohn, for information on the POWER/PowerPC series of " "processors." msgstr "" #. type: Plain text msgid "Thanks to Jamie Lokier, for research." msgstr "" #. type: Plain text msgid "" "Thanks to Martin Leisner, Mario Pernici, Stephen Compall and Nigel Lowry, " "for helpful corrections." msgstr "" #. type: Plain text msgid "Thanks to Gerard Jungman, for useful comments." msgstr "" #. type: Plain text msgid "" "Thanks to Steven Rubin, for generating the chip layout for the cover with " "Electric." msgstr "" #. type: Plain text msgid "" "And most importantly, thanks to Richard Stallman, founder of the GNU " "Project, for writing GCC and making it free software." msgstr "" #. type: Plain text msgid "" "The GNU Compiler Collection is part of the GNU Project, launched in 1984 to " "develop a complete Unix-like operating system which is free software: the " "GNU system." msgstr "" #. type: Plain text msgid "" "The Free Software Foundation (FSF) is a tax-exempt charity that raises funds " "for continuing work on the GNU Project. It is dedicated to promoting the " "right to use, study, copy, modify, and redistribute computer programs. One " "of the best ways to help the development of free software is to become an " "associate member of the Free Software Foundation, and pay regular dues to " "support their efforts." msgstr "" #. type: Plain text msgid "" "Associate members of the Free Software Foundation receive many benefits, " "including regular newsletters, admission to the FSF annual meeting, and " "discounts on books and CDROMs published by GNU Press. Membership dues are " "also tax deductible in the USA. For more information on becoming a member, " "visit the FSF website at @uref{http://www.fsf.org/}." msgstr "" #. type: Plain text msgid "" "The Free Software Foundation Europe (FSFE) is a sister organisation of the " "Free Software Foundation. The FSFE is active in promoting free software at " "all levels in Europe. For an annual membership fee, individuals can join " "FSFE and support its work. Members receive a personalised GPG-compatible " "membership smartcard, allowing secure digital authentication of email and " "files, and gain access to the ``FSFE Fellowship'', an electronic community " "for software freedom. For more information, visit the FSFE website at " "@uref{http://www.fsfe.org/}." msgstr "" #. type: Plain text msgid "" "The @cite{Foundation for a Free Information Infrastructure (FFII)} is " "another important organization in Europe. FFII is not specific to free " "software, but works to defend the rights of all programmers and computer " "users against monopolies in the field of computing, such as patents on " "software. For more information about FFII, or to support their work with a " "donation, visit their website at @uref{http://www.ffii.org/}." msgstr "" #. type: unnumbered #: #, no-wrap msgid "GNU Free Documentation License" msgstr "" #. type: center #, no-wrap msgid "Version 1.2, November 2002" msgstr "" #. type: ifnotinfo msgid "@smallerfonts @rm" msgstr "" #. type: display #, no-wrap msgid "" "Copyright @copyright{} 2000,2001,2002 Free Software Foundation, Inc.\n" "51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA\n" "\n" msgstr "" #. type: display #, no-wrap msgid "" "Everyone is permitted to copy and distribute verbatim copies\n" "of this license document, but changing it is not allowed.\n" msgstr "" #. type: enumerate msgid "PREAMBLE" msgstr "" #. type: enumerate msgid "" "The purpose of this License is to make a manual, textbook, or other " "functional and useful document @dfn{free} in the sense of freedom: to assure " "everyone the effective freedom to copy and redistribute it, with or without " "modifying it, either commercially or noncommercially. Secondarily, this " "License preserves for the author and publisher a way to get credit for their " "work, while not being considered responsible for modifications made by " "others." msgstr "" #. type: enumerate msgid "" "This License is a kind of ``copyleft'', which means that derivative works of " "the document must themselves be free in the same sense. It complements the " "GNU General Public License, which is a copyleft license designed for free " "software." msgstr "" #. type: enumerate msgid "" "We have designed this License in order to use it for manuals for free " "software, because free software needs free documentation: a free program " "should come with manuals providing the same freedoms that the software " "does. But this License is not limited to software manuals; it can be used " "for any textual work, regardless of subject matter or whether it is " "published as a printed book. We recommend this License principally for " "works whose purpose is instruction or reference." msgstr "" #. type: enumerate msgid "APPLICABILITY AND DEFINITIONS" msgstr "" #. type: enumerate msgid "" "This License applies to any manual or other work, in any medium, that " "contains a notice placed by the copyright holder saying it can be " "distributed under the terms of this License. Such a notice grants a " "world-wide, royalty-free license, unlimited in duration, to use that work " "under the conditions stated herein. The ``Document'', below, refers to any " "such manual or work. Any member of the public is a licensee, and is " "addressed as ``you''. You accept the license if you copy, modify or " "distribute the work in a way requiring permission under copyright law." msgstr "" #. type: enumerate msgid "" "A ``Modified Version'' of the Document means any work containing the " "Document or a portion of it, either copied verbatim, or with modifications " "and/or translated into another language." msgstr "" #. type: enumerate msgid "" "A ``Secondary Section'' is a named appendix or a front-matter section of the " "Document that deals exclusively with the relationship of the publishers or " "authors of the Document to the Document's overall subject (or to related " "matters) and contains nothing that could fall directly within that overall " "subject. (Thus, if the Document is in part a textbook of mathematics, a " "Secondary Section may not explain any mathematics.) The relationship could " "be a matter of historical connection with the subject or with related " "matters, or of legal, commercial, philosophical, ethical or political " "position regarding them." msgstr "" #. type: enumerate msgid "" "The ``Invariant Sections'' are certain Secondary Sections whose titles are " "designated, as being those of Invariant Sections, in the notice that says " "that the Document is released under this License. If a section does not fit " "the above definition of Secondary then it is not allowed to be designated as " "Invariant. The Document may contain zero Invariant Sections. If the " "Document does not identify any Invariant Sections then there are none." msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "" "A ``Transparent'' copy of the Document means a machine-readable copy, " "represented 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''." msgstr "" #. type: enumerate msgid "" "Examples of suitable formats for Transparent copies include plain @sc{ascii} " "without markup, Texinfo input format, La@TeX{} input format, @acronym{SGML} " "or @acronym{XML} using a publicly available @acronym{DTD}, and " "standard-conforming simple @acronym{HTML}, PostScript or @acronym{PDF} " "designed for human modification. Examples of transparent image formats " "include @acronym{PNG}, @acronym{XCF} and @acronym{JPG}. Opaque formats " "include proprietary formats that can be read and edited only by proprietary " "word processors, @acronym{SGML} or @acronym{XML} for which the @acronym{DTD} " "and/or processing tools are not generally available, and the " "machine-generated @acronym{HTML}, PostScript or @acronym{PDF} produced by " "some word processors for output purposes only." msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "" "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 " "translates 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." msgstr "" #. type: enumerate msgid "" "The Document may include Warranty Disclaimers next to the notice which " "states that this License applies to the Document. These Warranty " "Disclaimers are considered 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." msgstr "" #. type: enumerate msgid "VERBATIM COPYING" msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "" "You may also lend copies, under the same conditions stated above, and you " "may publicly display copies." msgstr "" #. type: enumerate msgid "COPYING IN QUANTITY" msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "" "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 location 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 ensure 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." msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "MODIFICATIONS" msgstr "" #. type: enumerate msgid "" "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:" msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "" "List on the Title Page, as authors, one or more persons or entities " "responsible for authorship of the modifications in the Modified Version, " "together with at least five of the principal authors of the Document (all of " "its principal authors, if it has fewer than five), unless they release you " "from this requirement." msgstr "" #. type: enumerate msgid "" "State on the Title page the name of the publisher of the Modified Version, " "as the publisher." msgstr "" #. type: enumerate msgid "Preserve all the copyright notices of the Document." msgstr "" #. type: enumerate msgid "" "Add an appropriate copyright notice for your modifications adjacent to the " "other copyright notices." msgstr "" #. type: enumerate msgid "" "Include, immediately after the copyright notices, a license notice giving " "the public permission to use the Modified Version under the terms of this " "License, in the form shown in the Addendum below." msgstr "" #. type: enumerate msgid "" "Preserve in that license notice the full lists of Invariant Sections and " "required Cover Texts given in the Document's license notice." msgstr "" #. type: enumerate msgid "Include an unaltered copy of this License." msgstr "" #. type: enumerate msgid "" "Preserve the section Entitled ``History'', Preserve its Title, and add to it " "an item stating at least the title, year, new authors, and publisher of the " "Modified Version as given on the Title Page. If there is no section " "Entitled ``History'' in the Document, create one stating the title, year, " "authors, and publisher of the Document as given on its Title Page, then add " "an item describing the Modified Version as stated in the previous sentence." msgstr "" #. type: enumerate msgid "" "Preserve the network location, if any, given in the Document for public " "access to a Transparent copy of the Document, and likewise the network " "locations given in the Document for previous versions it was based on. " "These may be placed in the ``History'' section. You may omit a network " "location for a work that was published at least four years before the " "Document itself, or if the original publisher of the version it refers to " "gives permission." msgstr "" #. type: enumerate msgid "" "For any section Entitled ``Acknowledgements'' or ``Dedications'', Preserve " "the Title of the section, and preserve in the section all the substance and " "tone of each of the contributor acknowledgements and/or dedications given " "therein." msgstr "" #. type: enumerate msgid "" "Preserve all the Invariant Sections of the Document, unaltered in their text " "and in their titles. Section numbers or the equivalent are not considered " "part of the section titles." msgstr "" #. type: enumerate msgid "" "Delete any section Entitled ``Endorsements''. Such a section may not be " "included in the Modified Version." msgstr "" #. type: enumerate msgid "" "Do not retitle any existing section to be Entitled ``Endorsements'' or to " "conflict in title with any Invariant Section." msgstr "" #. type: enumerate msgid "Preserve any Warranty Disclaimers." msgstr "" #. type: enumerate msgid "" "If the Modified Version includes new front-matter sections or appendices " "that qualify as Secondary Sections and contain no material copied from the " "Document, you may at your option designate some or all of these sections as " "invariant. To do this, add their titles to the list of Invariant Sections " "in the Modified Version's license notice. These titles must be distinct " "from any other section titles." msgstr "" #. type: enumerate msgid "" "You may add a section Entitled ``Endorsements'', provided it contains " "nothing but endorsements of your Modified Version by various parties---for " "example, statements of peer review or that the text has been approved by an " "organization as the authoritative definition of a standard." msgstr "" #. type: enumerate msgid "" "You may add a passage of up to five words as a Front-Cover Text, and a " "passage of up to 25 words as a Back-Cover Text, to the end of the list of " "Cover Texts in the Modified Version. Only one passage of Front-Cover Text " "and one of Back-Cover Text may be added by (or through arrangements made by) " "any one entity. If the Document already includes a cover text for the same " "cover, previously added by you or by arrangement made by the same entity you " "are acting on behalf of, you may not add another; but you may replace the " "old one, on explicit permission from the previous publisher that added the " "old one." msgstr "" #. type: enumerate msgid "" "The author(s) and publisher(s) of the Document do not by this License give " "permission to use their names for publicity for or to assert or imply " "endorsement of any Modified Version." msgstr "" #. type: enumerate msgid "COMBINING DOCUMENTS" msgstr "" #. type: enumerate msgid "" "You may combine the Document with other documents released under this " "License, 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." msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "" "In the combination, you must combine any sections Entitled ``History'' in " "the various original documents, forming one section Entitled ``History''; " "likewise combine any sections Entitled ``Acknowledgements'', and any " "sections Entitled ``Dedications''. You must delete all sections Entitled " "``Endorsements.''" msgstr "" #. type: enumerate msgid "COLLECTIONS OF DOCUMENTS" msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "AGGREGATION WITH INDEPENDENT WORKS" msgstr "" #. type: enumerate msgid "" "A compilation of the Document or its derivatives with other separate and " "independent documents or works, in or on a volume of a storage or " "distribution medium, is called an ``aggregate'' if the copyright resulting " "from the compilation 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." msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "TRANSLATION" msgstr "" #. type: enumerate msgid "" "Translation is considered a kind of modification, so you may distribute " "translations of the Document under the terms of section 4. Replacing " "Invariant Sections 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 disagreement " "between the translation and the original version of this License or a notice " "or disclaimer, the original version will prevail." msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "TERMINATION" msgstr "" #. type: enumerate msgid "" "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." msgstr "" #. type: enumerate msgid "FUTURE REVISIONS OF THIS LICENSE" msgstr "" #. type: enumerate msgid "" "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 @uref{http://www.gnu.org/copyleft/}." msgstr "" #. type: enumerate msgid "" "Each version of the License is given a distinguishing version number. If " "the Document 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." msgstr "" #. type: unnumberedsec #, no-wrap msgid "ADDENDUM: How to use this License for your documents" msgstr "" #. type: ifnotinfo msgid "" "To use this License in a document you have written, include a copy of the " "License in the document and put the following copyright and license notices " "just after the title page:" msgstr "" #. type: group #, no-wrap msgid "" " Copyright (C) @var{year} @var{your name}. \n" " Permission is granted to copy, distribute and/or modify\n" " this document under the terms of the GNU Free\n" " Documentation License, Version 1.2 or any later version\n" " published by the Free Software Foundation; with no\n" " Invariant Sections, no Front-Cover Texts, and no\n" " Back-Cover Texts. A copy of the license is included in\n" " the section entitled ``GNU Free Documentation License''.\n" msgstr "" #. type: ifnotinfo msgid "" "If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, " "replace the ``with...Texts.'' line with this:" msgstr "" #. type: group #, no-wrap msgid "" " with the Invariant Sections being @var{list their\n" " titles}, with the Front-Cover Texts being @var{list}, and\n" " with the Back-Cover Texts being @var{list}.\n" msgstr "" #. type: ifnotinfo msgid "" "If you have Invariant Sections without Cover Texts, or some other " "combination of the three, merge those two alternatives to suit the " "situation." msgstr "" #. type: ifnotinfo msgid "" "If your document contains nontrivial examples of program code, we recommend " "releasing these examples in parallel under your choice of free software " "license, such as the GNU General Public License, to permit their use in free " "software." msgstr "" #. type: ifset msgid "@*" msgstr ""