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 >
GNU Info File  |  1994-02-06  |  48KB  |  820 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.49 from the input
  2. file gcc.texi.
  3.    This file documents the use and the internals of the GNU compiler.
  4.    Copyright (C) 1988, 1989, 1992 Free Software Foundation, Inc.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the sections entitled "GNU General Public License" and "Protect
  11. Your Freedom--Fight `Look And Feel'" are included exactly as in the
  12. original, and provided that the entire resulting derived work is
  13. distributed under the terms of a permission notice identical to this
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the sections entitled "GNU General Public
  17. License" and "Protect Your Freedom--Fight `Look And Feel'", and this
  18. permission notice, may be included in translations approved by the Free
  19. Software Foundation instead of in the original English.
  20. File: gcc.info,  Node: Function Attributes,  Next: Function Prototypes,  Prev: Case Ranges,  Up: Extensions
  21. Declaring Attributes of Functions
  22. =================================
  23.    In GNU C, you declare certain things about functions called in your
  24. program which help the compiler optimize function calls.
  25.    A few standard library functions, such as `abort' and `exit', cannot
  26. return.  GNU CC knows this automatically.  Some programs define their
  27. own functions that never return.  You can declare them `volatile' to
  28. tell the compiler this fact.  For example,
  29.      extern void volatile fatal ();
  30.      
  31.      void
  32.      fatal (...)
  33.      {
  34.        ... /* Print error message. */ ...
  35.        exit (1);
  36.      }
  37.    The `volatile' keyword tells the compiler to assume that `fatal'
  38. cannot return.  This makes slightly better code, but more importantly
  39. it helps avoid spurious warnings of uninitialized variables.
  40.    It does not make sense for a `volatile' function to have a return
  41. type other than `void'.
  42.    Many functions do not examine any values except their arguments, and
  43. have no effects except the return value.  Such a function can be subject
  44. to common subexpression elimination and loop optimization just as an
  45. arithmetic operator would be.  These functions should be declared
  46. `const'.  For example,
  47.      extern int const square ();
  48. says that the hypothetical function `square' is safe to call fewer
  49. times than the program says.
  50.    Note that a function that has pointer arguments and examines the data
  51. pointed to must *not* be declared `const'.  Likewise, a function that
  52. calls a non-`const' function usually must not be `const'.  It does not
  53. make sense for a `const' function to return `void'.
  54.    We recommend placing the keyword `const' after the function's return
  55. type.  It makes no difference in the example above, but when the return
  56. type is a pointer, it is the only way to make the function itself
  57. const.  For example,
  58.      const char *mincp (int);
  59. says that `mincp' returns `const char *'--a pointer to a const object. 
  60. To declare `mincp' const, you must write this:
  61.      char * const mincp (int);
  62.    Some people object to this feature, suggesting that ANSI C's
  63. `#pragma' should be used instead.  There are two reasons for not doing
  64. this.
  65.   1. It is impossible to generate `#pragma' commands from a macro.
  66.   2. The `#pragma' command is just as likely as these keywords to mean
  67.      something else in another compiler.
  68.    These two reasons apply to almost any application that might be
  69. proposed for `#pragma'.  It is basically a mistake to use `#pragma' for
  70. *anything*.
  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.  One attribute, `format', is
  74. currently defined for functions.  Others are implemented for variables
  75. and structure fields (*note Function Attributes::.).
  76. `format (ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)'
  77.      The `format' attribute specifies that a function takes `printf' or
  78.      `scanf' style arguments which should be type-checked against a
  79.      format string.  For example, the declaration:
  80.           extern int
  81.           my_printf (void *my_object, const char *my_format, ...)
  82.                 __attribute__ ((format (printf, 2, 3)));
  83.      causes the compiler to check the arguments in calls to `my_printf'
  84.      for consistency with the `printf' style format string argument
  85.      `my_format'.
  86.      The parameter ARCHETYPE determines how the format string is
  87.      interpreted, and should be either `printf' or `scanf'.  The
  88.      parameter STRING-INDEX specifies which argument is the format
  89.      string argument (starting from 1), while FIRST-TO-CHECK is the
  90.      number of the first argument to check against the format string. 
  91.      For functions where the arguments are not available to be checked
  92.      (such as `vprintf'), specify the third parameter as zero.  In this
  93.      case the compiler only checks the format string for consistency.
  94.      In the example above, the format string (`my_format') is the second
  95.      argument of the function `my_print', and the arguments to check
  96.      start with the third argument, so the correct parameters for the
  97.      format attribute are 2 and 3.
  98.      The `format' attribute allows you to identify your own functions
  99.      which take format strings as arguments, so that GNU CC can check
  100.      the calls to these functions for errors.  The compiler always
  101.      checks formats for the ANSI library functions `printf', `fprintf',
  102.      `sprintf', `scanf', `fscanf', `sscanf', `vprintf', `vfprintf' and
  103.      `vsprintf' whenever such warnings are requested (using
  104.      `-Wformat'), so there is no need to modify the header file
  105.      `stdio.h'.
  106. File: gcc.info,  Node: Function Prototypes,  Next: Dollar Signs,  Prev: Function Attributes,  Up: Extensions
  107. Prototypes and Old-Style Function Definitions
  108. =============================================
  109.    GNU C extends ANSI C to allow a function prototype to override a
  110. later old-style non-prototype definition.  Consider the following
  111. example:
  112.      /* Use prototypes unless the compiler is old-fashioned.  */
  113.      #if __STDC__
  114.      #define P(x) (x)
  115.      #else
  116.      #define P(x) ()
  117.      #endif
  118.      
  119.      /* Prototype function declaration.  */
  120.      int isroot P((uid_t));
  121.      
  122.      /* Old-style function definition.  */
  123.      int
  124.      isroot (x)   /* ??? lossage here ??? */
  125.           uid_t x;
  126.      {
  127.        return x == 0;
  128.      }
  129.    Suppose the type `uid_t' happens to be `short'.  ANSI C does not
  130. allow this example, because subword arguments in old-style
  131. non-prototype definitions are promoted.  Therefore in this example the
  132. function definition's argument is really an `int', which does not match
  133. the prototype argument type of `short'.
  134.    This restriction of ANSI C makes it hard to write code that is
  135. portable to traditional C compilers, because the programmer does not
  136. know whether the `uid_t' type is `short', `int', or `long'.  Therefore,
  137. in cases like these GNU C allows a prototype to override a later
  138. old-style definition.  More precisely, in GNU C, a function prototype
  139. argument type overrides the argument type specified by a later
  140. old-style definition if the former type is the same as the latter type
  141. before promotion.  Thus in GNU C the above example is equivalent to the
  142. following:
  143.      int isroot (uid_t);
  144.      
  145.      int
  146.      isroot (uid_t x)
  147.      {
  148.        return x == 0;
  149.      }
  150. File: gcc.info,  Node: Dollar Signs,  Next: Character Escapes,  Prev: Function Prototypes,  Up: Extensions
  151. Dollar Signs in Identifier Names
  152. ================================
  153.    In GNU C, you may use dollar signs in identifier names.  This is
  154. because many traditional C implementations allow such identifiers.
  155.    On some machines, dollar signs are allowed in identifiers if you
  156. specify `-traditional'.  On a few systems they are allowed by default,
  157. even if you do not use `-traditional'.  But they are never allowed if
  158. you specify `-ansi'.
  159.    There are certain ANSI C