home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / msdos / djgpp / docs / gcc / extend.tex < prev    next >
Encoding:
Text File  |  1993-05-29  |  89.0 KB  |  2,465 lines

  1. @c Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  2. @c This is part of the GCC manual.
  3. @c For copying conditions, see the file gcc.texi.
  4.  
  5. @node C Extensions
  6. @chapter Extensions to the C Language Family
  7. @cindex extensions, C language
  8. @cindex C language extensions
  9.  
  10. GNU C provides several language features not found in ANSI standard C.
  11. (The @samp{-pedantic} option directs GNU CC to print a warning message if
  12. any of these features is used.)  To test for the availability of these
  13. features in conditional compilation, check for a predefined macro
  14. @code{__GNUC__}, which is always defined under GNU CC.
  15.  
  16. These extensions are available in C and in the languages derived from
  17. it, C++ and Objective C.  @xref{C++ Extensions,,Extensions to the
  18. C++ Language}, for extensions that apply @emph{only} to C++.
  19.  
  20. @c The only difference between the two versions of this menu is that the
  21. @c version for clear INTERNALS has an extra node, "Constraints" (which
  22. @c appears in a separate chapter in the other version of the manual).
  23. @ifset INTERNALS
  24. @menu
  25. * Statement Exprs::     Putting statements and declarations inside expressions.
  26. * Local Labels::        Labels local to a statement-expression.
  27. * Labels as Values::    Getting pointers to labels, and computed gotos.
  28. * Nested Functions::    As in Algol and Pascal, lexical scoping of functions.
  29. * Constructing Calls::    Dispatching a call to another function.
  30. * Naming Types::        Giving a name to the type of some expression.
  31. * Typeof::              @code{typeof}: referring to the type of an expression.
  32. * Lvalues::             Using @samp{?:}, @samp{,} and casts in lvalues.
  33. * Conditionals::        Omitting the middle operand of a @samp{?:} expression.
  34. * Long Long::        Double-word integers---@code{long long int}.
  35. * Zero Length::         Zero-length arrays.
  36. * Variable Length::     Arrays whose length is computed at run time.
  37. * Macro Varargs::    Macros with variable number of arguments.
  38. * Subscripting::        Any array can be subscripted, even if not an lvalue.
  39. * Pointer Arith::       Arithmetic on @code{void}-pointers and function pointers.
  40. * Initializers::        Non-constant initializers.
  41. * Constructors::        Constructor expressions give structures, unions
  42.                          or arrays as values.
  43. * Labeled Elements::    Labeling elements of initializers.
  44. * Cast to Union::       Casting to union type from any member of the union.
  45. * Case Ranges::        `case 1 ... 9' and such.
  46. * Function Attributes:: Declaring that functions have no side effects,
  47.                          or that they can never return.
  48. * Function Prototypes:: Prototype declarations and old-style definitions.
  49. * Dollar Signs::        Dollar sign is allowed in identifiers.
  50. * Character Escapes::   @samp{\e} stands for the character @key{ESC}.
  51. * Variable Attributes::    Specifying attributes of variables.
  52. * Alignment::           Inquiring about the alignment of a type or variable.
  53. * Inline::              Defining inline functions (as fast as macros).
  54. * Extended Asm::        Assembler instructions with C expressions as operands.
  55.                          (With them you can define ``built-in'' functions.)
  56. * Asm Labels::          Specifying the assembler name to use for a C symbol.
  57. * Explicit Reg Vars::   Defining variables residing in specified registers.
  58. * Alternate Keywords::  @code{__const__}, @code{__asm__}, etc., for header files.
  59. * Incomplete Enums::    @code{enum foo;}, with details to follow.
  60. * Function Names::    Printable strings which are the name of the current
  61.              function.
  62. @end menu
  63. @end ifset
  64. @ifclear INTERNALS
  65. @menu
  66. * Statement Exprs::     Putting statements and declarations inside expressions.
  67. * Local Labels::        Labels local to a statement-expression.
  68. * Labels as Values::    Getting pointers to labels, and computed gotos.
  69. * Nested Functions::    As in Algol and Pascal, lexical scoping of functions.
  70. * Constructing Calls::    Dispatching a call to another function.
  71. * Naming Types::        Giving a name to the type of some expression.
  72. * Typeof::              @code{typeof}: referring to the type of an expression.
  73. * Lvalues::             Using @samp{?:}, @samp{,} and casts in lvalues.
  74. * Conditionals::        Omitting the middle operand of a @samp{?:} expression.
  75. * Long Long::        Double-word integers---@code{long long int}.
  76. * Zero Length::         Zero-length arrays.
  77. * Variable Length::     Arrays whose length is computed at run time.
  78. * Macro Varargs::    Macros with variable number of arguments.
  79. * Subscripting::        Any array can be subscripted, even if not an lvalue.
  80. * Pointer Arith::       Arithmetic on @code{void}-pointers and function pointers.
  81. * Initializers::        Non-constant initializers.
  82. * Constructors::        Constructor expressions give structures, unions
  83.                          or arrays as values.
  84. * Labeled Elements::    Labeling elements of initializers.
  85. * Cast to Union::       Casting to union type from any member of the union.
  86. * Case Ranges::        `case 1 ... 9' and such.
  87. * Function Attributes:: Declaring that functions have no side effects,
  88.                          or that they can never return.
  89. * Function Prototypes:: Prototype declarations and old-style definitions.
  90. * Dollar Signs::        Dollar sign is allowed in identifiers.
  91. * Character Escapes::   @samp{\e} stands for the character @key{ESC}.
  92. * Variable Attributes::    Specifying attributes of variables.
  93. * Alignment::           Inquiring about the alignment of a type or variable.
  94. * Inline::              Defining inline functions (as fast as macros).
  95. * Extended Asm::        Assembler instructions with C expressions as operands.
  96.                          (With them you can define ``built-in'' functions.)
  97. * Constraints::         Constraints for asm operands
  98. * Asm Labels::          Specifying the assembler name to use for a C symbol.
  99. * Explicit Reg Vars::   Defining variables residing in specified registers.
  100. * Alternate Keywords::  @code{__const__}, @code{__asm__}, etc., for header files.
  101. * Incomplete Enums::    @code{enum foo;}, with details to follow.
  102. * Function Names::    Printable strings which are the name of the current
  103.              function.
  104. @end menu
  105. @end ifclear
  106.  
  107. @node Statement Exprs
  108. @section Statements and Declarations in Expressions
  109. @cindex statements inside expressions
  110. @cindex declarations inside expressions
  111. @cindex expressions containing statements
  112. @cindex macros, statements in expressions
  113.  
  114. @c the above section title wrapped and causes an underfull hbox.. i
  115. @c changed it from "within" to "in". --mew 4feb93
  116.  
  117. A compound statement enclosed in parentheses may appear as an expression
  118. in GNU C.  This allows you to use loops, switches, and local variables
  119. within an expression.
  120.  
  121. Recall that a compound statement is a sequence of statements surrounded
  122. by braces; in this construct, parentheses go around the braces.  For
  123. example:
  124.  
  125. @example
  126. (@{ int y = foo (); int z;
  127.    if (y > 0) z = y;
  128.    else z = - y;
  129.    z; @})
  130. @end example
  131.  
  132. @noindent
  133. is a valid (though slightly more complex than necessary) expression
  134. for the absolute value of @code{foo ()}.
  135.  
  136. The last thing in the compound statement should be an expression
  137. followed by a semicolon; the value of this subexpression serves as the
  138. value of the entire construct.  (If you use some other kind of statement
  139. last within the braces, the construct has type @code{void}, and thus
  140. effectively no value.)
  141.  
  142. This feature is especially useful in making macro definitions ``safe'' (so
  143. that they evaluate each operand exactly once).  For example, the
  144. ``maximum'' function is commonly defined as a macro in standard C as
  145. follows:
  146.  
  147. @example
  148. #define max(a,b) ((a) > (b) ? (a) : (b))
  149. @end example
  150.  
  151. @noindent
  152. @cindex side effects, macro argument
  153. But this definition computes either @var{a} or @var{b} twice, with bad
  154. results if the operand has side effects.  In GNU C, if you know the
  155. type of the operands (here let's assume @code{int}), you can define
  156. the macro safely as follows:
  157.  
  158. @example
  159. #define maxint(a,b) \
  160.   (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
  161. @end example
  162.  
  163. Embedded statements are not allowed in constant expressions, such as
  164. the value of an enumeration constant, the width of a bit field, or
  165. the initial value of a static variable.
  166.  
  167. If you don't know the type of the operand, you can still do this, but you
  168. must use @code{typeof} (@pxref{Typeof}) or type naming (@pxref{Naming
  169. Types}).
  170.  
  171. @node Local Labels
  172. @section Locally Declared Labels
  173. @cindex local labels
  174. @cindex macros, local labels
  175.  
  176. Each statement expression is a scope in which @dfn{local labels} can be
  177. declared.  A local label is simply an identifier; you can jump to it
  178. with an ordinary @code{goto} statement, but only from within the
  179. statement expression it belongs to.
  180.  
  181. A local label declaration looks like this:
  182.  
  183. @example
  184. __label__ @var{label};
  185. @end example
  186.  
  187. @noindent
  188. or
  189.  
  190. @example
  191. __label__ @var{label1}, @var{label2}, @dots{};
  192. @end example
  193.  
  194. Local label declarations must come at the beginning of the statement
  195. expression, right after the @samp{(@{}, before any ordinary
  196. declarations.
  197.  
  198. The label declaration defines the label @emph{name}, but does not define
  199. the label itself.  You must do this in the usual way, with
  200. @code{@var{label}:}, within the statements of the statement expression.
  201.  
  202. The local label feature is useful because statement expressions are
  203. often used in macros.  If the macro contains nested loops, a @code{goto}
  204. can be useful for breaking out of them.  However, an ordinary label
  205. whose scope is the whole function cannot be used: if the macro can be
  206. expanded several times in one function, the label will be multiply
  207. defined in that function.  A local label avoids this problem.  For
  208. example:
  209.  
  210. @example
  211. #define SEARCH(array, target)                     \
  212. (@{                                               \
  213.   __label__ found;                                \
  214.   typeof (target) _SEARCH_target = (target);      \
  215.   typeof (*(array)) *_SEARCH_array = (array);     \
  216.   int i, j;                                       \
  217.   int value;                                      \
  218.   for (i = 0; i < max; i++)                       \
  219.     for (j = 0; j < max; j++)                     \
  220.       if (_SEARCH_array[i][j] == _SEARCH_target)  \
  221.         @{ value = i; goto found; @}              \
  222.   value = -1;                                     \
  223.  found:                                           \
  224.   value;                                          \
  225. @})
  226. @end example
  227.  
  228. @node Labels as Values
  229. @section Labels as Values
  230. @cindex labels as values
  231. @cindex computed gotos
  232. @cindex goto with computed label 
  233. @cindex address of a label
  234.  
  235. You can get the address of a label defined in the current function
  236. (or a containing function) with the unary operator @samp{&&}.  The
  237. value has type @code{void *}.  This value is a constant and can be used 
  238. wherever a constant of that type is valid.  For example:
  239.  
  240. @example
  241. void *ptr;
  242. @dots{}
  243. ptr = &&foo;
  244. @end example
  245.  
  246. To use these values, you need to be able to jump to one.  This is done
  247. with the computed goto statement@footnote{The analogous feature in
  248. Fortran is called an assigned goto, but that name seems inappropriate in
  249. C, where one can do more than simply store label addresses in label
  250. variables.}, @code{goto *@var{exp};}.  For example,
  251.  
  252. @example
  253. goto *ptr;
  254. @end example
  255.  
  256. @noindent
  257. Any expression of type @code{void *} is allowed.
  258.  
  259. One way of using these constants is in initializing a static array that
  260. will serve as a jump table:
  261.  
  262. @example
  263. static void *array[] = @{ &&foo, &&bar, &&hack @};
  264. @end example
  265.  
  266. Then you can select a label with indexing, like this:
  267.  
  268. @example
  269. goto *array[i];
  270. @end example
  271.  
  272. @noindent
  273. Note that this does not check whether the subscript is in bounds---array
  274. indexing in C never does that.
  275.  
  276. Such an array of label values serves a purpose much like that of the
  277. @code{switch} statement.  The @code{switch} statement is cleaner, so
  278. use that rather than an array unless the problem does not fit a
  279. @code{switch} statement very well.
  280.  
  281. Another use of label values is in an interpreter for threaded code.
  282. The labels within the interpreter function can be stored in the
  283. threaded code for super-fast dispatching.  
  284.  
  285. You can use this mechanism to jump to code in a different function.  If
  286. you do that, totally unpredictable things will happen.  The best way to
  287. avoid this is to store the label address only in automatic variables and
  288. never pass it as an argument.
  289.  
  290. @node Nested Functions
  291. @section Nested Functions
  292. @cindex nested functions
  293. @cindex downward funargs
  294. @cindex thunks
  295.  
  296. A @dfn{nested function} is a function defined inside another function.
  297. (Nested functions are not supported for GNU C++.)  The nested function's
  298. name is local to the block where it is defined.  For example, here we
  299. define a nested function named @code{square}, and call it twice:
  300. @c this example broke at the newline; not sure this is good, so i
  301. @c grouped it. --mew 18feb93 
  302.  
  303. @example
  304. @group
  305. foo (double a, double b)
  306. @{
  307.   double square (double z) @{ return z * z; @}
  308.  
  309.   return square (a) + square (b);
  310. @}
  311. @end group
  312. @end example
  313.  
  314. The nested function can access all the variables of the containing
  315. function that are visible at the point of its definition.  This is
  316. called @dfn{lexical scoping}.  For example, here we show a nested
  317. function which uses an inherited variable named @code{offset}:
  318.  
  319. @example
  320. bar (int *array, int offset, int size)
  321. @{
  322.   int access (int *array, int index)
  323.     @{ return array[index + offset]; @}
  324.   int i;
  325.   @dots{}
  326.   for (i = 0; i < size; i++)
  327.     @dots{} access (array, i) @dots{}
  328. @}
  329. @end example
  330.  
  331. Nested function definitions must appear in the same part of a function
  332. as variable definitions; that is, before the first line of code in the
  333. enclosing function.
  334.  
  335. It is possible to call the nested function from outside the scope of its
  336. name by storing its address or passing the address to another function:
  337.  
  338. @example
  339. hack (int *array, int size)
  340. @{
  341.   void store (int index, int value)
  342.     @{ array[index] = value; @}
  343.  
  344.   intermediate (store, size);
  345. @}
  346. @end example
  347.  
  348. Here, the function @code{intermediate} receives the address of
  349. @code{store} as an argument.  If @code{intermediate} calls
  350. @code{store}, the arguments given to @code{store} are used to store
  351. into @code{array}.  But this technique works only so long as the
  352. containing function (@code{hack}, in this example) does not exit.  If
  353. you try to call the nested function through its address after the
  354. containing function has exited, all hell will break loose.
  355.  
  356. GNU CC implements taking the address of a nested function using a
  357. technique called @dfn{trampolines}.  A paper describing them is
  358. available from @samp{maya.idiap.ch} in the file
  359. @file{pub/tmb/usenix88-lexic.ps.Z}.
  360.  
  361. A nested function can jump to a label inherited from a containing
  362. function, provided the label was explicitly declared in the containing
  363. function (@pxref{Local Labels}).  Such a jump returns instantly to the
  364. containing function, exiting the nested function which did the
  365. @code{goto} and any intermediate functions as well.  Here is an example:
  366.  
  367. @example
  368. @group
  369. bar (int *array, int offset, int size)
  370. @{
  371.   __label__ failure;
  372.   int access (int *array, int index)
  373.     @{
  374.       if (index > size)
  375.         goto failure;
  376.       return array[index + offset];
  377.     @}
  378.   int i;
  379.   @dots{}
  380.   for (i = 0; i < size; i++)
  381.     @dots{} access (array, i) @dots{}
  382.   @dots{}
  383.   return 0;
  384.  
  385.  /* @r{Control comes here from @code{access}
  386.     if it detects an error.}  */
  387.  failure:
  388.   return -1;
  389. @}
  390. @end group
  391. @end example
  392.  
  393. A nested function always has internal linkage.  Declaring one with
  394. @code{extern} is erroneous.  If you need to declare the nested function
  395. before its definition, use @code{auto} (which is otherwise meaningless
  396. for function declarations).
  397.  
  398. @example
  399. bar (int *array, int offset, int size)
  400. @{
  401.   __label__ failure;
  402.   auto int access (int *, int);
  403.   @dots{}
  404.   int access (int *array, int index)
  405.     @{
  406.       if (index > size)
  407.         goto failure;
  408.       return array[index + offset];
  409.     @}
  410.   @dots{}
  411. @}
  412. @end example
  413.  
  414. @node Constructing Calls
  415. @section Constructing Function Calls
  416. @cindex constructing calls
  417. @cindex forwarding calls
  418.  
  419. Using the built-in functions described below, you can record
  420. the arguments a function received, and call another function
  421. with the same arguments, without knowing the number or types
  422. of the arguments.
  423.  
  424. You can also record the return value of that function call,
  425. and later return that value, without knowing what data type
  426. the function tried to return (as long as your caller expects
  427. that data type).
  428.  
  429. @table @code
  430. @findex __builtin_apply_args
  431. @item __builtin_apply_args ()
  432. This built-in function returns a pointer of type @code{void *} to data
  433. describing how to perform a call with the same arguments as were passed
  434. to the current function.
  435.  
  436. The function saves the arg pointer register, structure value address,
  437. and all registers that might be used to pass arguments to a function
  438. into a block of memory allocated on the stack.  Then it returns the
  439. address of that block.
  440.  
  441. @findex __builtin_apply
  442. @item __builtin_apply (@var{function}, @var{arguments}, @var{size})
  443. This built-in function invokes @var{function} (type @code{void (*)()})
  444. with a copy of the parameters described by @var{arguments} (type
  445. @code{void *}) and @var{size} (type @code{int}).
  446.  
  447. The value of @var{arguments} should be the value returned by
  448. @code{__builtin_apply_args}.  The argument @var{size} specifies the size
  449. of the stack argument data, in bytes.
  450.  
  451. This function returns a pointer of type @code{void *} to data describing
  452. how to return whatever value was returned by @var{function}.  The data
  453. is saved in a block of memory allocated on the stack.
  454.  
  455. It is not always simple to compute the proper value for @var{size}.  The
  456. value is used by @code{__builtin_apply} to compute the amount of data
  457. that should be pushed on the stack and copied from the incoming argument
  458. area.
  459.  
  460. @findex __builtin_return
  461. @item __builtin_return (@var{result})
  462. This built-in function returns the value described by @var{result} from
  463. the containing function.  You should specify, for @var{result}, a value
  464. returned by @code{__builtin_apply}.
  465. @end table
  466.  
  467. @node Naming Types
  468. @section Naming an Expression's Type
  469. @cindex naming types
  470.  
  471. You can give a name to the type of an expression using a @code{typedef}
  472. declaration with an initializer.  Here is how to define @var{name} as a
  473. type name for the type of @var{exp}:
  474.  
  475. @example
  476. typedef @var{name} = @var{exp};
  477. @end example
  478.  
  479. This is useful in conjunction with the statements-within-expressions
  480. feature.  Here is how the two together can be used to define a safe
  481. ``maximum'' macro that operates on any arithmetic type:
  482.  
  483. @example
  484. #define max(a,b) \
  485.   (@{typedef _ta = (a), _tb = (b);  \
  486.     _ta _a = (a); _tb _b = (b);     \
  487.     _a > _b ? _a : _b; @})
  488. @end example
  489.  
  490. @cindex underscores in variables in macros
  491. @cindex @samp{_} in variables in macros
  492. @cindex local variables in macros
  493. @cindex variables, local, in macros
  494. @cindex macros, local variables in
  495.  
  496. The reason for using names that start with underscores for the local
  497. variables is to avoid conflicts with variable names that occur within the
  498. expressions that are substituted for @code{a} and @code{b}.  Eventually we
  499. hope to design a new form of declaration syntax that allows you to declare
  500. variables whose scopes start only after their initializers; this will be a
  501. more reliable way to prevent such conflicts.
  502.  
  503. @node Typeof
  504. @section Referring to a Type with @code{typeof}
  505. @findex typeof
  506. @findex sizeof
  507. @cindex macros, types of arguments
  508.  
  509. Another way to refer to the type of an expression is with @code{typeof}.
  510. The syntax of using of this keyword looks like @code{sizeof}, but the
  511. construct acts semantically like a type name defined with @code{typedef}.
  512.  
  513. There are two ways of writing the argument to @code{typeof}: with an
  514. expression or with a type.  Here is an example with an expression:
  515.  
  516. @example
  517. typeof (x[0](1))
  518. @end example
  519.  
  520. @noindent
  521. This assumes that @code{x} is an array of functions; the type described
  522. is that of the values of the functions.
  523.  
  524. Here is an example with a typename as the argument:
  525.  
  526. @example
  527. typeof (int *)
  528. @end example
  529.  
  530. @noindent
  531. Here the type described is that of pointers to @code{int}.
  532.  
  533. If you are writing a header file that must work when included in ANSI C
  534. programs, write @code{__typeof__} instead of @code{typeof}.
  535. @xref{Alternate Keywords}.
  536.  
  537. A @code{typeof}-construct can be used anywhere a typedef name could be
  538. used.  For example, you can use it in a declaration, in a cast, or inside
  539. of @code{sizeof} or @code{typeof}.
  540.  
  541. @itemize @bullet
  542. @item
  543. This declares @code{y} with the type of what @code{x} points to.
  544.  
  545. @example
  546. typeof (*x) y;
  547. @end example
  548.  
  549. @item
  550. This declares @code{y} as an array of such values.
  551.  
  552. @example
  553. typeof (*x) y[4];
  554. @end example
  555.  
  556. @item
  557. This declares @code{y} as an array of pointers to characters:
  558.  
  559. @example
  560. typeof (typeof (char *)[4]) y;
  561. @end example
  562.  
  563. @noindent
  564. It is equivalent to the following traditional C declaration:
  565.  
  566. @example
  567. char *y[4];
  568. @end example
  569.  
  570. To see the meaning of the declaration using @code{typeof}, and why it
  571. might be a useful way to write, let's rewrite it with these macros:
  572.  
  573. @example
  574. #define pointer(T)  typeof(T *)
  575. #define array(T, N) typeof(T [N])
  576. @end example
  577.  
  578. @noindent
  579. Now the declaration can be rewritten this way:
  580.  
  581. @example
  582. array (pointer (char), 4) y;
  583. @end example
  584.  
  585. @noindent
  586. Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
  587. pointers to @code{char}.
  588. @end itemize
  589.  
  590. @node Lvalues
  591. @section Generalized Lvalues
  592. @cindex compound expressions as lvalues
  593. @cindex expressions, compound, as lvalues
  594. @cindex conditional expressions as lvalues
  595. @cindex expressions, conditional, as lvalues
  596. @cindex casts as lvalues
  597. @cindex generalized lvalues
  598. @cindex lvalues, generalized
  599. @cindex extensions, @code{?:}
  600. @cindex @code{?:} extensions
  601. Compound expressions, conditional expressions and casts are allowed as
  602. lvalues provided their operands are lvalues.  This means that you can take
  603. their addresses or store values into them.
  604.  
  605. For example, a compound expression can be assigned, provided the last
  606. expression in the sequence is an lvalue.  These two expressions are
  607. equivalent:
  608.  
  609. @example
  610. (a, b) += 5
  611. a, (b += 5)
  612. @end example
  613.  
  614. Similarly, the address of the compound expression can be taken.  These two
  615. expressions are equivalent:
  616.  
  617. @example
  618. &(a, b)
  619. a, &b
  620. @end example
  621.  
  622. A conditional expression is a valid lvalue if its type is not void and the
  623. true and false branches are both valid lvalues.  For example, these two
  624. expressions are equivalent:
  625.  
  626. @example
  627. (a ? b : c) = 5
  628. (a ? b = 5 : (c = 5))
  629. @end example
  630.  
  631. A cast is a valid lvalue if its operand is an lvalue.  A simple
  632. assignment whose left-hand side is a cast works by converting the
  633. right-hand side first to the specified type, then to the type of the
  634. inner left-hand side expression.  After this is stored, the value is
  635. converted back to the specified type to become the value of the
  636. assignment.  Thus, if @code{a} has type @code{char *}, the following two
  637. expressions are equivalent:
  638.  
  639. @example
  640. (int)a = 5
  641. (int)(a = (char *)(int)5)
  642. @end example
  643.  
  644. An assignment-with-arithmetic operation such as @samp{+=} applied to a cast
  645. performs the arithmetic using the type resulting from the cast, and then
  646. continues as in the previous case.  Therefore, these two expressions are
  647. equivalent:
  648.  
  649. @example
  650. (int)a += 5
  651. (int)(a = (char *)(int) ((int)a + 5))
  652. @end example
  653.  
  654. You cannot take the address of an lvalue cast, because the use of its
  655. address would not work out coherently.  Suppose that @code{&(int)f} were
  656. permitted, where @code{f} has type @code{float}.  Then the following
  657. statement would try to store an integer bit-pattern where a floating
  658. point number belongs:
  659.  
  660. @example
  661. *&(int)f = 1;
  662. @end example
  663.  
  664. This is quite different from what @code{(int)f = 1} would do---that
  665. would convert 1 to floating point and store it.  Rather than cause this
  666. inconsistency, we think it is better to prohibit use of @samp{&} on a cast.
  667.  
  668. If you really do want an @code{int *} pointer with the address of
  669. @code{f}, you can simply write @code{(int *)&f}.
  670.  
  671. @c this makes an underfull hbox; any ideas?  --mew 27jan93
  672. @c Now fixed --bob 5feb93
  673. @c Old text, page 98, was:
  674. @c Conditional Expressions with Omitted Operands
  675. @node Conditionals
  676. @section Conditionals with Omitted Operands
  677. @cindex conditional expressions, extensions
  678. @cindex omitted middle-operands
  679. @cindex middle-operands, omitted
  680. @cindex extensions, @code{?:}
  681. @cindex @code{?:} extensions
  682.  
  683. The middle operand in a conditional expression may be omitted.  Then
  684. if the first operand is nonzero, its value is the value of the conditional
  685. expression.
  686.  
  687. Therefore, the expression
  688.  
  689. @example
  690. x ? : y
  691. @end example
  692.  
  693. @noindent
  694. has the value of @code{x} if that is nonzero; otherwise, the value of
  695. @code{y}.
  696.  
  697. This example is perfectly equivalent to
  698.  
  699. @example
  700. x ? x : y
  701. @end example
  702.  
  703. @cindex side effect in ?:
  704. @cindex ?: side effect
  705. @noindent
  706. In this simple case, the ability to omit the middle operand is not
  707. especially useful.  When it becomes useful is when the first operand does,
  708. or may (if it is a macro argument), contain a side effect.  Then repeating
  709. the operand in the middle would perform the side effect twice.  Omitting
  710. the middle operand uses the value already computed without the undesirable
  711. effects of recomputing it.
  712.  
  713. @node Long Long
  714. @section Double-Word Integers
  715. @cindex @code{long long} data types
  716. @cindex double-word arithmetic
  717. @cindex multiprecision arithmetic
  718.  
  719. GNU C supports data types for integers that are twice as long as
  720. @code{long int}.  Simply write @code{long long int} for a signed
  721. integer, or @code{unsigned long long int} for an unsigned integer.
  722. To make an integer constant of type @code{long long int}, add the suffix
  723. @code{LL} to the integer.  To make an integer constant of type
  724. @code{unsigned long long int}, add the suffix @code{ULL} to the integer.
  725.  
  726. You can use these types in arithmetic like any other integer types.
  727. Addition, subtraction, and bitwise boolean operations on these types
  728. are open-coded on all types of machines.  Multiplication is open-coded
  729. if the machine supports fullword-to-doubleword a widening multiply
  730. instruction.  Division and shifts are open-coded only on machines that
  731. provide special support.  The operations that are not open-coded use
  732. special library routines that come with GNU CC.
  733.  
  734. There may be pitfalls when you use @code{long long} types for function
  735. arguments, unless you declare function prototypes.  If a function
  736. expects type @code{int} for its argument, and you pass a value of type
  737. @code{long long int}, confusion will result because the caller and the
  738. subroutine will disagree about the number of bytes for the argument.
  739. Likewise, if the function expects @code{long long int} and you pass
  740. @code{int}.  The best way to avoid such problems is to use prototypes.
  741.  
  742. @node Zero Length
  743. @section Arrays of Length Zero
  744. @cindex arrays of length zero
  745. @cindex zero-length arrays
  746. @cindex length-zero arrays
  747.  
  748. Zero-length arrays are allowed in GNU C.  They are very useful as the last
  749. element of a structure which is really a header for a variable-length
  750. object:
  751.  
  752. @example
  753. struct line @{
  754.   int length;
  755.   char contents[0];
  756. @};
  757.  
  758. @{
  759.   struct line *thisline = (struct line *)
  760.     malloc (sizeof (struct line) + this_length);
  761.   thisline->length = this_length;
  762. @}
  763. @end example
  764.  
  765. In standard C, you would have to give @code{contents} a length of 1, which
  766. means either you waste space or complicate the argument to @code{malloc}.
  767.  
  768. @node Variable Length
  769. @section Arrays of Variable Length
  770. @cindex variable-length arrays
  771. @cindex arrays of variable length
  772.  
  773. Variable-length automatic arrays are allowed in GNU C.  These arrays are
  774. declared like any other automatic arrays, but with a length that is not
  775. a constant expression.  The storage is allocated at the point of
  776. declaration and deallocated when the brace-level is exited.  For
  777. example:
  778.  
  779. @example
  780. FILE *
  781. concat_fopen (char *s1, char *s2, char *mode)
  782. @{
  783.   char str[strlen (s1) + strlen (s2) + 1];
  784.   strcpy (str, s1);
  785.   strcat (str, s2);
  786.   return fopen (str, mode);
  787. @}
  788. @end example
  789.  
  790. @cindex scope of a variable length array
  791. @cindex variable-length array scope
  792. @cindex deallocating variable length arrays
  793. Jumping or breaking out of the scope of the array name deallocates the
  794. storage.  Jumping into the scope is not allowed; you get an error
  795. message for it.
  796.  
  797. @cindex @code{alloca} vs variable-length arrays
  798. You can use the function @code{alloca} to get an effect much like
  799. variable-length arrays.  The function @code{alloca} is available in
  800. many other C implementations (but not in all).  On the other hand,
  801. variable-length arrays are more elegant.
  802.  
  803. There are other differences between these two methods.  Space allocated
  804. with @code{alloca} exists until the containing @emph{function} returns.
  805. The space for a variable-length array is deallocated as soon as the array
  806. name's scope ends.  (If you use both variable-length arrays and
  807. @code{alloca} in the same function, deallocation of a variable-length array
  808. will also deallocate anything more recently allocated with @code{alloca}.)
  809.  
  810. You can also use variable-length arrays as arguments to functions:
  811.  
  812. @example
  813. struct entry
  814. tester (int len, char data[len][len])
  815. @{
  816.   @dots{}
  817. @}
  818. @end example
  819.  
  820. The length of an array is computed once when the storage is allocated
  821. and is remembered for the scope of the array in case you access it with
  822. @code{sizeof}.
  823.  
  824. If you want to pass the array first and the length afterward, you can
  825. use a forward declaration in the parameter list---another GNU extension.
  826.  
  827. @example
  828. struct entry
  829. tester (int len; char data[len][len], int len)
  830. @{
  831.   @dots{}
  832. @}
  833. @end example
  834.  
  835. @cindex parameter forward declaration
  836. The @samp{int len} before the semicolon is a @dfn{parameter forward
  837. declaration}, and it serves the purpose of making the name @code{len}
  838. known when the declaration of @code{data} is parsed.
  839.  
  840. You can write any number of such parameter forward declarations in the
  841. parameter list.  They can be separated by commas or semicolons, but the
  842. last one must end with a semicolon, which is followed by the ``real''
  843. parameter declarations.  Each forward declaration must match a ``real''
  844. declaration in parameter name and data type.
  845.  
  846. @node Macro Varargs
  847. @section Macros with Variable Numbers of Arguments
  848. @cindex variable number of arguments
  849. @cindex macro with variable arguments
  850. @cindex rest argument (in macro)
  851.  
  852. In GNU C, a macro can accept a variable number of arguments, much as a
  853. function can.  The syntax for defining the macro looks much like that
  854. used for a function.  Here is an example:
  855.  
  856. @example
  857. #define eprintf(format, args...)  \
  858.  fprintf (stderr, format , ## args)
  859. @end example
  860.  
  861. Here @code{args} is a @dfn{rest argument}: it takes in zero or more
  862. arguments, as many as the call contains.  All of them plus the commas
  863. between them form the value of @code{args}, which is substituted into
  864. the macro body where @code{args} is used.  Thus, we have this expansion:
  865.  
  866. @example
  867. eprintf ("%s:%d: ", input_file_name, line_number)
  868. @expansion{}
  869. fprintf (stderr, "%s:%d: " , input_file_name, line_number)
  870. @end example
  871.  
  872. @noindent
  873. Note that the comma after the string constant comes from the definition
  874. of @code{eprintf}, whereas the last comma comes from the value of
  875. @code{args}.
  876.  
  877. The reason for using @samp{##} is to handle the case when @code{args}
  878. matches no arguments at all.  In this case, @code{args} has an empty
  879. value.  In this case, the second comma in the definition becomes an
  880. embarrassment: if it got through to the expansion of the macro, we would
  881. get something like this:
  882.  
  883. @example
  884. fprintf (stderr, "success!\n" , )
  885. @end example
  886.  
  887. @noindent
  888. which is invalid C syntax.  @samp{##} gets rid of the comma, so we get
  889. the following instead:
  890.  
  891. @example
  892. fprintf (stderr, "success!\n")
  893. @end example
  894.  
  895. This is a special feature of the GNU C preprocessor: @samp{##} before a
  896. rest argument that is empty discards the preceding sequence of
  897. non-whitespace characters from the macro definition.  (If another macro
  898. argument precedes, none of it is discarded.)
  899.  
  900. It might be better to discard the last preprocessor token instead of the
  901. last preceding sequence of non-whitespace characters; in fact, we may
  902. someday change this feature to do so.  We advise you to write the macro
  903. definition so that the preceding sequence of non-whitespace characters
  904. is just a single token, so that the meaning will not change if we change
  905. the definition of this feature.
  906.  
  907. @node Subscripting
  908. @section Non-Lvalue Arrays May Have Subscripts
  909. @cindex subscripting
  910. @cindex arrays, non-lvalue
  911.  
  912. @cindex subscripting and function values
  913. Subscripting is allowed on arrays that are not lvalues, even though the
  914. unary @samp{&} operator is not.  For example, this is valid in GNU C though
  915. not valid in other C dialects:
  916.  
  917. @example
  918. struct foo @{int a[4];@};
  919.  
  920. struct foo f();
  921.  
  922. bar (int index)
  923. @{
  924.   return f().a[index];
  925. @}
  926. @end example
  927.  
  928. @node Pointer Arith
  929. @section Arithmetic on @code{void}- and Function-Pointers
  930. @cindex void pointers, arithmetic
  931. @cindex void, size of pointer to
  932. @cindex function pointers, arithmetic
  933. @cindex function, size of pointer to
  934.  
  935. In GNU C, addition and subtraction operations are supported on pointers to
  936. @code{void} and on pointers to functions.  This is done by treating the
  937. size of a @code{void} or of a function as 1.
  938.  
  939. A consequence of this is that @code{sizeof} is also allowed on @code{void}
  940. and on function types, and returns 1.
  941.  
  942. The option @samp{-Wpointer-arith} requests a warning if these extensions
  943. are used.
  944.  
  945. @node Initializers
  946. @section Non-Constant Initializers
  947. @cindex initializers, non-constant
  948. @cindex non-constant initializers
  949.  
  950. The elements of an aggregate initializer for an automatic variable are
  951. not required to be constant expressions in GNU C.  Here is an example of
  952. an initializer with run-time varying elements:
  953.  
  954. @example
  955. foo (float f, float g)
  956. @{
  957.   float beat_freqs[2] = @{ f-g, f+g @};
  958.   @dots{}
  959. @}
  960. @end example
  961.  
  962. @node Constructors
  963. @section Constructor Expressions
  964. @cindex constructor expressions
  965. @cindex initializations in expressions
  966. @cindex structures, constructor expression
  967. @cindex expressions, constructor 
  968.  
  969. GNU C supports constructor expressions.  A constructor looks like
  970. a cast containing an initializer.  Its value is an object of the
  971. type specified in the cast, containing the elements specified in
  972. the initializer.
  973.  
  974. Usually, the specified type is a structure.  Assume that
  975. @code{struct foo} and @code{structure} are declared as shown:
  976.  
  977. @example
  978. struct foo @{int a; char b[2];@} structure;
  979. @end example
  980.  
  981. @noindent
  982. Here is an example of constructing a @code{struct foo} with a constructor:
  983.  
  984. @example
  985. structure = ((struct foo) @{x + y, 'a', 0@});
  986. @end example
  987.  
  988. @noindent
  989. This is equivalent to writing the following:
  990.  
  991. @example
  992. @{
  993.   struct foo temp = @{x + y, 'a', 0@};
  994.   structure = temp;
  995. @}
  996. @end example
  997.  
  998. You can also construct an array.  If all the elements of the constructor
  999. are (made up of) simple constant expressions, suitable for use in
  1000. initializers, then the constructor is an lvalue and can be coerced to a
  1001. pointer to its first element, as shown here:
  1002.  
  1003. @example
  1004. char **foo = (char *[]) @{ "x", "y", "z" @};
  1005. @end example
  1006.  
  1007. Array constructors whose elements are not simple constants are
  1008. not very useful, because the constructor is not an lvalue.  There
  1009. are only two valid ways to use it: to subscript it, or initialize
  1010. an array variable with it.  The former is probably slower than a
  1011. @code{switch} statement, while the latter does the same thing an
  1012. ordinary C initializer would do.  Here is an example of
  1013. subscripting an array constructor:
  1014.  
  1015. @example
  1016. output = ((int[]) @{ 2, x, 28 @}) [input];
  1017. @end example
  1018.  
  1019. Constructor expressions for scalar types and union types are is
  1020. also allowed, but then the constructor expression is equivalent
  1021. to a cast.
  1022.  
  1023. @node Labeled Elements
  1024. @section Labeled Elements in Initializers
  1025. @cindex initializers with labeled elements
  1026. @cindex labeled elements in initializers
  1027. @cindex case labels in initializers
  1028.  
  1029. Standard C requires the elements of an initializer to appear in a fixed
  1030. order, the same as the order of the elements in the array or structure
  1031. being initialized.
  1032.  
  1033. In GNU C you can give the elements in any order, specifying the array
  1034. indices or structure field names they apply to.
  1035.  
  1036. To specify an array index, write @samp{[@var{index}]} before the
  1037. element value.  For example,
  1038.  
  1039. @example
  1040. int a[6] = @{ [4] 29, [2] 15 @};
  1041. @end example
  1042.  
  1043. @noindent
  1044. is equivalent to
  1045.  
  1046. @example
  1047. int a[6] = @{ 0, 0, 15, 0, 29, 0 @};
  1048. @end example
  1049.  
  1050. @noindent
  1051. The index values must be constant expressions, even if the array being
  1052. initialized is automatic.
  1053.  
  1054. In a structure initializer, specify the name of a field to initialize
  1055. with @samp{@var{fieldname}:} before the element value.  For example,
  1056. given the following structure, 
  1057.  
  1058. @example
  1059. struct point @{ int x, y; @};
  1060. @end example
  1061.  
  1062. @noindent
  1063. the following initialization
  1064.  
  1065. @example
  1066. struct point p = @{ y: yvalue, x: xvalue @};
  1067. @end example
  1068.  
  1069. @noindent
  1070. is equivalent to
  1071.  
  1072. @example
  1073. struct point p = @{ xvalue, yvalue @};
  1074. @end example
  1075.  
  1076. You can also use an element label when initializing a union, to
  1077. specify which element of the union should be used.  For example,
  1078.  
  1079. @example
  1080. union foo @{ int i; double d; @};
  1081.  
  1082. union foo f = @{ d: 4 @};
  1083. @end example
  1084.  
  1085. @noindent
  1086. will convert 4 to a @code{double} to store it in the union using
  1087. the second element.  By contrast, casting 4 to type @code{union foo}
  1088. would store it into the union as the integer @code{i}, since it is
  1089. an integer.  (@xref{Cast to Union}.)
  1090.  
  1091. You can combine this technique of naming elements with ordinary C
  1092. initialization of successive elements.  Each initializer element that
  1093. does not have a label applies to the next consecutive element of the
  1094. array or structure.  For example,
  1095.  
  1096. @example
  1097. int a[6] = @{ [1] v1, v2, [4] v4 @};
  1098. @end example
  1099.  
  1100. @noindent
  1101. is equivalent to
  1102.  
  1103. @example
  1104. int a[6] = @{ 0, v1, v2, 0, v4, 0 @};
  1105. @end example
  1106.  
  1107. Labeling the elements of an array initializer is especially useful
  1108. when the indices are characters or belong to an @code{enum} type.
  1109. For example:
  1110.  
  1111. @example
  1112. int whitespace[256]
  1113.   = @{ [' '] 1, ['\t'] 1, ['\h'] 1,
  1114.       ['\f'] 1, ['\n'] 1, ['\r'] 1 @};
  1115. @end example
  1116.  
  1117. @node Case Ranges
  1118. @section Case Ranges
  1119. @cindex case ranges
  1120. @cindex ranges in case statements
  1121.  
  1122. You can specify a range of consecutive values in a single @code{case} label,
  1123. like this:
  1124.  
  1125. @example
  1126. case @var{low} ... @var{high}:
  1127. @end example
  1128.  
  1129. @noindent
  1130. This has the same effect as the proper number of individual @code{case}
  1131. labels, one for each integer value from @var{low} to @var{high}, inclusive.
  1132.  
  1133. This feature is especially useful for ranges of ASCII character codes:
  1134.  
  1135. @example
  1136. case 'A' ... 'Z':
  1137. @end example
  1138.  
  1139. @strong{Be careful:} Write spaces around the @code{...}, for otherwise
  1140. it may be parsed wrong when you use it with integer values.  For example,
  1141. write this:
  1142.  
  1143. @example
  1144. case 1 ... 5:
  1145. @end example
  1146.  
  1147. @noindent 
  1148. rather than this:
  1149.  
  1150. @example
  1151. case 1...5:
  1152. @end example
  1153.  
  1154. @quotation
  1155. @emph{Warning to C++ users:} When compiling C++, you must write two dots
  1156. @samp{..} rather than three to specify a range in case statements, thus:
  1157.  
  1158. @example
  1159. case 'A' .. 'Z':
  1160. @end example
  1161.  
  1162. @noindent
  1163. This is an anachronism in the GNU C++ front end, and will be rectified
  1164. in a future release.
  1165. @end quotation
  1166.  
  1167. @node Cast to Union
  1168. @section Cast to a Union Type
  1169. @cindex cast to a union
  1170. @cindex union, casting to a 
  1171.  
  1172. A cast to union type is similar to other casts, except that the type
  1173. specified is a union type.  You can specify the type either with
  1174. @code{union @var{tag}} or with a typedef name.  A cast to union is actually
  1175. a constructor though, not a cast, and hence does not yield an lvalue like
  1176. normal casts.  (@xref{Constructors}.)
  1177.  
  1178. The types that may be cast to the union type are those of the members
  1179. of the union.  Thus, given the following union and variables:
  1180.  
  1181. @example
  1182. union foo @{ int i; double d; @};
  1183. int x;
  1184. double y;
  1185. @end example
  1186.  
  1187. @noindent
  1188. both @code{x} and @code{y} can be cast to type @code{union} foo.
  1189.  
  1190. Using the cast as the right-hand side of an assignment to a variable of
  1191. union type is equivalent to storing in a member of the union:
  1192.  
  1193. @example
  1194. union foo u;
  1195. @dots{}
  1196. u = (union foo) x  @equiv{}  u.i = x
  1197. u = (union foo) y  @equiv{}  u.d = y
  1198. @end example
  1199.  
  1200. You can also use the union cast as a function argument:
  1201.  
  1202. @example
  1203. void hack (union foo);
  1204. @dots{}
  1205. hack ((union foo) x);
  1206. @end example
  1207.  
  1208. @node Function Attributes
  1209. @section Declaring Attributes of Functions
  1210. @cindex function attributes
  1211. @cindex declaring attributes of functions
  1212. @cindex functions that never return
  1213. @cindex functions that have no side effects
  1214. @cindex @code{volatile} applied to function
  1215. @cindex @code{const} applied to function
  1216.  
  1217. In GNU C, you declare certain things about functions called in your program
  1218. which help the compiler optimize function calls.
  1219.  
  1220. A few standard library functions, such as @code{abort} and @code{exit},
  1221. cannot return.  GNU CC knows this automatically.  Some programs define
  1222. their own functions that never return.  You can declare them
  1223. @code{volatile} to tell the compiler this fact.  For example,
  1224.  
  1225. @smallexample
  1226. extern void volatile fatal ();
  1227.  
  1228. void
  1229. fatal (@dots{})
  1230. @{
  1231.   @dots{} /* @r{Print error message.} */ @dots{}
  1232.   exit (1);
  1233. @}
  1234. @end smallexample
  1235.  
  1236. The @code{volatile} keyword tells the compiler to assume that
  1237. @code{fatal} cannot return.  This makes slightly better code, but more
  1238. importantly it helps avoid spurious warnings of uninitialized variables.
  1239.  
  1240. It does not make sense for a @code{volatile} function to have a return
  1241. type other than @code{void}.
  1242.  
  1243. Many functions do not examine any values except their arguments, and
  1244. have no effects except the return value.  Such a function can be subject
  1245. to common subexpression elimination and loop optimization just as an
  1246. arithmetic operator would be.  These functions should be declared
  1247. @code{const}.  For example,
  1248.  
  1249. @smallexample
  1250. extern int const square ();
  1251. @end smallexample
  1252.  
  1253. @noindent
  1254. says that the hypothetical function @code{square} is safe to call
  1255. fewer times than the program says.
  1256.  
  1257. @cindex pointer arguments
  1258. Note that a function that has pointer arguments and examines the data
  1259. pointed to must @emph{not} be declared @code{const}.  Likewise, a
  1260. function that calls a non-@code{const} function usually must not be
  1261. @code{const}.  It does not make sense for a @code{const} function to
  1262. return @code{void}.
  1263.  
  1264. We recommend placing the keyword @code{const} after the function's
  1265. return type.  It makes no difference in the example above, but when the
  1266. return type is a pointer, it is the only way to make the function itself
  1267. const.  For example,
  1268.  
  1269. @smallexample
  1270. const char *mincp (int);
  1271. @end smallexample
  1272.  
  1273. @noindent
  1274. says that @code{mincp} returns @code{const char *}---a pointer to a
  1275. const object.  To declare @code{mincp} const, you must write this:
  1276.  
  1277. @smallexample
  1278. char * const mincp (int);
  1279. @end smallexample
  1280.   
  1281. @cindex @code{#pragma}, reason for not using
  1282. @cindex pragma, reason for not using
  1283. Some people object to this feature, suggesting that ANSI C's
  1284. @code{#pragma} should be used instead.  There are two reasons for not
  1285. doing this.
  1286.  
  1287. @enumerate
  1288. @item
  1289. It is impossible to generate @code{#pragma} commands from a macro.
  1290.  
  1291. @item
  1292. The @code{#pragma} command is just as likely as these keywords to mean
  1293. something else in another compiler.
  1294. @end enumerate
  1295.  
  1296. These two reasons apply to almost any application that might be proposed
  1297. for @code{#pragma}.  It is basically a mistake to use @code{#pragma} for
  1298. @emph{anything}.
  1299.  
  1300. The keyword @code{__attribute__} allows you to specify special
  1301. attributes when making a declaration.  This keyword is followed by an
  1302. attribute specification inside double parentheses.  One attribute,
  1303. @code{format}, is currently defined for functions.  Others are
  1304. implemented for variables and structure fields (@pxref{Function
  1305. Attributes}).
  1306.  
  1307. @table @code
  1308. @item format (@var{archetype}, @var{string-index}, @var{first-to-check})
  1309. @cindex @code{format} attribute
  1310. The @code{format} attribute specifies that a function takes @code{printf}
  1311. or @code{scanf} style arguments which should be type-checked against a
  1312. format string.  For example, the declaration:
  1313.  
  1314. @smallexample
  1315. extern int
  1316. my_printf (void *my_object, const char *my_format, ...)
  1317.       __attribute__ ((format (printf, 2, 3)));
  1318. @end smallexample
  1319.  
  1320. @noindent
  1321. causes the compiler to check the arguments in calls to @code{my_printf}
  1322. for consistency with the @code{printf} style format string argument
  1323. @code{my_format}.
  1324.  
  1325. The parameter @var{archetype} determines how the format string is
  1326. interpreted, and should be either @code{printf} or @code{scanf}.  The
  1327. parameter @var{string-index} specifies which argument is the format
  1328. string argument (starting from 1), while @var{first-to-check} is the
  1329. number of the first argument to check against the format string.  For
  1330. functions where the arguments are not available to be checked (such as
  1331. @code{vprintf}), specify the third parameter as zero.  In this case the
  1332. compiler only checks the format string for consistency.
  1333.  
  1334. In the example above, the format string (@code{my_format}) is the second
  1335. argument of the function @code{my_print}, and the arguments to check
  1336. start with the third argument, so the correct parameters for the format
  1337. attribute are 2 and 3.
  1338.  
  1339. The @code{format} attribute allows you to identify your own functions
  1340. which take format strings as arguments, so that GNU CC can check the
  1341. calls to these functions for errors.  The compiler always checks formats
  1342. for the ANSI library functions @code{printf}, @code{fprintf},
  1343. @code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf},
  1344. @code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such
  1345. warnings are requested (using @samp{-Wformat}), so there is no need to
  1346. modify the header file @file{stdio.h}.
  1347. @end table
  1348.  
  1349. @node Function Prototypes
  1350. @section Prototypes and Old-Style Function Definitions
  1351. @cindex function prototype declarations
  1352. @cindex old-style function definitions
  1353. @cindex promotion of formal parameters
  1354.  
  1355. GNU C extends ANSI C to allow a function prototype to override a later
  1356. old-style non-prototype definition.  Consider the following example:
  1357.  
  1358. @example
  1359. /* @r{Use prototypes unless the compiler is old-fashioned.}  */
  1360. #if __STDC__
  1361. #define P(x) (x)
  1362. #else
  1363. #define P(x) ()
  1364. #endif
  1365.  
  1366. /* @r{Prototype function declaration.}  */
  1367. int isroot P((uid_t));
  1368.  
  1369. /* @r{Old-style function definition.}  */
  1370. int
  1371. isroot (x)   /* ??? lossage here ??? */
  1372.      uid_t x;
  1373. @{
  1374.   return x == 0;
  1375. @}
  1376. @end example
  1377.  
  1378. Suppose the type @code{uid_t} happens to be @code{short}.  ANSI C does
  1379. not allow this example, because subword arguments in old-style
  1380. non-prototype definitions are promoted.  Therefore in this example the
  1381. function definition's argument is really an @code{int}, which does not
  1382. match the prototype argument type of @code{short}.
  1383.  
  1384. This restriction of ANSI C makes it hard to write code that is portable
  1385. to traditional C compilers, because the programmer does not know
  1386. whether the @code{uid_t} type is @code{short}, @code{int}, or
  1387. @code{long}.  Therefore, in cases like these GNU C allows a prototype
  1388. to override a later old-style definition.  More precisely, in GNU C, a
  1389. function prototype argument type overrides the argument type specified
  1390. by a later old-style definition if the former type is the same as the
  1391. latter type before promotion.  Thus in GNU C the above example is
  1392. equivalent to the following:
  1393.  
  1394. @example
  1395. int isroot (uid_t);
  1396.  
  1397. int
  1398. isroot (uid_t x)
  1399. @{
  1400.   return x == 0;
  1401. @}
  1402. @end example
  1403.  
  1404. @node Dollar Signs
  1405. @section Dollar Signs in Identifier Names
  1406. @cindex $
  1407. @cindex dollar signs in identifier names
  1408. @cindex identifier names, dollar signs in
  1409.  
  1410. In GNU C, you may use dollar signs in identifier names.  This is because
  1411. many traditional C implementations allow such identifiers.
  1412.  
  1413. On some machines, dollar signs are allowed in identifiers if you specify
  1414. @w{@samp{-traditional}}.  On a few systems they are allowed by default,
  1415. even if you do not use @w{@samp{-traditional}}.  But they are never
  1416. allowed if you specify @w{@samp{-ansi}}.
  1417.  
  1418. There are certain ANSI C programs (obscure, to be sure) that would
  1419. compile incorrectly if dollar signs were permitted in identifiers.  For
  1420. example:
  1421.  
  1422. @example
  1423. #define foo(a) #a
  1424. #define lose(b) foo (b)
  1425. #define test$
  1426. lose (test)
  1427. @end example
  1428.  
  1429. @node Character Escapes
  1430. @section The Character @key{ESC} in Constants
  1431.  
  1432. You can use the sequence @samp{\e} in a string or character constant to
  1433. stand for the ASCII character @key{ESC}.
  1434.  
  1435. @node Alignment
  1436. @section Inquiring on Alignment of Types or Variables
  1437. @cindex alignment
  1438. @cindex type alignment
  1439. @cindex variable alignment
  1440.  
  1441. The keyword @code{__alignof__} allows you to inquire about how an object
  1442. is aligned, or the minimum alignment usually required by a type.  Its
  1443. syntax is just like @code{sizeof}.
  1444.  
  1445. For example, if the target machine requires a @code{double} value to be
  1446. aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.
  1447. This is true on many RISC machines.  On more traditional machine
  1448. designs, @code{__alignof__ (double)} is 4 or even 2.
  1449.  
  1450. Some machines never actually require alignment; they allow reference to any
  1451. data type even at an odd addresses.  For these machines, @code{__alignof__}
  1452. reports the @emph{recommended} alignment of a type.
  1453.  
  1454. When the operand of @code{__alignof__} is an lvalue rather than a type, the
  1455. value is the largest alignment that the lvalue is known to have.  It may
  1456. have this alignment as a result of its data type, or because it is part of
  1457. a structure and inherits alignment from that structure.  For example, after
  1458. this declaration:
  1459.  
  1460. @example
  1461. struct foo @{ int x; char y; @} foo1;
  1462. @end example
  1463.  
  1464. @noindent
  1465. the value of @code{__alignof__ (foo1.y)} is probably 2 or 4, the same as
  1466. @code{__alignof__ (int)}, even though the data type of @code{foo1.y}
  1467. does not itself demand any alignment.@refill
  1468.  
  1469. A related feature which lets you specify the alignment of an object is
  1470. @code{__attribute__ ((aligned (@var{alignment})))}; see the following
  1471. section.
  1472.  
  1473. @node Variable Attributes
  1474. @section Specifying Attributes of Variables
  1475. @cindex attribute of variables
  1476. @cindex variable attributes
  1477.  
  1478. The keyword @code{__attribute__} allows you to specify special
  1479. attributes of variables or structure fields.  This keyword is followed
  1480. by an attribute specification inside double parentheses.  Four
  1481. attributes are currently defined: @code{aligned}, @code{format},
  1482. @code{mode} and @code{packed}.  @code{format} is used for functions,
  1483. and thus not documented here; see @ref{Function Attributes}.
  1484.  
  1485. @table @code
  1486. @cindex @code{aligned} attribute
  1487. @item aligned (@var{alignment})
  1488. This attribute specifies a minimum alignment for the variable or
  1489. structure field, measured in bytes.  For example, the declaration:
  1490.  
  1491. @smallexample
  1492. int x __attribute__ ((aligned (16))) = 0;
  1493. @end smallexample
  1494.  
  1495. @noindent
  1496. causes the compiler to allocate the global variable @code{x} on a
  1497. 16-byte boundary.  On a 68040, this could be used in conjunction with
  1498. an @code{asm} expression to access the @code{move16} instruction which
  1499. requires 16-byte aligned operands.
  1500.  
  1501. You can also specify the alignment of structure fields.  For example, to
  1502. create a double-word aligned @code{int} pair, you could write:
  1503.  
  1504. @smallexample
  1505. struct foo @{ int x[2] __attribute__ ((aligned (8))); @};
  1506. @end smallexample
  1507.  
  1508. @noindent
  1509. This is an alternative to creating a union with a @code{double} member
  1510. that forces the union to be double-word aligned.
  1511.  
  1512. It is not possible to specify the alignment of functions; the alignment
  1513. of functions is determined by the machine's requirements and cannot be
  1514. changed.  You cannot specify alignment for a typedef name because such a
  1515. name is just an alias, not a distinct type.
  1516.  
  1517. The @code{aligned} attribute can only increase the alignment; but you
  1518. can decrease it by specifying @code{packed} as well.  See below.
  1519.  
  1520. The linker of your operating system imposes a maximum alignment.  If the
  1521. linker aligns each object file on a four byte boundary, then it is
  1522. beyond the compiler's power to cause anything to be aligned to a larger
  1523. boundary than that.  For example, if  the linker happens to put this object
  1524. file at address 136 (eight more than a multiple of 64), then the compiler
  1525. cannot guarantee an alignment of more than 8 just by aligning variables in
  1526. the object file.
  1527.  
  1528. @item mode (@var{mode})
  1529. @cindex @code{mode} attribute
  1530. This attribute specifies the data type for the declaration---whichever
  1531. type corresponds to the mode @var{mode}.  This in effect lets you
  1532. request an integer or floating point type according to its width.
  1533.  
  1534. @item packed
  1535. @cindex @code{packed} attribute
  1536. The @code{packed} attribute specifies that a variable or structure field
  1537. should have the smallest possible alignment---one byte for a variable,
  1538. and one bit for a field, unless you specify a larger value with the
  1539. @code{aligned} attribute.
  1540. @end table
  1541.  
  1542. @node Inline
  1543. @section An Inline Function is As Fast As a Macro
  1544. @cindex inline functions
  1545. @cindex integrating function code
  1546. @cindex open coding
  1547. @cindex macros, inline alternative
  1548.  
  1549. By declaring a function @code{inline}, you can direct GNU CC to
  1550. integrate that function's code into the code for its callers.  This
  1551. makes execution faster by eliminating the function-call overhead; in
  1552. addition, if any of the actual argument values are constant, their known
  1553. values may permit simplifications at compile time so that not all of the
  1554. inline function's code needs to be included.  The effect on code size is
  1555. less predictable; object code may be larger or smaller with function
  1556. inlining, depending on the particular case.  Inlining of functions is an
  1557. optimization and it really ``works'' only in optimizing compilation.  If
  1558. you don't use @samp{-O}, no function is really inline.
  1559.  
  1560. To declare a function inline, use the @code{inline} keyword in its
  1561. declaration, like this:
  1562.  
  1563. @example
  1564. inline int
  1565. inc (int *a)
  1566. @{
  1567.   (*a)++;
  1568. @}
  1569. @end example
  1570.  
  1571. (If you are writing a header file to be included in ANSI C programs, write
  1572. @code{__inline__} instead of @code{inline}.  @xref{Alternate Keywords}.)
  1573.  
  1574. You can also make all ``simple enough'' functions inline with the option
  1575. @samp{-finline-functions}.  Note that certain usages in a function
  1576. definition can make it unsuitable for inline substitution.
  1577.  
  1578. @cindex automatic @code{inline} for C++ member fns
  1579. @cindex @code{inline} automatic for C++ member fns
  1580. @cindex member fns, automatically @code{inline}
  1581. @cindex C++ member fns, automatically @code{inline}
  1582. For C++ programs, GNU CC automatically inlines member functions even if
  1583. they are not explicitly declared @code{inline}.
  1584. (You can override this with @w{@samp{-fno-default-inline}};
  1585. @pxref{C++ Dialect Options,,Options Controlling C++ Dialect}.)
  1586.  
  1587. @cindex inline functions, omission of
  1588. When a function is both inline and @code{static}, if all calls to the
  1589. function are integrated into the caller, and the function's address is
  1590. never used, then the function's own assembler code is never referenced.
  1591. In this case, GNU CC does not actually output assembler code for the
  1592. function, unless you specify the option @samp{-fkeep-inline-functions}.
  1593. Some calls cannot be integrated for various reasons (in particular,
  1594. calls that precede the function's definition cannot be integrated, and
  1595. neither can recursive calls within the definition).  If there is a
  1596. nonintegrated call, then the function is compiled to assembler code as
  1597. usual.  The function must also be compiled as usual if the program
  1598. refers to its address, because that can't be inlined.
  1599.  
  1600. @cindex non-static inline function
  1601. When an inline function is not @code{static}, then the compiler must assume
  1602. that there may be calls from other source files; since a global symbol can
  1603. be defined only once in any program, the function must not be defined in
  1604. the other source files, so the calls therein cannot be integrated.
  1605. Therefore, a non-@code{static} inline function is always compiled on its
  1606. own in the usual fashion.
  1607.  
  1608. If you specify both @code{inline} and @code{extern} in the function
  1609. definition, then the definition is used only for inlining.  In no case
  1610. is the function compiled on its own, not even if you refer to its
  1611. address explicitly.  Such an address becomes an external reference, as
  1612. if you had only declared the function, and had not defined it.
  1613.  
  1614. This combination of @code{inline} and @code{extern} has almost the
  1615. effect of a macro.  The way to use it is to put a function definition in
  1616. a header file with these keywords, and put another copy of the
  1617. definition (lacking @code{inline} and @code{extern}) in a library file.
  1618. The definition in the header file will cause most calls to the function
  1619. to be inlined.  If any uses of the function remain, they will refer to
  1620. the single copy in the library.
  1621.  
  1622. GNU C does not inline any functions when not optimizing.  It is not
  1623. clear whether it is better to inline or not, in this case, but we found
  1624. that a correct implementation when not optimizing was difficult.  So we
  1625. did the easy thing, and turned it off.
  1626.  
  1627. @node Extended Asm
  1628. @section Assembler Instructions with C Expression Operands
  1629. @cindex extended @code{asm}
  1630. @cindex @code{asm} expressions
  1631. @cindex assembler instructions
  1632. @cindex registers
  1633.  
  1634. In an assembler instruction using @code{asm}, you can now specify the
  1635. operands of the instruction using C expressions.  This means no more
  1636. guessing which registers or memory locations will contain the data you want
  1637. to use.
  1638.  
  1639. You must specify an assembler instruction template much like what appears
  1640. in a machine description, plus an operand constraint string for each
  1641. operand.
  1642.  
  1643. For example, here is how to use the 68881's @code{fsinx} instruction:
  1644.  
  1645. @example
  1646. asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
  1647. @end example
  1648.  
  1649. @noindent
  1650. Here @code{angle} is the C expression for the input operand while
  1651. @code{result} is that of the output operand.  Each has @samp{"f"} as its
  1652. operand constraint, saying that a floating point register is required.  The
  1653. @samp{=} in @samp{=f} indicates that the operand is an output; all output
  1654. operands' constraints must use @samp{=}.  The constraints use the same
  1655. language used in the machine description (@pxref{Constraints}).
  1656.  
  1657. Each operand is described by an operand-constraint string followed by the C
  1658. expression in parentheses.  A colon separates the assembler template from
  1659. the first output operand, and another separates the last output operand
  1660. from the first input, if any.  Commas separate output operands and separate
  1661. inputs.  The total number of operands is limited to ten or to the maximum
  1662. number of operands in any instruction pattern in the machine description,
  1663. whichever is greater.
  1664.  
  1665. If there are no output operands, and there are input operands, then there
  1666. must be two consecutive colons surrounding the place where the output
  1667. operands would go.
  1668.  
  1669. Output operand expressions must be lvalues; the compiler can check this.
  1670. The input operands need not be lvalues.  The compiler cannot check whether
  1671. the operands have data types that are reasonable for the instruction being
  1672. executed.  It does not parse the assembler instruction template and does
  1673. not know what it means, or whether it is valid assembler input.  The
  1674. extended @code{asm} feature is most often used for machine instructions
  1675. that the compiler itself does not know exist.
  1676.  
  1677. The output operands must be write-only; GNU CC will assume that the values
  1678. in these operands before the instruction are dead and need not be
  1679. generated.  Extended asm does not support input-output or read-write
  1680. operands.  For this reason, the constraint character @samp{+}, which
  1681. indicates such an operand, may not be used.
  1682.  
  1683. When the assembler instruction has a read-write operand, or an operand
  1684. in which only some of the bits are to be changed, you must logically
  1685. split its function into two separate operands, one input operand and one
  1686. write-only output operand.  The connection between them is expressed by
  1687. constraints which say they need to be in the same location when the
  1688. instruction executes.  You can use the same C expression for both
  1689. operands, or different expressions.  For example, here we write the
  1690. (fictitious) @samp{combine} instruction with @code{bar} as its read-only
  1691. source operand and @code{foo} as its read-write destination:
  1692.  
  1693. @example
  1694. asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar));
  1695. @end example
  1696.  
  1697. @noindent
  1698. The constraint @samp{"0"} for operand 1 says that it must occupy the same
  1699. location as operand 0.  A digit in constraint is allowed only in an input
  1700. operand, and it must refer to an output operand.
  1701.  
  1702. Only a digit in the constraint can guarantee that one operand will be in
  1703. the same place as another.  The mere fact that @code{foo} is the value of
  1704. both operands is not enough to guarantee that they will be in the same
  1705. place in the generated assembler code.  The following would not work:
  1706.  
  1707. @example
  1708. asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar));
  1709. @end example
  1710.  
  1711. Various optimizations or reloading could cause operands 0 and 1 to be in
  1712. different registers; GNU CC knows no reason not to do so.  For example, the
  1713. compiler might find a copy of the value of @code{foo} in one register and
  1714. use it for operand 1, but generate the output operand 0 in a different
  1715. register (copying it afterward to @code{foo}'s own address).  Of course,
  1716. since the register for operand 1 is not even mentioned in the assembler
  1717. code, the result will not work, but GNU CC can't tell that.
  1718.  
  1719. Some instructions clobber specific hard registers.  To describe this, write
  1720. a third colon after the input operands, followed by the names of the
  1721. clobbered hard registers (given as strings).  Here is a realistic example
  1722. for the Vax:
  1723.  
  1724. @example
  1725. asm volatile ("movc3 %0,%1,%2"
  1726.               : /* no outputs */
  1727.               : "g" (from), "g" (to), "g" (count)
  1728.               : "r0", "r1", "r2", "r3", "r4", "r5");
  1729. @end example
  1730.  
  1731. If you refer to a particular hardware register from the assembler code,
  1732. then you will probably have to list the register after the third colon
  1733. to tell the compiler that the register's value is modified.  In many
  1734. assemblers, the register names begin with @samp{%}; to produce one
  1735. @samp{%} in the assembler code, you must write @samp{%%} in the input.
  1736.  
  1737. If your assembler instruction can alter the condition code register,
  1738. add @samp{cc} to the list of clobbered registers.  GNU CC on some
  1739. machines represents the condition codes as a specific hardware
  1740. register; @samp{cc} serves to name this register.  On other machines,
  1741. the condition code is handled differently, and specifying @samp{cc}
  1742. has no effect.  But it is valid no matter what the machine.
  1743.  
  1744. If your assembler instruction modifies memory in an unpredictable
  1745. fashion, add @samp{memory} to the list of clobbered registers.
  1746. This will cause GNU CC to not keep memory values cached in
  1747. registers across the assembler instruction.
  1748.  
  1749. You can put multiple assembler instructions together in a single @code{asm}
  1750. template, separated either with newlines (written as @samp{\n}) or with
  1751. semicolons if the assembler allows such semicolons.  The GNU assembler
  1752. allows semicolons and all Unix assemblers seem to do so.  The input
  1753. operands are guaranteed not to use any of the clobbered registers, and
  1754. neither will the output operands' addresses, so you can read and write the
  1755. clobbered registers as many times as you like.  Here is an example of
  1756. multiple instructions in a template; it assumes that the subroutine
  1757. @code{_foo} accepts arguments in registers 9 and 10:
  1758.  
  1759. @example
  1760. asm ("movl %0,r9;movl %1,r10;call _foo"
  1761.      : /* no outputs */
  1762.      : "g" (from), "g" (to)
  1763.      : "r9", "r10");
  1764. @end example
  1765.  
  1766. Unless an output operand has the @samp{&} constraint modifier, GNU CC may
  1767. allocate it in the same register as an unrelated input operand, on the
  1768. assumption that the inputs are consumed before the outputs are produced.
  1769. This assumption may be false if the assembler code actually consists of
  1770. more than one instruction.  In such a case, use @samp{&} for each output
  1771. operand that may not overlap an input.
  1772. @xref{Modifiers}.
  1773.  
  1774. If you want to test the condition code produced by an assembler instruction,
  1775. you must include a branch and a label in the @code{asm} construct, as follows:
  1776.  
  1777. @example
  1778. asm ("clr %0;frob %1;beq 0f;mov #1,%0;0:"
  1779.      : "g" (result)
  1780.      : "g" (input));
  1781. @end example
  1782.  
  1783. @noindent
  1784. This assumes your assembler supports local labels, as the GNU assembler
  1785. and most Unix assemblers do.
  1786.  
  1787. @cindex macros containing @code{asm}
  1788. Usually the most convenient way to use these @code{asm} instructions is to
  1789. encapsulate them in macros that look like functions.  For example,
  1790.  
  1791. @example
  1792. #define sin(x)       \
  1793. (@{ double __value, __arg = (x);   \
  1794.    asm ("fsinx %1,%0": "=f" (__value): "f" (__arg));  \
  1795.    __value; @})
  1796. @end example
  1797.  
  1798. @noindent
  1799. Here the variable @code{__arg} is used to make sure that the instruction
  1800. operates on a proper @code{double} value, and to accept only those
  1801. arguments @code{x} which can convert automatically to a @code{double}.
  1802.  
  1803. Another way to make sure the instruction operates on the correct data type
  1804. is to use a cast in the @code{asm}.  This is different from using a
  1805. variable @code{__arg} in that it converts more different types.  For
  1806. example, if the desired type were @code{int}, casting the argument to
  1807. @code{int} would accept a pointer with no complaint, while assigning the
  1808. argument to an @code{int} variable named @code{__arg} would warn about
  1809. using a pointer unless the caller explicitly casts it.
  1810.  
  1811. If an @code{asm} has output operands, GNU CC assumes for optimization
  1812. purposes that the instruction has no side effects except to change the
  1813. output operands.  This does not mean that instructions with a side effect
  1814. cannot be used, but you must be careful, because the compiler may eliminate
  1815. them if the output operands aren't used, or move them out of loops, or
  1816. replace two with one if they constitute a common subexpression.  Also, if
  1817. your instruction does have a side effect on a variable that otherwise
  1818. appears not to change, the old value of the variable may be reused later if
  1819. it happens to be found in a register.
  1820.  
  1821. You can prevent an @code{asm} instruction from being deleted, moved
  1822. significantly, or combined, by writing the keyword @code{volatile} after
  1823. the @code{asm}.  For example:
  1824.  
  1825. @example
  1826. #define set_priority(x)  \
  1827. asm volatile ("set_priority %0": /* no outputs */ : "g" (x))
  1828. @end example
  1829.  
  1830. @noindent
  1831. An instruction without output operands will not be deleted or moved
  1832. significantly, regardless, unless it is unreachable.
  1833.  
  1834. Note that even a volatile @code{asm} instruction can be moved in ways
  1835. that appear insignificant to the compiler, such as across jump
  1836. instructions.  You can't expect a sequence of volatile @code{asm}
  1837. instructions to remain perfectly consecutive.  If you want consecutive
  1838. output, use a single @code{asm}.
  1839.  
  1840. It is a natural idea to look for a way to give access to the condition
  1841. code left by the assembler instruction.  However, when we attempted to
  1842. implement this, we found no way to make it work reliably.  The problem
  1843. is that output operands might need reloading, which would result in
  1844. additional following ``store'' instructions.  On most machines, these
  1845. instructions would alter the condition code before there was time to
  1846. test it.  This problem doesn't arise for ordinary ``test'' and
  1847. ``compare'' instructions because they don't have any output operands.
  1848.  
  1849. If you are writing a header file that should be includable in ANSI C
  1850. programs, write @code{__asm__} instead of @code{asm}.  @xref{Alternate
  1851. Keywords}.
  1852.  
  1853. @ifclear INTERNALS
  1854. @c Show the details on constraints if they do not appear elsewhere in
  1855. @c the manual
  1856. @include md.texi
  1857. @end ifclear
  1858.  
  1859. @node Asm Labels
  1860. @section Controlling Names Used in Assembler Code
  1861. @cindex assembler names for identifiers
  1862. @cindex names used in assembler code
  1863. @cindex identifiers, names in assembler code
  1864.  
  1865. You can specify the name to be used in the assembler code for a C
  1866. function or variable by writing the @code{asm} (or @code{__asm__})
  1867. keyword after the declarator as follows:
  1868.  
  1869. @example
  1870. int foo asm ("myfoo") = 2;
  1871. @end example
  1872.  
  1873. @noindent
  1874. This specifies that the name to be used for the variable @code{foo} in
  1875. the assembler code should be @samp{myfoo} rather than the usual
  1876. @samp{_foo}.
  1877.  
  1878. On systems where an underscore is normally prepended to the name of a C
  1879. function or variable, this feature allows you to define names for the
  1880. linker that do not start with an underscore.
  1881.  
  1882. You cannot use @code{asm} in this way in a function @emph{definition}; but
  1883. you can get the same effect by writing a declaration for the function
  1884. before its definition and putting @code{asm} there, like this:
  1885.  
  1886. @example
  1887. extern func () asm ("FUNC");
  1888.  
  1889. func (x, y)
  1890.      int x, y;
  1891. @dots{}
  1892. @end example
  1893.  
  1894. It is up to you to make sure that the assembler names you choose do not
  1895. conflict with any other assembler symbols.  Also, you must not use a
  1896. register name; that would produce completely invalid assembler code.  GNU
  1897. CC does not as yet have the ability to store static variables in registers.
  1898. Perhaps that will be added.
  1899.  
  1900. @node Explicit Reg Vars
  1901. @section Variables in Specified Registers
  1902. @cindex explicit register variables
  1903. @cindex variables in specified registers
  1904. @cindex specified registers
  1905. @cindex registers, global allocation
  1906.  
  1907. GNU C allows you to put a few global variables into specified hardware
  1908. registers.  You can also specify the register in which an ordinary
  1909. register variable should be allocated.
  1910.  
  1911. @itemize @bullet
  1912. @item
  1913. Global register variables reserve registers throughout the program.
  1914. This may be useful in programs such as programming language
  1915. interpreters which have a couple of global variables that are accessed
  1916. very often.
  1917.  
  1918. @item
  1919. Local register variables in specific registers do not reserve the
  1920. registers.  The compiler's data flow analysis is capable of determining
  1921. where the specified registers contain live values, and where they are
  1922. available for other uses.
  1923.  
  1924. These local variables are sometimes convenient for use with the extended
  1925. @code{asm} feature (@pxref{Extended Asm}), if you want to write one
  1926. output of the assembler instruction directly into a particular register.
  1927. (This will work provided the register you specify fits the constraints
  1928. specified for that operand in the @code{asm}.)
  1929. @end itemize
  1930.  
  1931. @menu
  1932. * Global Reg Vars::
  1933. * Local Reg Vars::
  1934. @end menu
  1935.  
  1936. @node Global Reg Vars
  1937. @subsection Defining Global Register Variables
  1938. @cindex global register variables
  1939. @cindex registers, global variables in
  1940.  
  1941. You can define a global register variable in GNU C like this:
  1942.  
  1943. @example
  1944. register int *foo asm ("a5");
  1945. @end example
  1946.  
  1947. @noindent
  1948. Here @code{a5} is the name of the register which should be used.  Choose a
  1949. register which is normally saved and restored by function calls on your
  1950. machine, so that library routines will not clobber it.
  1951.  
  1952. Naturally the register name is cpu-dependent, so you would need to
  1953. conditionalize your program according to cpu type.  The register
  1954. @code{a5} would be a good choice on a 68000 for a variable of pointer
  1955. type.  On machines with register windows, be sure to choose a ``global''
  1956. register that is not affected magically by the function call mechanism.
  1957.  
  1958. In addition, operating systems on one type of cpu may differ in how they
  1959. name the registers; then you would need additional conditionals.  For
  1960. example, some 68000 operating systems call this register @code{%a5}.
  1961.  
  1962. Eventually there may be a way of asking the compiler to choose a register
  1963. automatically, but first we need to figure out how it should choose and
  1964. how to enable you to guide the choice.  No solution is evident.
  1965.  
  1966. Defining a global register variable in a certain register reserves that
  1967. register entirely for this use, at least within the current compilation.
  1968. The register will not be allocated for any other purpose in the functions
  1969. in the current compilation.  The register will not be saved and restored by
  1970. these functions.  Stores into this register are never deleted even if they
  1971. would appear to be dead, but references may be deleted or moved or
  1972. simplified.
  1973.  
  1974. It is not safe to access the global register variables from signal
  1975. handlers, or from more than one thread of control, because the system
  1976. library routines may temporarily use the register for other things (unless
  1977. you recompile them specially for the task at hand).
  1978.  
  1979. @cindex @code{qsort}, and global register variables
  1980. It is not safe for one function that uses a global register variable to
  1981. call another such function @code{foo} by way of a third function
  1982. @code{lose} that was compiled without knowledge of this variable (i.e. in a
  1983. different source file in which the variable wasn't declared).  This is
  1984. because @code{lose} might save the register and put some other value there.
  1985. For example, you can't expect a global register variable to be available in
  1986. the comparison-function that you pass to @code{qsort}, since @code{qsort}
  1987. might have put something else in that register.  (If you are prepared to
  1988. recompile @code{qsort} with the same global register variable, you can
  1989. solve this problem.)
  1990.  
  1991. If you want to recompile @code{qsort} or other source files which do not
  1992. actually use your global register variable, so that they will not use that
  1993. register for any other purpose, then it suffices to specify the compiler
  1994. option @samp{-ffixed-@var{reg}}.  You need not actually add a global
  1995. register declaration to their source code.
  1996.  
  1997. A function which can alter the value of a global register variable cannot
  1998. safely be called from a function compiled without this variable, because it
  1999. could clobber the value the caller expects to find there on return.
  2000. Therefore, the function which is the entry point into the part of the
  2001. program that uses the global register variable must explicitly save and
  2002. restore the value which belongs to its caller.
  2003.  
  2004. @cindex register variable after @code{longjmp}
  2005. @cindex global register after @code{longjmp}
  2006. @cindex value after @code{longjmp}
  2007. @findex longjmp
  2008. @findex setjmp
  2009. On most machines, @code{longjmp} will restore to each global register
  2010. variable the value it had at the time of the @code{setjmp}.  On some
  2011. machines, however, @code{longjmp} will not change the value of global
  2012. register variables.  To be portable, the function that called @code{setjmp}
  2013. should make other arrangements to save the values of the global register
  2014. variables, and to restore them in a @code{longjmp}.  This way, the same
  2015. thing will happen regardless of what @code{longjmp} does.
  2016.  
  2017. All global register variable declarations must precede all function
  2018. definitions.  If such a declaration could appear after function
  2019. definitions, the declaration would be too late to prevent the register from
  2020. being used for other purposes in the preceding functions.
  2021.  
  2022. Global register variables may not have initial values, because an
  2023. executable file has no means to supply initial contents for a register.
  2024.  
  2025. On the Sparc, there are reports that g3 @dots{} g7 are suitable
  2026. registers, but certain library functions, such as @code{getwd}, as well
  2027. as the subroutines for division and remainder, modify g3 and g4.  g1 and
  2028. g2 are local temporaries.
  2029.  
  2030. On the 68000, a2 @dots{} a5 should be suitable, as should d2 @dots{} d7.
  2031. Of course, it will not do to use more than a few of those.
  2032.  
  2033. @node Local Reg Vars
  2034. @subsection Specifying Registers for Local Variables
  2035. @cindex local variables, specifying registers 
  2036. @cindex specifying registers for local variables
  2037. @cindex registers for local variables
  2038.  
  2039. You can define a local register variable with a specified register
  2040. like this:
  2041.  
  2042. @example
  2043. register int *foo asm ("a5");
  2044. @end example
  2045.  
  2046. @noindent
  2047. Here @code{a5} is the name of the register which should be used.  Note
  2048. that this is the same syntax used for defining global register
  2049. variables, but for a local variable it would appear within a function.
  2050.  
  2051. Naturally the register name is cpu-dependent, but this is not a
  2052. problem, since specific registers are most often useful with explicit
  2053. assembler instructions (@pxref{Extended Asm}).  Both of these things
  2054. generally require that you conditionalize your program according to
  2055. cpu type.
  2056.  
  2057. In addition, operating systems on one type of cpu may differ in how they
  2058. name the registers; then you would need additional conditionals.  For
  2059. example, some 68000 operating systems call this register @code{%a5}.
  2060.  
  2061. Eventually there may be a way of asking the compiler to choose a register
  2062. automatically, but first we need to figure out how it should choose and
  2063. how to enable you to guide the choice.  No solution is evident.
  2064.  
  2065. Defining such a register variable does not reserve the register; it
  2066. remains available for other uses in places where flow control determines
  2067. the variable's value is not live.  However, these registers are made
  2068. unavailable for use in the reload pass.  I would not be surprised if
  2069. excessive use of this feature leaves the compiler too few available
  2070. registers to compile certain functions.
  2071.  
  2072. @node Alternate Keywords
  2073. @section Alternate Keywords
  2074. @cindex alternate keywords
  2075. @cindex keywords, alternate
  2076.  
  2077. The option @samp{-traditional} disables certain keywords; @samp{-ansi}
  2078. disables certain others.  This causes trouble when you want to use GNU C
  2079. extensions, or ANSI C features, in a general-purpose header file that
  2080. should be usable by all programs, including ANSI C programs and traditional
  2081. ones.  The keywords @code{asm}, @code{typeof} and @code{inline} cannot be
  2082. used since they won't work in a program compiled with @samp{-ansi}, while
  2083. the keywords @code{const}, @code{volatile}, @code{signed}, @code{typeof}
  2084. and @code{inline} won't work in a program compiled with
  2085. @samp{-traditional}.@refill
  2086.  
  2087. The way to solve these problems is to put @samp{__} at the beginning and
  2088. end of each problematical keyword.  For example, use @code{__asm__}
  2089. instead of @code{asm}, @code{__const__} instead of @code{const}, and
  2090. @code{__inline__} instead of @code{inline}.
  2091.  
  2092. Other C compilers won't accept these alternative keywords; if you want to
  2093. compile with another compiler, you can define the alternate keywords as
  2094. macros to replace them with the customary keywords.  It looks like this:
  2095.  
  2096. @example
  2097. #ifndef __GNUC__
  2098. #define __asm__ asm
  2099. #endif
  2100. @end example
  2101.  
  2102. @samp{-pedantic} causes warnings for many GNU C extensions.  You can
  2103. prevent such warnings within one expression by writing
  2104. @code{__extension__} before the expression.  @code{__extension__} has no
  2105. effect aside from this.
  2106.  
  2107. @node Incomplete Enums
  2108. @section Incomplete @code{enum} Types
  2109.  
  2110. You can define an @code{enum} tag without specifying its possible values.
  2111. This results in an incomplete type, much like what you get if you write
  2112. @code{struct foo} without describing the elements.  A later declaration
  2113. which does specify the possible values completes the type.
  2114.  
  2115. You can't allocate variables or storage using the type while it is
  2116. incomplete.  However, you can work with pointers to that type.
  2117.  
  2118. This extension may not be very useful, but it makes the handling of
  2119. @code{enum} more consistent with the way @code{struct} and @code{union}
  2120. are handled.
  2121.  
  2122. @node Function Names
  2123. @section Function Names as Strings
  2124.  
  2125. GNU CC predefines two string variables to be the name of the current function.
  2126. The variable @code{__FUNCTION__} is the name of the function as it appears
  2127. in the source.  The variable @code{__PRETTY_FUNCTION__} is the name of
  2128. the function pretty printed in a language specific fashion.
  2129.  
  2130. These names are always the same in a C function, but in a C++ function
  2131. they may be different.  For example, this program:
  2132.  
  2133. @smallexample
  2134. extern "C" @{
  2135. extern int printf (char *, ...);
  2136. @}
  2137.  
  2138. class a @{
  2139.  public:
  2140.   sub (int i)
  2141.     @{
  2142.       printf ("__FUNCTION__ = %s\n", __FUNCTION__);
  2143.       printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
  2144.     @}
  2145. @};
  2146.  
  2147. int
  2148. main (void)
  2149. @{
  2150.   a ax;
  2151.   ax.sub (0);
  2152.   return 0;
  2153. @}
  2154. @end smallexample
  2155.  
  2156. @noindent
  2157. gives this output:
  2158.  
  2159. @smallexample
  2160. __FUNCTION__ = sub
  2161. __PRETTY_FUNCTION__ = int  a::sub (int)
  2162. @end smallexample
  2163.  
  2164. @node C++ Extensions
  2165. @chapter Extensions to the C++ Language
  2166. @cindex extensions, C++ language
  2167. @cindex C++ language extensions
  2168.  
  2169. The GNU compiler provides these extensions to the C++ language (and you
  2170. can also use most of the C language extensions in your C++ programs).  If you
  2171. want to write code that checks whether these features are available, you can
  2172. test for the GNU compiler the same way as for C programs: check for a
  2173. predefined macro @code{__GNUC__}.  You can also use @code{__GNUG__} to
  2174. test specifically for GNU C++ (@pxref{Standard Predefined,,Standard
  2175. Predefined Macros,cpp.info,The C Preprocessor}).
  2176.  
  2177. @menu
  2178. * Naming Results::      Giving a name to C++ function return values.
  2179. * Min and Max::        C++ Minimum and maximum operators.
  2180. * Destructors and Goto:: Goto is safe to use in C++ even when destructors
  2181.                            are needed.
  2182. * C++ Interface::       You can use a single C++ header file for both
  2183.                          declarations and definitions.
  2184. @end menu
  2185.  
  2186. @node Naming Results
  2187. @section Named Return Values in C++
  2188.  
  2189. @cindex @code{return}, in C++ function header
  2190. @cindex return value, named, in C++
  2191. @cindex named return value in C++
  2192. @cindex C++ named return value
  2193. GNU C++ extends the function-definition syntax to allow you to specify a
  2194. name for the result of a function outside the body of the definition, in
  2195. C++ programs:
  2196.  
  2197. @example
  2198. @group
  2199. @var{type}
  2200. @var{functionname} (@var{args}) return @var{resultname};
  2201. @{ 
  2202.   @dots{}
  2203.   @var{body}
  2204.   @dots{}
  2205. @}
  2206. @end group
  2207. @end example
  2208.  
  2209. You can use this feature to avoid an extra constructor call when
  2210. a function result has a class type.  For example, consider a function
  2211. @code{m}, declared as @w{@samp{X v = m ();}}, whose result is of class
  2212. @code{X}:
  2213.  
  2214. @example
  2215. X
  2216. m ()
  2217. @{
  2218.   X b;
  2219.   b.a = 23;
  2220.   return b; 
  2221. @}
  2222. @end example
  2223.  
  2224. @cindex implicit argument: return value
  2225. Although @code{m} appears to have no arguments, in fact it has one implicit
  2226. argument: the address of the return value.  At invocation, the address
  2227. of enough space to hold @code{v} is sent in as the implicit argument.
  2228. Then @code{b} is constructed and its @code{a} field is set to the value
  2229. 23.  Finally, a copy constructor (a constructor of the form @samp{X(X&)})
  2230. is applied to @code{b}, with the (implicit) return value location as the
  2231. target, so that @code{v} is now bound to the return value.
  2232.  
  2233. But this is wasteful.  The local @code{b} is declared just to hold
  2234. something that will be copied right out.  While a compiler that
  2235. combined an ``elision'' algorithm with interprocedural data flow
  2236. analysis could conceivably eliminate all of this, it is much more
  2237. practical to allow you to assist the compiler in generating
  2238. efficient code by manipulating the return value explicitly,
  2239. thus avoiding the local variable and copy constructor altogether.
  2240.  
  2241. Using the extended GNU C++ function-definition syntax, you can avoid the
  2242. temporary allocation and copying by naming @code{r} as your return value
  2243. as the outset, and assigning to its @code{a} field directly:
  2244.  
  2245. @example
  2246. X
  2247. m () return r;
  2248. @{
  2249.   r.a = 23; 
  2250. @}
  2251. @end example
  2252.  
  2253. @noindent
  2254. The declaration of @code{r} is a standard, proper declaration, whose effects
  2255. are executed @strong{before} any of the body of @code{m}.
  2256.  
  2257. Functions of this type impose no additional restrictions; in particular,
  2258. you can execute @code{return} statements, or return implicitly by
  2259. reaching the end of the function body (``falling off the edge'').
  2260. Cases like 
  2261.  
  2262. @example
  2263. X
  2264. m () return r (23);
  2265. @{
  2266.   return; 
  2267. @}
  2268. @end example
  2269.  
  2270. @noindent
  2271. (or even @w{@samp{X m () return r (23); @{ @}}}) are unambiguous, since
  2272. the return value @code{r} has been initialized in either case.  The
  2273. following code may be hard to read, but also works predictably:
  2274.  
  2275. @example
  2276. X
  2277. m () return r;
  2278. @{
  2279.   X b;
  2280.   return b; 
  2281. @}
  2282. @end example
  2283.  
  2284. The return value slot denoted by @code{r} is initialized at the outset,
  2285. but the statement @samp{return b;} overrides this value.  The compiler
  2286. deals with this by destroying @code{r} (calling the destructor if there
  2287. is one, or doing nothing if there is not), and then reinitializing
  2288. @code{r} with @code{b}.
  2289.  
  2290. This extension is provided primarily to help people who use overloaded
  2291. operators, where there is a great need to control not just the
  2292. arguments, but the return values of functions.  For classes where the
  2293. copy constructor incurs a heavy performance penalty (especially in the
  2294. common case where there is a quick default constructor), this is a major
  2295. savings.  The disadvantage of this extension is that you do not control
  2296. when the default constructor for the return value is called: it is
  2297. always called at the beginning.
  2298.  
  2299. @node Min and Max
  2300. @section Minimum and Maximum Operators in C++
  2301.  
  2302. It is very convenient to have operators which return the ``minimum'' or the
  2303. ``maximum'' of two arguments.  In GNU C++ (but not in GNU C),
  2304.  
  2305. @table @code
  2306. @item @var{a} <? @var{b}
  2307. @findex <?
  2308. @cindex minimum operator
  2309. is the @dfn{minimum}, returning the smaller of the numeric values
  2310. @var{a} and @var{b};
  2311.  
  2312. @item @var{a} >? @var{b}
  2313. @findex >?
  2314. @cindex maximum operator
  2315. is the @dfn{maximum}, returning the larger of the numeric values @var{a}
  2316. and @var{b}.
  2317. @end table
  2318.  
  2319. These operations are not primitive in ordinary C++, since you can
  2320. use a macro to return the minimum of two things in C++, as in the
  2321. following example.
  2322.  
  2323. @example
  2324. #define MIN(X,Y) ((X) < (Y) ? : (X) : (Y))
  2325. @end example
  2326.  
  2327. @noindent
  2328. You might then use @w{@samp{int min = MIN (i, j);}} to set @var{min} to
  2329. the minimum value of variables @var{i} and @var{j}.
  2330.  
  2331. However, side effects in @code{X} or @code{Y} may cause unintended
  2332. behavior.  For example, @code{MIN (i++, j++)} will fail, incrementing
  2333. the smaller counter twice.  A GNU C extension allows you to write safe
  2334. macros that avoid this kind of problem (@pxref{Naming Types,,Naming an
  2335. Expression's Type}).  However, writing @code{MIN} and @code{MAX} as
  2336. macros also forces you to use function-call notation notation for a
  2337. fundamental arithmetic operation.  Using GNU C++ extensions, you can
  2338. write @w{@samp{int min = i <? j;}} instead.
  2339.  
  2340. Since @code{<?} and @code{>?} are built into the compiler, they properly
  2341. handle expressions with side-effects;  @w{@samp{int min = i++ <? j++;}}
  2342. works correctly.
  2343.  
  2344. @node Destructors and Goto
  2345. @section @code{goto} and Destructors in GNU C++
  2346.  
  2347. @cindex @code{goto} in C++
  2348. @cindex destructors vs @code{goto}
  2349. In C++ programs, you can safely use the @code{goto} statement.  When you
  2350. use it to exit a block which contains aggregates requiring destructors,
  2351. the destructors will run before the @code{goto} transfers control.  (In
  2352. ANSI C++, @code{goto} is restricted to targets within the current
  2353. block.)
  2354.  
  2355. @cindex constructors vs @code{goto}
  2356. The compiler still forbids using @code{goto} to @emph{enter} a scope
  2357. that requires constructors.
  2358.  
  2359. @node C++ Interface
  2360. @section Declarations and Definitions in One Header
  2361.  
  2362. @cindex interface and implementation headers, C++
  2363. @cindex C++ interface and implementation headers
  2364. C++ object definitions can be quite complex.  In principle, your source
  2365. code will need two kinds of things for each object that you use across
  2366. more than one source file.  First, you need an @dfn{interface}
  2367. specification, describing its structure with type declarations and
  2368. function prototypes.  Second, you need the @dfn{implementation} itself.
  2369. It can be tedious to maintain a separate interface description in a
  2370. header file, in parallel to the actual implementation.  It is also
  2371. dangerous, since separate interface and implementation definitions may
  2372. not remain parallel.
  2373.  
  2374. @cindex pragmas, interface and implementation
  2375. With GNU C++, you can use a single header file for both purposes.
  2376.  
  2377. @quotation
  2378. @emph{Warning:} The mechanism to specify this is in transition.  For the
  2379. nonce, you must use one of two @code{#pragma} commands; in a future
  2380. release of GNU C++, an alternative mechanism will make these
  2381. @code{#pragma} commands unnecessary.
  2382. @end quotation
  2383.  
  2384. The header file contains the full definitions, but is marked with
  2385. @samp{#pragma interface} in the source code.  This allows the compiler
  2386. to use the header file only as an interface specification when ordinary
  2387. source files incorporate it with @code{#include}.  In the single source
  2388. file where the full implementation belongs, you can use either a naming
  2389. convention or @samp{#pragma implementation} to indicate this alternate
  2390. use of the header file.
  2391.  
  2392. @table @code
  2393. @item #pragma interface
  2394. @kindex #pragma interface
  2395. Use this directive in @emph{header files} that define object classes, to save
  2396. space in most of the object files that use those classes.  Normally,
  2397. local copies of certain information (backup copies of inline member
  2398. functions, debugging information, and the internal tables that implement
  2399. virtual functions) must be kept in each object file that includes class
  2400. definitions.  You can use this pragma to avoid such duplication.  When a
  2401. header file containing @samp{#pragma interface} is included in a
  2402. compilation, this auxiliary information will not be generated (unless
  2403. the main input source file itself uses @samp{#pragma implementation}).
  2404. Instead, the object files will contain references to be resolved at link
  2405. time.
  2406.  
  2407. @item #pragma implementation
  2408. @itemx #pragma implementation "@var{objects}.h"
  2409. @kindex #pragma implementation
  2410. Use this pragma in a @emph{main input file}, when you want full output from
  2411. included header files to be generated (and made globally visible).  The
  2412. included header file, in turn, should use @samp{#pragma interface}.
  2413. Backup copies of inline member functions, debugging information, and the
  2414. internal tables used to implement virtual functions are all generated in
  2415. implementation files.
  2416.  
  2417. @cindex implied @code{#pragma implementation}
  2418. @cindex @code{#pragma implementation}, implied
  2419. @cindex naming convention, implementation headers
  2420. @samp{#pragma implementation} is @emph{implied} whenever the
  2421. basename@footnote{A file's @dfn{basename} is the name stripped of all
  2422. leading path information and of trailing suffixes, such as @samp{.h} or
  2423. @samp{.C} or @samp{.cc}.} of your source file matches the basename of a
  2424. header file it includes.  There is no way to turn this off (other than
  2425. using a different name for one of the two files).  In the same vein, if
  2426. you use @samp{#pragma implementation} with no argument, it applies to an
  2427. include file with the same basename as your source file.  For example, in
  2428. @file{allclass.cc}, @samp{#pragma implementation} by itself is
  2429. equivalent to @samp{#pragma implementation "allclass.h"}; but even if
  2430. you do not say @samp{#pragma implementation} at all, @file{allclass.h}
  2431. is treated as an implementation file whenever you include it from
  2432. @file{allclass.cc}.
  2433.  
  2434. If you use an explicit @samp{#pragma implementation}, it must appear in
  2435. your source file @emph{before} you include the affected header files.
  2436.  
  2437. Use the string argument if you want a single implementation file to
  2438. include code from multiple header files.  (You must also use
  2439. @samp{#include} to include the header file; @samp{#pragma
  2440. implementation} only specifies how to use the file---it doesn't actually
  2441. include it.)
  2442.  
  2443. There is no way to split up the contents of a single header file into
  2444. multiple implementation files.
  2445. @end table
  2446.  
  2447. @cindex inlining and C++ pragmas
  2448. @cindex C++ pragmas, effect on inlining
  2449. @cindex pragmas in C++, effect on inlining
  2450. @samp{#pragma implementation} and @samp{#pragma interface} also have an
  2451. effect on function inlining.
  2452.  
  2453. If you define a class in a header file marked with @samp{#pragma
  2454. interface}, the effect on a function defined in that class is similar to
  2455. an explicit @code{extern} declaration---the compiler emits no code at
  2456. all to define an independent version of the function.  Its definition
  2457. is used only for inlining with its callers.
  2458.  
  2459. Conversely, when you include the same header file in a main source file
  2460. that declares it as @samp{#pragma implementation}, the compiler emits
  2461. code for the function itself; this defines a version of the function
  2462. that can be found via pointers (or by callers compiled without
  2463. inlining).  
  2464.  
  2465.