home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 5
/
FreshFish_July-August1994.bin
/
bbs
/
gnu
/
gcc-2.5.8-bin.lha
/
info
/
gcc.info-7
(
.txt
)
< prev
next >
Wrap
GNU Info File
|
1994-07-11
|
50KB
|
914 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 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: Complex, Next: Zero Length, Prev: Long Long, Up: C Extensions
Complex Numbers
===============
GNU C supports complex data types. You can declare both complex
integer types and complex floating types, using the keyword
`__complex__'.
For example, `__complex__ double x;' declares `x' as a variable
whose real part and imaginary part are both of type `double'.
`__complex__ short int y;' declares `y' to have real and imaginary
parts of type `short int'; this is not likely to be useful, but it
shows that the set of complex types is complete.
To write a constant with a complex data type, use the suffix `i' or
`j' (either one; they are equivalent). For example, `2.5fi' has type
`__complex__ float' and `3i' has type `__complex__ int'. Such a
constant always has a pure imaginary value, but you can form any
complex value you like by adding one to a real constant.
To extract the real part of a complex-valued expression EXP, write
`__real__ EXP'. Likewise, use `__imag__' to extract the imaginary part.
The operator `~' performs complex conjugation when used on a value
with a complex type.
GNU CC can allocate complex automatic variables in a noncontiguous
fashion; it's even possible for the real part to be in a register while
the imaginary part is on the stack (or vice-versa). None of the
supported debugging info formats has a way to represent noncontiguous
allocation like this, so GNU CC describes a noncontiguous complex
variable as if it were two separate variables of noncomplex type. If
the variable's actual name is `foo', the two fictitious variables are
named `foo$real' and `foo$imag'. You can examine and set these two
fictitious variables with your debugger.
A future version of GDB will know how to recognize such pairs and
treat them as a single variable with a complex type.
File: gcc.info, Node: Zero Length, Next: Variable Length, Prev: Complex, Up: C Extensions
Arrays of Length Zero
=====================
Zero-length arrays are allowed in GNU C. They are very useful as
the last element of a structure which is really a header for a
variable-length object:
struct line {
int length;
char contents[0];
};
{
struct line *thisline = (struct line *)
malloc (sizeof (struct line) + this_length);
thisline->length = this_length;
}
In standard C, you would have to give `contents' a length of 1, which
means either you waste space or complicate the argument to `malloc'.
File: gcc.info, Node: Variable Length, Next: Macro Varargs, Prev: Zero Length, Up: C Extensions
Arrays of Variable Length
=========================
Variable-length automatic arrays are allowed in GNU C. These arrays
are declared like any other automatic arrays, but with a length that is
not a constant expression. The storage is allocated at the point of
declaration and deallocated when the brace-level is exited. For
example:
FILE *
concat_fopen (char *s1, char *s2, char *mode)
{
char str[strlen (s1) + strlen (s2) + 1];
strcpy (str, s1);
strcat (str, s2);
return fopen (str, mode);
}
Jumping or breaking out of the scope of the array name deallocates
the storage. Jumping into the scope is not allowed; you get an error
message for it.
You can use the function `alloca' to get an effect much like
variable-length arrays. The function `alloca' is available in many
other C implementations (but not in all). On the other hand,
variable-length arrays are more elegant.
There are other differences between these two methods. Space
allocated with `alloca' exists until the containing *function* returns.
The space for a variable-length array is deallocated as soon as the
array name's scope ends. (If you use both variable-length arrays and
`alloca' in the same function, deallocation of a variable-length array
will also deallocate anything more recently allocated with `alloca'.)
You can also use variable-length arrays as arguments to functions:
struct entry
tester (int len, char data[len][len])
{
...
}
The length of an array is computed once when the storage is allocated
and is remembered for the scope of the array in case you access it with
`sizeof'.
If you want to pass the array first and the length afterward, you can
use a forward declaration in the parameter list--another GNU extension.
struct entry
tester (int len; char data[len][len], int len)
{
...
}
The `int len' before the semicolon is a "parameter forward
declaration", and it serves the purpose of making the name `len' known
when the declaration of `data' is parsed.
You can write any number of such parameter forward declarations in
the parameter list. They can be separated by commas or semicolons, but
the last one must end with a semicolon, which is followed by the "real"
parameter declarations. Each forward declaration must match a "real"
declaration in parameter name and data type.
File: gcc.info, Node: Macro Varargs, Next: Subscripting, Prev: Variable Length, Up: C Extensions
Macros with Variable Numbers of Arguments
=========================================
In GNU C, a macro can accept a variable number of arguments, much as
a function can. The syntax for defining the macro looks much like that
used for a function. Here is an example:
#define eprintf(format, args...) \
fprintf (stderr, format , ## args)
Here `args' is a "rest argument": it takes in zero or more
arguments, as many as the call contains. All of them plus the commas
between them form the value of `args', which is substituted into the
macro body where `args' is used. Thus, we have this expansion:
eprintf ("%s:%d: ", input_file_name, line_number)
==>
fprintf (stderr, "%s:%d: " , input_file_name, line_number)
Note that the comma after the string constant comes from the definition
of `eprintf', whereas the last comma comes from the value of `args'.
The reason for using `##' is to handle the case when `args' matches
no arguments at all. In this case, `args' has an empty value. In this
case, the second comma in the definition becomes an embarrassment: if
it got through to the expansion of the macro, we would get something
like this:
fprintf (stderr, "success!\n" , )
which is invalid C syntax. `##' gets rid of the comma, so we get the
following instead:
fprintf (stderr, "success!\n")
This is a special feature of the GNU C preprocessor: `##' before a
rest argument that is empty discards the preceding sequence of
non-whitespace characters from the macro definition. (If another macro
argument precedes, none of it is discarded.)
It might be better to discard the last preprocessor token instead of
the last preceding sequence of non-whitespace characters; in fact, we
may someday change this feature to d