home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / gcc.info-8 (.txt) < prev    next >
GNU Info File  |  1994-12-22  |  51KB  |  928 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, 1994 Free Software Foundation,
  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," "Funding for
  13. Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
  14. included exactly as in the original, and provided that the entire
  15. resulting derived work is distributed under the terms of a permission
  16. notice identical to this one.
  17.    Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions, except that the sections entitled "GNU General Public
  20. License," "Funding for Free Software," and "Protect Your Freedom--Fight
  21. `Look And Feel'", and this permission notice, may be included in
  22. translations approved by the Free Software Foundation instead of in the
  23. original English.
  24. File: gcc.info,  Node: Case Ranges,  Next: Function Attributes,  Prev: Cast to Union,  Up: C Extensions
  25. Case Ranges
  26. ===========
  27.    You can specify a range of consecutive values in a single `case'
  28. label, like this:
  29.      case LOW ... HIGH:
  30. This has the same effect as the proper number of individual `case'
  31. labels, one for each integer value from LOW to HIGH, inclusive.
  32.    This feature is especially useful for ranges of ASCII character
  33. codes:
  34.      case 'A' ... 'Z':
  35.    *Be careful:* Write spaces around the `...', for otherwise it may be
  36. parsed wrong when you use it with integer values.  For example, write
  37. this:
  38.      case 1 ... 5:
  39. rather than this:
  40.      case 1...5:
  41. File: gcc.info,  Node: Cast to Union,  Next: Case Ranges,  Prev: Labeled Elements,  Up: C Extensions
  42. Cast to a Union Type
  43. ====================
  44.    A cast to union type is similar to other casts, except that the type
  45. specified is a union type.  You can specify the type either with `union
  46. TAG' or with a typedef name.  A cast to union is actually a constructor
  47. though, not a cast, and hence does not yield an lvalue like normal
  48. casts.  (*Note Constructors::.)
  49.    The types that may be cast to the union type are those of the members
  50. of the union.  Thus, given the following union and variables:
  51.      union foo { int i; double d; };
  52.      int x;
  53.      double y;
  54. both `x' and `y' can be cast to type `union' foo.
  55.    Using the cast as the right-hand side of an assignment to a variable
  56. of union type is equivalent to storing in a member of the union:
  57.      union foo u;
  58.      ...
  59.      u = (union foo) x  ==  u.i = x
  60.      u = (union foo) y  ==  u.d = y
  61.    You can also use the union cast as a function argument:
  62.      void hack (union foo);
  63.      ...
  64.      hack ((union foo) x);
  65. File: gcc.info,  Node: Function Attributes,  Next: Function Prototypes,  Prev: Case Ranges,  Up: C Extensions
  66. Declaring Attributes of Functions
  67. =================================
  68.    In GNU C, you declare certain things about functions called in your
  69. program which help the compiler optimize function calls and check your
  70. code more carefully.
  71.    The keyword `__attribute__' allows you to specify special attributes
  72. when making a declaration.  This keyword is followed by an attribute
  73. specification inside double parentheses.  Four attributes, `noreturn',
  74. `const', `format', and `section' are currently defined for functions.
  75. Other attributes, including `section' are supported for variables
  76. declarations (*note Variable Attributes::.).
  77.    You may also specify attributes with `__' preceeding and following
  78. each keyword.  This allows you to use them in header files without
  79. being concerned about a possible macro of the same name.  For example,
  80. you may use `__noreturn__' instead of `noreturn'.
  81. `noreturn'
  82.      A few standard library functions, such as `abort' and `exit',
  83.      cannot return.  GNU CC knows this automatically.  Some programs
  84.      define their own functions that never return.  You can declare them
  85.      `noreturn' to tell the compiler this fact.  For example,
  86.           void fatal () __attribute__ ((noreturn));
  87.           
  88.           void
  89.           fatal (...)
  90.           {
  91.             ... /* Print error message. */ ...
  92.             exit (1);
  93.           }
  94.      The `noreturn' keyword tells the compiler to assume that `fatal'
  95.      cannot return.  It can then optimize without regard to what would
  96.      happen if `fatal' ever did return.  This makes slightly better
  97.      code.  More importantly, it helps avoid spurious warnings of
  98.      uninitialized variables.
  99.      Do not assume that registers saved by the calling function are
  100.      restored before calling the `noreturn' function.
  101.      It does not make sense for a `noreturn' function to have a return
  102.      type other than `void'.
  103.      The attribute `noreturn' is not implemented in GNU C versions
  104.      earlier than 2.5.  An alternative way to declare that a function
  105.      does not return, which works in the current version and in some
  106.      older versions, is as follows:
  107.           typedef void voidfn ();
  108.           
  109.           volatile voidfn fatal;
  110. `const'
  111.      Many functions do not examine any values except their arguments,
  112.      and have no effects except the return value.  Such a function can
  113.      be subject to common subexpression elimination and loop
  114.      optimization just as an arithmetic operator would be.  These
  115.      functions should be declared with the attribute `const'.  For
  116.      example,
  117.           int square (int) __attribute__ ((const));
  118.      says that the hypothetical function `square' is safe to call fewer
  119.      times than the program says.
  120.      The attribute `const' is not implemented in GNU C versions earlier
  121.      than 2.5.  An alternative way to declare that a function has no
  122.      side effects, which works in the current version and in some older
  123.      versions, is as follows:
  124.           typedef int intfn ();
  125.           
  126.           extern const intfn square;
  127.      This approach does not work in GNU C++ from 2.6.0 on, since the
  128.      language specifies that the `const' must be attached to the return
  129.      value.
  130.      Note that a function that has pointer arguments and examines the
  131.      data pointed to must *not* be declared `const'.  Likewise, a
  132.      function that calls a non-`const' function usually must not be
  133.      `const'.  It does not make sense for a `const' function to return
  134.      `void'.
  135. `format (ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)'
  136.      The `format' attribute specifies that a function takes `printf' or
  137.      `scanf' style arguments which should be type-checked against a
  138.      format string.  For example, the declaration:
  139.           extern int
  140.           my_printf (void *my_object, const char *my_format, ...)
  141.                 __attribute__ ((format (printf, 2, 3)));
  142.      causes the compiler to check the arguments in calls to `my_printf'
  143.      for consistency with the `printf' style format string argument
  144.      `my_format'.
  145.      The parameter ARCHETYPE determines how the format string is
  146.      interpreted, and should be either `printf' or `scanf'.  The
  147.      parameter STRING-INDEX specifies which argument is the format
  148.      string argument (starting from 1), while FIRST-TO-CHECK is the
  149.      number of the first argument to check against the format string.
  150.      For functions where the arguments are not available to be checked
  151.      (such as `vprintf'), specify the third parameter as zero.  In this
  152.      case the compiler only checks the format string for consistency.
  153.      In the example above, the format string (`my_format') is the second
  154.      argument of the function `my_print', and the arguments to check
  155.      start with the third argument, so the correct parameters for the
  156.      format attribute are 2 and 3.
  157.      The `format' attribute allows you to identify your own functions
  158.      which take format strings as arguments, so that GNU CC can check
  159.      the calls to these fun