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 >
GNU Info File  |  1994-07-11  |  50KB  |  914 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.55 from the input
  2. file gcc.texi.
  3.    This file documents the use and the internals of the GNU compiler.
  4.    Published by the Free Software Foundation 675 Massachusetts Avenue
  5. Cambridge, MA 02139 USA
  6.    Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  7.    Permission is granted to make and distribute verbatim copies of this
  8. manual provided the copyright notice and this permission notice are
  9. preserved on all copies.
  10.    Permission is granted to copy and distribute modified versions of
  11. this manual under the conditions for verbatim copying, provided also
  12. that the sections entitled "GNU General Public License" and "Protect
  13. Your Freedom--Fight `Look And Feel'" are included exactly as in the
  14. original, and provided that the entire resulting derived work is
  15. distributed under the terms of a permission notice identical to this
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that the sections entitled "GNU General Public
  19. License" and "Protect Your Freedom--Fight `Look And Feel'", and this
  20. permission notice, may be included in translations approved by the Free
  21. Software Foundation instead of in the original English.
  22. File: gcc.info,  Node: Complex,  Next: Zero Length,  Prev: Long Long,  Up: C Extensions
  23. Complex Numbers
  24. ===============
  25.    GNU C supports complex data types.  You can declare both complex
  26. integer types and complex floating types, using the keyword
  27. `__complex__'.
  28.    For example, `__complex__ double x;' declares `x' as a variable
  29. whose real part and imaginary part are both of type `double'.
  30. `__complex__ short int y;' declares `y' to have real and imaginary
  31. parts of type `short int'; this is not likely to be useful, but it
  32. shows that the set of complex types is complete.
  33.    To write a constant with a complex data type, use the suffix `i' or
  34. `j' (either one; they are equivalent).  For example, `2.5fi' has type
  35. `__complex__ float' and `3i' has type `__complex__ int'.  Such a
  36. constant always has a pure imaginary value, but you can form any
  37. complex value you like by adding one to a real constant.
  38.    To extract the real part of a complex-valued expression EXP, write
  39. `__real__ EXP'.  Likewise, use `__imag__' to extract the imaginary part.
  40.    The operator `~' performs complex conjugation when used on a value
  41. with a complex type.
  42.    GNU CC can allocate complex automatic variables in a noncontiguous
  43. fashion; it's even possible for the real part to be in a register while
  44. the imaginary part is on the stack (or vice-versa).  None of the
  45. supported debugging info formats has a way to represent noncontiguous
  46. allocation like this, so GNU CC describes a noncontiguous complex
  47. variable as if it were two separate variables of noncomplex type.  If
  48. the variable's actual name is `foo', the two fictitious variables are
  49. named `foo$real' and `foo$imag'.  You can examine and set these two
  50. fictitious variables with your debugger.
  51.    A future version of GDB will know how to recognize such pairs and
  52. treat them as a single variable with a complex type.
  53. File: gcc.info,  Node: Zero Length,  Next: Variable Length,  Prev: Complex,  Up: C Extensions
  54. Arrays of Length Zero
  55. =====================
  56.    Zero-length arrays are allowed in GNU C.  They are very useful as
  57. the last element of a structure which is really a header for a
  58. variable-length object:
  59.      struct line {
  60.        int length;
  61.        char contents[0];
  62.      };
  63.      
  64.      {
  65.        struct line *thisline = (struct line *)
  66.          malloc (sizeof (struct line) + this_length);
  67.        thisline->length = this_length;
  68.      }
  69.    In standard C, you would have to give `contents' a length of 1, which
  70. means either you waste space or complicate the argument to `malloc'.
  71. File: gcc.info,  Node: Variable Length,  Next: Macro Varargs,  Prev: Zero Length,  Up: C Extensions
  72. Arrays of Variable Length
  73. =========================
  74.    Variable-length automatic arrays are allowed in GNU C.  These arrays
  75. are declared like any other automatic arrays, but with a length that is
  76. not a constant expression.  The storage is allocated at the point of
  77. declaration and deallocated when the brace-level is exited.  For
  78. example:
  79.      FILE *
  80.      concat_fopen (char *s1, char *s2, char *mode)
  81.      {
  82.        char str[strlen (s1) + strlen (s2) + 1];
  83.        strcpy (str, s1);
  84.        strcat (str, s2);
  85.        return fopen (str, mode);
  86.      }
  87.    Jumping or breaking out of the scope of the array name deallocates
  88. the storage.  Jumping into the scope is not allowed; you get an error
  89. message for it.
  90.    You can use the function `alloca' to get an effect much like
  91. variable-length arrays.  The function `alloca' is available in many
  92. other C implementations (but not in all).  On the other hand,
  93. variable-length arrays are more elegant.
  94.    There are other differences between these two methods.  Space
  95. allocated with `alloca' exists until the containing *function* returns.
  96. The space for a variable-length array is deallocated as soon as the
  97. array name's scope ends.  (If you use both variable-length arrays and
  98. `alloca' in the same function, deallocation of a variable-length array
  99. will also deallocate anything more recently allocated with `alloca'.)
  100.    You can also use variable-length arrays as arguments to functions:
  101.      struct entry
  102.      tester (int len, char data[len][len])
  103.      {
  104.        ...
  105.      }
  106.    The length of an array is computed once when the storage is allocated
  107. and is remembered for the scope of the array in case you access it with
  108. `sizeof'.
  109.    If you want to pass the array first and the length afterward, you can
  110. use a forward declaration in the parameter list--another GNU extension.
  111.      struct entry
  112.      tester (int len; char data[len][len], int len)
  113.      {
  114.        ...
  115.      }
  116.    The `int len' before the semicolon is a "parameter forward
  117. declaration", and it serves the purpose of making the name `len' known
  118. when the declaration of `data' is parsed.
  119.    You can write any number of such parameter forward declarations in
  120. the parameter list.  They can be separated by commas or semicolons, but
  121. the last one must end with a semicolon, which is followed by the "real"
  122. parameter declarations.  Each forward declaration must match a "real"
  123. declaration in parameter name and data type.
  124. File: gcc.info,  Node: Macro Varargs,  Next: Subscripting,  Prev: Variable Length,  Up: C Extensions
  125. Macros with Variable Numbers of Arguments
  126. =========================================
  127.    In GNU C, a macro can accept a variable number of arguments, much as
  128. a function can.  The syntax for defining the macro looks much like that
  129. used for a function.  Here is an example:
  130.      #define eprintf(format, args...)  \
  131.       fprintf (stderr, format , ## args)
  132.    Here `args' is a "rest argument": it takes in zero or more
  133. arguments, as many as the call contains.  All of them plus the commas
  134. between them form the value of `args', which is substituted into the
  135. macro body where `args' is used.  Thus, we have this expansion:
  136.      eprintf ("%s:%d: ", input_file_name, line_number)
  137.      ==>
  138.      fprintf (stderr, "%s:%d: " , input_file_name, line_number)
  139. Note that the comma after the string constant comes from the definition
  140. of `eprintf', whereas the last comma comes from the value of `args'.
  141.    The reason for using `##' is to handle the case when `args' matches
  142. no arguments at all.  In this case, `args' has an empty value.  In this
  143. case, the second comma in the definition becomes an embarrassment: if
  144. it got through to the expansion of the macro, we would get something
  145. like this:
  146.      fprintf (stderr, "success!\n" , )
  147. which is invalid C syntax.  `##' gets rid of the comma, so we get the
  148. following instead:
  149.      fprintf (stderr, "success!\n")
  150.    This is a special feature of the GNU C preprocessor: `##' before a
  151. rest argument that is empty discards the preceding sequence of
  152. non-whitespace characters from the macro definition.  (If another macro
  153. argument precedes, none of it is discarded.)
  154.    It might be better to discard the last preprocessor token instead of
  155. the last preceding sequence of non-whitespace characters; in fact, we
  156. may someday change this feature to d