home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
info
/
gcc.info-8
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-12-22
|
51KB
|
928 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: Case Ranges, Next: Function Attributes, Prev: Cast to Union, Up: C Extensions
Case Ranges
===========
You can specify a range of consecutive values in a single `case'
label, like this:
case LOW ... HIGH:
This has the same effect as the proper number of individual `case'
labels, one for each integer value from LOW to HIGH, inclusive.
This feature is especially useful for ranges of ASCII character
codes:
case 'A' ... 'Z':
*Be careful:* Write spaces around the `...', for otherwise it may be
parsed wrong when you use it with integer values. For example, write
this:
case 1 ... 5:
rather than this:
case 1...5:
File: gcc.info, Node: Cast to Union, Next: Case Ranges, Prev: Labeled Elements, Up: C Extensions
Cast to a Union Type
====================
A cast to union type is similar to other casts, except that the type
specified is a union type. You can specify the type either with `union
TAG' or with a typedef name. A cast to union is actually a constructor
though, not a cast, and hence does not yield an lvalue like normal
casts. (*Note Constructors::.)
The types that may be cast to the union type are those of the members
of the union. Thus, given the following union and variables:
union foo { int i; double d; };
int x;
double y;
both `x' and `y' can be cast to type `union' foo.
Using the cast as the right-hand side of an assignment to a variable
of union type is equivalent to storing in a member of the union:
union foo u;
...
u = (union foo) x == u.i = x
u = (union foo) y == u.d = y
You can also use the union cast as a function argument:
void hack (union foo);
...
hack ((union foo) x);
File: gcc.info, Node: Function Attributes, Next: Function Prototypes, Prev: Case Ranges, Up: C Extensions
Declaring Attributes of Functions
=================================
In GNU C, you declare certain things about functions called in your
program which help the compiler optimize function calls and check your
code more carefully.
The keyword `__attribute__' allows you to specify special attributes
when making a declaration. This keyword is followed by an attribute
specification inside double parentheses. Four attributes, `noreturn',
`const', `format', and `section' are currently defined for functions.
Other attributes, including `section' are supported for variables
declarations (*note Variable Attributes::.).
You may also specify attributes with `__' preceeding and following
each keyword. This allows you to use them in header files without
being concerned about a possible macro of the same name. For example,
you may use `__noreturn__' instead of `noreturn'.
`noreturn'
A few standard library functions, such as `abort' and `exit',
cannot return. GNU CC knows this automatically. Some programs
define their own functions that never return. You can declare them
`noreturn' to tell the compiler this fact. For example,
void fatal () __attribute__ ((noreturn));
void
fatal (...)
{
... /* Print error message. */ ...
exit (1);
}
The `noreturn' keyword tells the compiler to assume that `fatal'
cannot return. It can then optimize without regard to what would
happen if `fatal' ever did return. This makes slightly better
code. More importantly, it helps avoid spurious warnings of
uninitialized variables.
Do not assume that registers saved by the calling function are
restored before calling the `noreturn' function.
It does not make sense for a `noreturn' function to have a return
type other than `void'.
The attribute `noreturn' is not implemented in GNU C versions
earlier than 2.5. An alternative way to declare that a function
does not return, which works in the current version and in some
older versions, is as follows:
typedef void voidfn ();
volatile voidfn fatal;
`const'
Many functions do not examine any values except their arguments,
and have no effects except the return value. Such a function can
be subject to common subexpression elimination and loop
optimization just as an arithmetic operator would be. These
functions should be declared with the attribute `const'. For
example,
int square (int) __attribute__ ((const));
says that the hypothetical function `square' is safe to call fewer
times than the program says.
The attribute `const' is not implemented in GNU C versions earlier
than 2.5. An alternative way to declare that a function has no
side effects, which works in the current version and in some older
versions, is as follows:
typedef int intfn ();
extern const intfn square;
This approach does not work in GNU C++ from 2.6.0 on, since the
language specifies that the `const' must be attached to the return
value.
Note that a function that has pointer arguments and examines the
data pointed to must *not* be declared `const'. Likewise, a
function that calls a non-`const' function usually must not be
`const'. It does not make sense for a `const' function to return
`void'.
`format (ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)'
The `format' attribute specifies that a function takes `printf' or
`scanf' style arguments which should be type-checked against a
format string. For example, the declaration:
extern int
my_printf (void *my_object, const char *my_format, ...)
__attribute__ ((format (printf, 2, 3)));
causes the compiler to check the arguments in calls to `my_printf'
for consistency with the `printf' style format string argument
`my_format'.
The parameter ARCHETYPE determines how the format string is
interpreted, and should be either `printf' or `scanf'. The
parameter STRING-INDEX specifies which argument is the format
string argument (starting from 1), while FIRST-TO-CHECK is the
number of the first argument to check against the format string.
For functions where the arguments are not available to be checked
(such as `vprintf'), specify the third parameter as zero. In this
case the compiler only checks the format string for consistency.
In the example above, the format string (`my_format') is the second
argument of the function `my_print', and the arguments to check
start with the third argument, so the correct parameters for the
format attribute are 2 and 3.
The `format' attribute allows you to identify your own functions
which take format strings as arguments, so that GNU CC can check
the calls to these fun