home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
gnu
/
gcc-2.6.3-bin.lha
/
GNU
/
info
/
gcc.info-9
(
.txt
)
< prev
Wrap
GNU Info File
|
1994-12-23
|
50KB
|
851 lines
This is Info file gcc.info, produced by Makeinfo-1.55 from the input
file gcc.texi.
This file documents the use and the internals of the GNU compiler.
Published by the Free Software Foundation 675 Massachusetts Avenue
Cambridge, MA 02139 USA
Copyright (C) 1988, 1989, 1992, 1993, 1994 Free Software Foundation,
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
Permission is granted to copy and distribute modified versions of
this manual under the conditions for verbatim copying, provided also
that the sections entitled "GNU General Public License," "Funding for
Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
included exactly as in the original, and provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
Permission is granted to copy and distribute translations of this
manual into another language, under the above conditions for modified
versions, except that the sections entitled "GNU General Public
License," "Funding for Free Software," and "Protect Your Freedom--Fight
`Look And Feel'", and this permission notice, may be included in
translations approved by the Free Software Foundation instead of in the
original English.
File: gcc.info, Node: Min and Max, Next: Destructors and Goto, Prev: Naming Results, Up: C++ Extensions
Minimum and Maximum Operators in C++
====================================
It is very convenient to have operators which return the "minimum"
or the "maximum" of two arguments. In GNU C++ (but not in GNU C),
`A <? B'
is the "minimum", returning the smaller of the numeric values A
and B;
`A >? B'
is the "maximum", returning the larger of the numeric values A and
B.
These operations are not primitive in ordinary C++, since you can
use a macro to return the minimum of two things in C++, as in the
following example.
#define MIN(X,Y) ((X) < (Y) ? : (X) : (Y))
You might then use `int min = MIN (i, j);' to set MIN to the minimum
value of variables I and J.
However, side effects in `X' or `Y' may cause unintended behavior.
For example, `MIN (i++, j++)' will fail, incrementing the smaller
counter twice. A GNU C extension allows you to write safe macros that
avoid this kind of problem (*note Naming an Expression's Type: Naming
Types.). However, writing `MIN' and `MAX' as macros also forces you to
use function-call notation notation for a fundamental arithmetic
operation. Using GNU C++ extensions, you can write `int min = i <? j;'
instead.
Since `<?' and `>?' are built into the compiler, they properly
handle expressions with side-effects; `int min = i++ <? j++;' works
correctly.
File: gcc.info, Node: Destructors and Goto, Next: C++ Interface, Prev: Min and Max, Up: C++ Extensions
`goto' and Destructors in GNU C++
=================================
In C++ programs, you can safely use the `goto' statement. When you
use it to exit a block which contains aggregates requiring destructors,
the destructors will run before the `goto' transfers control. (In ANSI
C++, `goto' is restricted to targets within the current block.)
The compiler still forbids using `goto' to *enter* a scope that
requires constructors.
File: gcc.info, Node: C++ Interface, Next: Template Instantiation, Prev: Destructors and Goto, Up: C++ Extensions
Declarations and Definitions in One Header
==========================================
C++ object definitions can be quite complex. In principle, your
source code will need two kinds of things for each object that you use
across more than one source file. First, you need an "interface"
specification, describing its structure with type declarations and
function prototypes. Second, you need the "implementation" itself. It
can be tedious to maintain a separate interface description in a header
file, in parallel to the actual implementation. It is also dangerous,
since separate interface and implementation definitions may not remain
parallel.
With GNU C++, you can use a single header file for both purposes.
*Warning:* The mechanism to specify this is in transition. For the
nonce, you must use one of two `#pragma' commands; in a future
release of GNU C++, an alternative mechanism will make these
`#pragma' commands unnecessary.
The header file contains the full definitions, but is marked with
`#pragma interface' in the source code. This allows the compiler to
use the header file only as an interface specification when ordinary
source files incorporate it with `#include'. In the single source file
where the full implementation belongs, you can use either a naming
convention or `#pragma implementation' to indicate this alternate use
of the header file.
`#pragma interface'
`#pragma interface "SUBDIR/OBJECTS.h"'
Use this directive in *header files* that define object classes,
to save space in most of the object files that use those classes.
Normally, local copies of certain information (backup copies of
inline member functions, debugging information, and the internal
tables that implement virtual functions) must be kept in each
object file that includes class definitions. You can use this
pragma to avoid such duplication. When a header file containing
`#pragma interface' is included in a compilation, this auxiliary
information will not be generated (unless the main input source
file itself uses `#pragma implementation'). Instead, the object
files will contain references to be resolved at link time.
The second form of this directive is useful for the case where you
have multiple headers with the same name in different directories.
If you use this form, you must specify the same string to `#pragma
implementation'.
`#pragma implementation'
`#pragma implementation "OBJECTS.h"'
Use this pragma in a *main input file*, when you want full output
from included header files to be generated (and made globally
visible). The included header file, in turn, should use `#pragma
interface'. Backup copies of inline member functions, debugging
information, and the internal tables used to implement virtual
functions are all generated in implementation files.
If you use `#pragma implementation' with no argument, it applies to
an include file with the same basename(1) as your source file.
For example, in `allclass.cc', `#pragma implementation' by itself
is equivalent to `#pragma implementation "allclass.h"'.
In versions of GNU C++ prior to 2.6.0 `allclass.h' was treated as
an implementation file whenever you would include it from
`allclass.cc' even if you never specified `#pragma
implementation'. This was deemed to be more trouble than it was
worth, however, and disabled.
If you use an explicit `#pragma implementation', it must appear in
your source file *before* you include the affected header files.
Use the string argument if you want a single implementation file to
include code from multiple header files. (You must also use
`#include' to include the header file; `#pragma implementation'
only specifies how to use the file--it doesn't actually include
it.)
There is no way to split up the contents of a single header file
into multiple implementation files.
`#pragma implementation' and `#pragma interface' also have an effect
on function inlining.
If you define a class in a header file marked with `#pragma
interface', the effect on a function defined in that class is similar to
an explicit `extern' declaration--the compiler emits no code at all to
define an independent version of the function. Its definition is used
only for inlining with its callers.
Conversely, when you include the same header file in a main source
file that declares it as `#pragma implementation', the compiler emits
code for the function itself; this defines a version of the function
that can be found via pointers (or by callers compiled without
inlining). If all c