home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
gnu
/
gcc-2.3.3-src.lha
/
GNU
/
src
/
amiga
/
gcc-2.3.3
/
gcc.info-6
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-02-06
|
48KB
|
820 lines
This is Info file gcc.info, produced by Makeinfo-1.49 from the input
file gcc.texi.
This file documents the use and the internals of the GNU compiler.
Copyright (C) 1988, 1989, 1992 Free Software Foundation, Inc.
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" 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
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" 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: Function Attributes, Next: Function Prototypes, Prev: Case Ranges, Up: 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.
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 `volatile' to
tell the compiler this fact. For example,
extern void volatile fatal ();
void
fatal (...)
{
... /* Print error message. */ ...
exit (1);
}
The `volatile' keyword tells the compiler to assume that `fatal'
cannot return. This makes slightly better code, but more importantly
it helps avoid spurious warnings of uninitialized variables.
It does not make sense for a `volatile' function to have a return
type other than `void'.
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
`const'. For example,
extern int const square ();
says that the hypothetical function `square' is safe to call fewer
times than the program says.
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'.
We recommend placing the keyword `const' after the function's return
type. It makes no difference in the example above, but when the return
type is a pointer, it is the only way to make the function itself
const. For example,
const char *mincp (int);
says that `mincp' returns `const char *'--a pointer to a const object.
To declare `mincp' const, you must write this:
char * const mincp (int);
Some people object to this feature, suggesting that ANSI C's
`#pragma' should be used instead. There are two reasons for not doing
this.
1. It is impossible to generate `#pragma' commands from a macro.
2. The `#pragma' command is just as likely as these keywords to mean
something else in another compiler.
These two reasons apply to almost any application that might be
proposed for `#pragma'. It is basically a mistake to use `#pragma' for
*anything*.
The keyword `__attribute__' allows you to specify special attributes
when making a declaration. This keyword is followed by an attribute
specification inside double parentheses. One attribute, `format', is
currently defined for functions. Others are implemented for variables
and structure fields (*note Function Attributes::.).
`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 functions for errors. The compiler always
checks formats for the ANSI library functions `printf', `fprintf',
`sprintf', `scanf', `fscanf', `sscanf', `vprintf', `vfprintf' and
`vsprintf' whenever such warnings are requested (using
`-Wformat'), so there is no need to modify the header file
`stdio.h'.
File: gcc.info, Node: Function Prototypes, Next: Dollar Signs, Prev: Function Attributes, Up: Extensions
Prototypes and Old-Style Function Definitions
=============================================
GNU C extends ANSI C to allow a function prototype to override a
later old-style non-prototype definition. Consider the following
example:
/* Use prototypes unless the compiler is old-fashioned. */
#if __STDC__
#define P(x) (x)
#else
#define P(x) ()
#endif
/* Prototype function declaration. */
int isroot P((uid_t));
/* Old-style function definition. */
int
isroot (x) /* ??? lossage here ??? */
uid_t x;
{
return x == 0;
}
Suppose the type `uid_t' happens to be `short'. ANSI C does not
allow this example, because subword arguments in old-style
non-prototype definitions are promoted. Therefore in this example the
function definition's argument is really an `int', which does not match
the prototype argument type of `short'.
This restriction of ANSI C makes it hard to write code that is
portable to traditional C compilers, because the programmer does not
know whether the `uid_t' type is `short', `int', or `long'. Therefore,
in cases like these GNU C allows a prototype to override a later
old-style definition. More precisely, in GNU C, a function prototype
argument type overrides the argument type specified by a later
old-style definition if the former type is the same as the latter type
before promotion. Thus in GNU C the above example is equivalent to the
following:
int isroot (uid_t);
int
isroot (uid_t x)
{
return x == 0;
}
File: gcc.info, Node: Dollar Signs, Next: Character Escapes, Prev: Function Prototypes, Up: Extensions
Dollar Signs in Identifier Names
================================
In GNU C, you may use dollar signs in identifier names. This is
because many traditional C implementations allow such identifiers.
On some machines, dollar signs are allowed in identifiers if you
specify `-traditional'. On a few systems they are allowed by default,
even if you do not use `-traditional'. But they are never allowed if
you specify `-ansi'.
There are certain ANSI C