home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / info / gcc.i06 (.txt) < prev    next >
GNU Info File  |  1993-06-12  |  49KB  |  820 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.47 from the input
  2. file gcc.tex.
  3.    This file documents the use and the internals of the GNU compiler.
  4.    Copyright (C) 1988, 1989, 1992 Free Software Foundation, Inc.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the sections entitled "GNU General Public License" and "Protect
  11. Your Freedom--Fight `Look And Feel'" are included exactly as in the
  12. original, and provided that the entire resulting derived work is
  13. distributed under the terms of a permission notice identical to this
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that the sections entitled "GNU General Public
  17. License" and "Protect Your Freedom--Fight `Look And Feel'", and this
  18. permission notice, may be included in translations approved by the Free
  19. Software Foundation instead of in the original English.
  20. File: gcc.info,  Node: Function Attributes,  Next: Function Prototypes,  Prev: Case Ranges,  Up: Extensions
  21. Declaring Attributes of Functions
  22. =================================
  23.    In GNU C, you declare certain things about functions called in your
  24. program which help the compiler optimize function calls.
  25.    A few standard library functions, such as `abort' and `exit', cannot
  26. return.  GNU CC knows this automatically.  Some programs define their
  27. own functions that never return.  You can declare them `volatile' to
  28. tell the compiler this fact.  For example,
  29.      extern void volatile fatal ();
  30.      
  31.      void
  32.      fatal (...)
  33.      {
  34.        ... /* Print error message. */ ...
  35.        exit (1);
  36.      }
  37.    The `volatile' keyword tells the compiler to assume that `fatal'
  38. cannot return.  This makes slightly better code, but more importantly
  39. it helps avoid spurious warnings of uninitialized variables.
  40.    It does not make sense for a `volatile' function to have a return
  41. type other than `void'.
  42.    Many functions do not examine any values except their arguments, and
  43. have no effects except the return value.  Such a function can be subject
  44. to common subexpression elimination and loop optimization just as an
  45. arithmetic operator would be.  These functions should be declared
  46. `const'.  For example,
  47.      extern int const square ();
  48. says that the hypothetical function `square' is safe to call fewer
  49. times than the program says.
  50.    Note that a function that has pointer arguments and examines the data
  51. pointed to must *not* be declared `const'.  Likewise, a function that
  52. calls a non-`const' function usually must not be `const'.  It does not
  53. make sense for a `const' function to return `void'.
  54.    We recommend placing the keyword `const' after the function's return
  55. type.  It makes no difference in the example above, but when the return
  56. type is a pointer, it is the only way to make the function itself
  57. const.  For example,
  58.      const char *mincp (int);
  59. says that `mincp' returns `const char *'--a pointer to a const object. 
  60. To declare `mincp' const, you must write this:
  61.      char * const mincp (int);
  62.    Some people object to this feature, suggesting that ANSI C's
  63. `#pragma' should be used instead.  There are two reasons for not doing
  64. this.
  65.   1. It is impossible to generate `#pragma' commands from a macro.
  66.   2. The `#pragma' command is just as likely as these keywords to mean
  67.      something else in another compiler.
  68.    These two reasons apply to almost any application that might be
  69. proposed for `#pragma'.  It is basically a mistake to use `#pragma' for
  70. *anything*.
  71.    The keyword `__attribute__' allows you to specify special attributes
  72. when making a declaration.  This keyword is followed by an attribute
  73. specification inside double parentheses.  One attributes, `format', is
  74. currently defined for functions.  Others are implemented for variables
  75. and structure fields (*note Function Attributes::.).
  76. `format (ARCHETYPE, STRING-INDEX, FIRST-TO-CHECK)'
  77.      The `format' attribute specifies that a function takes `printf' or
  78.      `scanf' style arguments which should be type-checked against a
  79.      format string.  For example, the declaration:
  80.           extern int
  81.           my_printf (void *my_object, const char *my_format, ...)
  82.                 __attribute__ ((format (printf, 2, 3)));
  83.      causes the compiler to check the arguments in calls to `my_printf'
  84.      for consistency with the `printf' style format string argument
  85.      `my_format'.
  86.      The parameter ARCHETYPE determines how the format string is
  87.      interpreted, and should be either `printf' or `scanf'.  The
  88.      parameter STRING-INDEX specifies which argument is the format
  89.      string argument (starting from 1), while FIRST-TO-CHECK is the
  90.      number of the first argument to check against the format string. 
  91.      For functions where the arguments are not available to be checked
  92.      (such as `vprintf'), specify the third parameter as zero.  In this
  93.      case the compiler only checks the format string for consistency.
  94.      In the example above, the format string (`my_format') is the second
  95.      argument of the function `my_print', and the arguments to check
  96.      start with the third argument, so the correct parameters for the
  97.      format attribute are 2 and 3.
  98.      The `format' attribute allows you to identify your own functions
  99.      which take format strings as arguments, so that GNU CC can check
  100.      the calls to these functions for errors.  The compiler always
  101.      checks formats for the ANSI library functions `printf', `fprintf',
  102.      `sprintf', `scanf', `fscanf', `sscanf', `vprintf', `vfprintf' and
  103.      `vsprintf' whenever such warnings are requested (using
  104.      `-Wformat'), so there is no need to modify the header file
  105.      `stdio.h'.
  106. File: gcc.info,  Node: Function Prototypes,  Next: Dollar Signs,  Prev: Function Attributes,  Up: Extensions
  107. Prototypes and Old-Style Function Definitions
  108. =============================================
  109.    GNU C extends ANSI C to allow a function prototype to override a
  110. later old-style non-prototype definition.  Consider the following
  111. example:
  112.      /* Use prototypes unless the compiler is old-fashioned.  */
  113.      #if __STDC__
  114.      #define P(x) (x)
  115.      #else
  116.      #define P(x) ()
  117.      #endif
  118.      
  119.      /* Prototype function declaration.  */
  120.      int isroot P((uid_t));
  121.      
  122.      /* Old-style function definition.  */
  123.      int
  124.      isroot (x)   /* ??? lossage here ??? */
  125.           uid_t x;
  126.      {
  127.        return x == 0;
  128.      }
  129.    Suppose the type `uid_t' happens to be `short'.  ANSI C does not
  130. allow this example, because subword arguments in old-style
  131. non-prototype definitions are promoted.  Therefore in this example the
  132. function definition's argument is really an `int', which does not match
  133. the prototype argument type of `short'.
  134.    This restriction of ANSI C makes it hard to write code that is
  135. portable to traditional C compilers, because the programmer does not
  136. know whether the `uid_t' type is `short', `int', or `long'.  Therefore,
  137. in cases like these GNU C allows a prototype to override a later
  138. old-style definition.  More precisely, in GNU C, a function prototype
  139. argument type overrides the argument type specified by a later
  140. old-style definition if the former type is the same as the latter type
  141. before promotion.  Thus in GNU C the above example is equivalent to the
  142. following:
  143.      int isroot (uid_t);
  144.      
  145.      int
  146.      isroot (uid_t x)
  147.      {
  148.        return x == 0;
  149.      }
  150. File: gcc.info,  Node: Dollar Signs,  Next: Character Escapes,  Prev: Function Prototypes,  Up: Extensions
  151. Dollar Signs in Identifier Names
  152. ================================
  153.    In GNU C, you may use dollar signs in identifier names.  This is
  154. because many traditional C implementations allow such identifiers.
  155.    On some machines, dollar signs are allowed in identifiers if you
  156. specify `-traditional'.  On a few systems they are allowed by default,
  157. even if you do not use `-traditional'.  But they are never allowed if
  158. you specify `-ansi'.
  159.    There are certain ANSI C programs (obscure, to be sure) that would
  160. compile incorrectly if dollar signs were permitted in identifiers.  For
  161. example:
  162.      #define foo(a) #a
  163.      #define lose(b) foo (b)
  164.      #define test$
  165.      lose (test)
  166. File: gcc.info,  Node: Character Escapes,  Next: Variable Attributes,  Prev: Dollar Signs,  Up: Extensions
  167. The Character ESC in Constants
  168. ==============================
  169.    You can use the sequence `\e' in a string or character constant to
  170. stand for the ASCII character ESC.
  171. File: gcc.info,  Node: Alignment,  Next: Inline,  Prev: Variable Attributes,  Up: Extensions
  172. Inquiring on Alignment of Types or Variables
  173. ============================================
  174.    The keyword `__alignof__' allows you to inquire about how an object
  175. is aligned, or the minimum alignment usually required by a type.  Its
  176. syntax is just like `sizeof'.
  177.    For example, if the target machine requires a `double' value to be
  178. aligned on an 8-byte boundary, then `__alignof__ (double)' is 8. This
  179. is true on many RISC machines.  On more traditional machine designs,
  180. `__alignof__ (double)' is 4 or even 2.
  181.    Some machines never actually require alignment; they allow reference
  182. to any data type even at an odd addresses.  For these machines,
  183. `__alignof__' reports the *recommended* alignment of a type.
  184.    When the operand of `__alignof__' is an lvalue rather than a type,
  185. the value is the largest alignment that the lvalue is known to have. 
  186. It may have this alignment as a result of its data type, or because it
  187. is part of a structure and inherits alignment from that structure. For
  188. example, after this declaration:
  189.      struct foo { int x; char y; } foo1;
  190. the value of `__alignof__ (foo1.y)' is probably 2 or 4, the same as
  191. `__alignof__ (int)', even though the data type of `foo1.y' does not
  192. itself demand any alignment.
  193.    A related feature which lets you specify the alignment of an object
  194. is `__attribute__ ((aligned (ALIGNMENT)))'; see the following section.
  195. File: gcc.info,  Node: Variable Attributes,  Next: Alignment,  Prev: Character Escapes,  Up: Extensions
  196. Specifying Attributes of Variables
  197. ==================================
  198.    The keyword `__attribute__' allows you to specify special attributes
  199. of variables or structure fields.  This keyword is followed by an
  200. attribute specification inside double parentheses.  Four attributes are
  201. currently defined: `aligned', `format', `mode' and `packed'.  `format'
  202. is used for functions, and thus not documented here; see *Note Function
  203. Attributes::.
  204. `aligned (ALIGNMENT)'
  205.      This attribute specifies the alignment of the variable or structure
  206.      field, measured in bytes.  For example, the declaration:
  207.           int x __attribute__ ((aligned (16))) = 0;
  208.      causes the compiler to allocate the global variable `x' on a
  209.      16-byte boundary.  On a 68040, this could be used in conjunction
  210.      with an `asm' expression to access the `move16' instruction which
  211.      requires 16-byte aligned operands.
  212.      You can also specify the alignment of structure fields.  For
  213.      example, to create a double-word aligned `int' pair, you could
  214.      write:
  215.           struct foo { int x[2] __attribute__ ((aligned (8))); };
  216.      This is an alternative to creating a union with a `double' member
  217.      that forces the union to be double-word aligned.
  218.      It is not possible to specify the alignment of functions; the
  219.      alignment of functions is determined by the machine's requirements
  220.      and cannot be changed.  You cannot specify alignment for a typedef
  221.      name because such a name is just an alias, not a distinct type.
  222.      The linker of your operating system imposes a maximum alignment. 
  223.      If the linker aligns each object file on a four byte boundary,
  224.      then it is beyond the compiler's power to cause anything to be
  225.      aligned to a larger boundary than that.  For example, if  the
  226.      linker happens to put this object file at address 136 (eight more
  227.      than a multiple of 64), then the compiler cannot guarantee an
  228.      alignment of more than 8 just by aligning variables in the object
  229.      file.
  230. `mode (MODE)'
  231.      This attribute specifies the data type for the
  232.      declaration--whichever type corresponds to the mode MODE.  This in
  233.      effect lets you request an integer or floating point type
  234.      according to its width.
  235. `packed'
  236.      The `packed' attribute specifies that a variable or structure field
  237.      should have the smallest possible alignment--one byte for a
  238.      variable, and one bit for a field, unless you specify a larger
  239.      value with the `aligned' attribute.
  240. File: gcc.info,  Node: Inline,  Next: Extended Asm,  Prev: Alignment,  Up: Extensions
  241. An Inline Function is As Fast As a Macro
  242. ========================================
  243.    By declaring a function `inline', you can direct GNU CC to integrate
  244. that function's code into the code for its callers.  This makes
  245. execution faster by eliminating the function-call overhead; in
  246. addition, if any of the actual argument values are constant, their known
  247. values may permit simplifications at compile time so that not all of the
  248. inline function's code needs to be included.  Inlining of functions is
  249. an optimization and it really "works" only in optimizing compilation.
  250. If you don't use `-O', no function is really inline.
  251.    To declare a function inline, use the `inline' keyword in its
  252. declaration, like this:
  253.      inline int
  254.      inc (int *a)
  255.      {
  256.        (*a)++;
  257.      }
  258.    (If you are writing a header file to be included in ANSI C programs,
  259. write `__inline__' instead of `inline'.  *Note Alternate Keywords::.)
  260.    You can also make all "simple enough" functions inline with the
  261. option `-finline-functions'.  Note that certain usages in a function
  262. definition can make it unsuitable for inline substitution.
  263.    When a function is both inline and `static', if all calls to the
  264. function are integrated into the caller, and the function's address is
  265. never used, then the function's own assembler code is never referenced.
  266. In this case, GNU CC does not actually output assembler code for the
  267. function, unless you specify the option `-fkeep-inline-functions'. Some
  268. calls cannot be integrated for various reasons (in particular, calls
  269. that precede the function's definition cannot be integrated, and
  270. neither can recursive calls within the definition).  If there is a
  271. nonintegrated call, then the function is compiled to assembler code as
  272. usual.  The function must also be compiled as usual if the program
  273. refers to its address, because that can't be inlined.
  274.    When an inline function is not `static', then the compiler must
  275. assume that there may be calls from other source files; since a global
  276. symbol can be defined only once in any program, the function must not
  277. be defined in the other source files, so the calls therein cannot be
  278. integrated. Therefore, a non-`static' inline function is always
  279. compiled on its own in the usual fashion.
  280.    If you specify both `inline' and `extern' in the function
  281. definition, then the definition is used only for inlining.  In no case
  282. is the function compiled on its own, not even if you refer to its
  283. address explicitly.  Such an address becomes an external reference, as
  284. if you had only declared the function, and had not defined it.
  285.    This combination of `inline' and `extern' has almost the effect of a
  286. macro.  The way to use it is to put a function definition in a header
  287. file with these keywords, and put another copy of the definition
  288. (lacking `inline' and `extern') in a library file. The definition in
  289. the header file will cause most calls to the function to be inlined. 
  290. If any uses of the function remain, they will refer to the single copy
  291. in the library.
  292.    GNU C does not inline any functions when not optimizing.  It is not
  293. clear whether it is better to inline or not, in this case, but we found
  294. that a correct implementation when not optimizing was difficult.  So we
  295. did the easy thing, and turned it off.
  296. File: gcc.info,  Node: Extended Asm,  Next: Asm Labels,  Prev: Inline,  Up: Extensions
  297. Assembler Instructions with C Expression Operands
  298. =================================================
  299.    In an assembler instruction using `asm', you can now specify the
  300. operands of the instruction using C expressions.  This means no more
  301. guessing which registers or memory locations will contain the data you
  302. want to use.
  303.    You must specify an assembler instruction template much like what
  304. appears in a machine description, plus an operand constraint string for
  305. each operand.
  306.    For example, here is how to use the 68881's `fsinx' instruction:
  307.      asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
  308. Here `angle' is the C expression for the input operand while `result'
  309. is that of the output operand.  Each has `"f"' as its operand
  310. constraint, saying that a floating point register is required.  The `='
  311. in `=f' indicates that the operand is an output; all output operands'
  312. constraints must use `='.  The constraints use the same language used
  313. in the machine description (*note Constraints::.).
  314. Each operand is described by an operand-constraint string followed by
  315. the C expression in parentheses.  A colon separates the assembler
  316. template from the first output operand, and another separates the last
  317. output operand from the first input, if any.  Commas separate output
  318. operands and separate inputs.  The total number of operands is limited
  319. to ten or to the maximum number of operands in any instruction pattern
  320. in the machine description, whichever is greater.
  321.    If there are no output operands, and there are input operands, then
  322. there must be two consecutive colons surrounding the place where the
  323. output operands would go.
  324.    Output operand expressions must be lvalues; the compiler can check
  325. this. The input operands need not be lvalues.  The compiler cannot
  326. check whether the operands have data types that are reasonable for the
  327. instruction being executed.  It does not parse the assembler
  328. instruction template and does not know what it means, or whether it is
  329. valid assembler input.  The extended `asm' feature is most often used
  330. for machine instructions that the compiler itself does not know exist.
  331.    The output operands must be write-only; GNU CC will assume that the
  332. values in these operands before the instruction are dead and need not be
  333. generated.  Extended asm does not support input-output or read-write
  334. operands.  For this reason, the constraint character `+', which
  335. indicates such an operand, may not be used.
  336.    When the assembler instruction has a read-write operand, or an
  337. operand in which only some of the bits are to be changed, you must
  338. logically split its function into two separate operands, one input
  339. operand and one write-only output operand.  The connection between them
  340. is expressed by constraints which say they need to be in the same
  341. location when the instruction executes.  You can use the same C
  342. expression for both operands, or different expressions.  For example,
  343. here we write the (fictitious) `combine' instruction with `bar' as its
  344. read-only source operand and `foo' as its read-write destination:
  345.      asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar));
  346. The constraint `"0"' for operand 1 says that it must occupy the same
  347. location as operand 0.  A digit in constraint is allowed only in an
  348. input operand, and it must refer to an output operand.
  349.    Only a digit in the constraint can guarantee that one operand will
  350. be in the same place as another.  The mere fact that `foo' is the value
  351. of both operands is not enough to guarantee that they will be in the
  352. same place in the generated assembler code.  The following would not
  353. work:
  354.      asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar));
  355.    Various optimizations or reloading could cause operands 0 and 1 to
  356. be in different registers; GNU CC knows no reason not to do so.  For
  357. example, the compiler might find a copy of the value of `foo' in one
  358. register and use it for operand 1, but generate the output operand 0 in
  359. a different register (copying it afterward to `foo''s own address).  Of
  360. course, since the register for operand 1 is not even mentioned in the
  361. assembler code, the result will not work, but GNU CC can't tell that.
  362.    Some instructions clobber specific hard registers.  To describe
  363. this, write a third colon after the input operands, followed by the
  364. names of the clobbered hard registers (given as strings).  Here is a
  365. realistic example for the Vax:
  366.      asm volatile ("movc3 %0,%1,%2"
  367.                    : /* no outputs */
  368.                    : "g" (from), "g" (to), "g" (count)
  369.                    : "r0", "r1", "r2", "r3", "r4", "r5");
  370.    If you refer to a particular hardware register from the assembler
  371. code, then you will probably have to list the register after the third
  372. colon to tell the compiler that the register's value is modified.  In
  373. many assemblers, the register names begin with `%'; to produce one `%'
  374. in the assembler code, you must write `%%' in the input.
  375.    If your assembler instruction can alter the condition code register,
  376. add `cc' to the list of clobbered registers.  GNU CC on some machines
  377. represents the condition codes as a specific hardware register; `cc'
  378. serves to name this register.  On other machines, the condition code is
  379. handled differently, and specifying `cc' has no effect.  But it is
  380. valid no matter what the machine.
  381.    If your assembler instruction modifies memory in an unpredicable
  382. fashion, add `memory' to the list of clobbered registers. This will
  383. cause GNU CC to not keep memory values cached in registers across the
  384. assembler instruction.
  385.    You can put multiple assembler instructions together in a single
  386. `asm' template, separated either with newlines (written as `\n') or with
  387. semicolons if the assembler allows such semicolons.  The GNU assembler
  388. allows semicolons and all Unix assemblers seem to do so.  The input
  389. operands are guaranteed not to use any of the clobbered registers, and
  390. neither will the output operands' addresses, so you can read and write
  391. the clobbered registers as many times as you like.  Here is an example
  392. of multiple instructions in a template; it assumes that the subroutine
  393. `_foo' accepts arguments in registers 9 and 10:
  394.      asm ("movl %0,r9;movl %1,r10;call _foo"
  395.           : /* no outputs */
  396.           : "g" (from), "g" (to)
  397.           : "r9", "r10");
  398.    Unless an output operand has the `&' constraint modifier, GNU CC may
  399. allocate it in the same register as an unrelated input operand, on the
  400. assumption that the inputs are consumed before the outputs are produced.
  401. This assumption may be false if the assembler code actually consists of
  402. more than one instruction.  In such a case, use `&' for each output
  403. operand that may not overlap an input. *Note Modifiers::.
  404.    If you want to test the condition code produced by an assembler
  405. instruction, you must include a branch and a label in the `asm'
  406. construct, as follows:
  407.      asm ("clr %0;frob %1;beq 0f;mov #1,%0;0:"
  408.           : "g" (result)
  409.           : "g" (input));
  410. This assumes your assembler supports local labels, as the GNU assembler
  411. and most Unix assemblers do.
  412.    Usually the most convenient way to use these `asm' instructions is to
  413. encapsulate them in macros that look like functions.  For example,
  414.      #define sin(x)       \
  415.      ({ double __value, __arg = (x);   \
  416.         asm ("fsinx %1,%0": "=f" (__value): "f" (__arg));  \
  417.         __value; })
  418. Here the variable `__arg' is used to make sure that the instruction
  419. operates on a proper `double' value, and to accept only those arguments
  420. `x' which can convert automatically to a `double'.
  421.    Another way to make sure the instruction operates on the correct
  422. data type is to use a cast in the `asm'.  This is different from using a
  423. variable `__arg' in that it converts more different types.  For
  424. example, if the desired type were `int', casting the argument to `int'
  425. would accept a pointer with no complaint, while assigning the argument
  426. to an `int' variable named `__arg' would warn about using a pointer
  427. unless the caller explicitly casts it.
  428.    If an `asm' has output operands, GNU CC assumes for optimization
  429. purposes that the instruction has no side effects except to change the
  430. output operands.  This does not mean that instructions with a side
  431. effect cannot be used, but you must be careful, because the compiler
  432. may eliminate them if the output operands aren't used, or move them out
  433. of loops, or replace two with one if they constitute a common
  434. subexpression.  Also, if your instruction does have a side effect on a
  435. variable that otherwise appears not to change, the old value of the
  436. variable may be reused later if it happens to be found in a register.
  437.    You can prevent an `asm' instruction from being deleted, moved
  438. significantly, or combined, by writing the keyword `volatile' after the
  439. `asm'.  For example:
  440.      #define set_priority(x)  \
  441.      asm volatile ("set_priority %0": /* no outputs */ : "g" (x))
  442. An instruction without output operands will not be deleted or moved
  443. significantly, regardless, unless it is unreachable.
  444.    Note that even a volatile `asm' instruction can be moved in ways
  445. that appear insignificant to the compiler, such as across jump
  446. instructions.  You can't expect a sequence of volatile `asm'
  447. instructions to remain perfectly consecutive.  If you want consecutive
  448. output, use a single `asm'.
  449.    It is a natural idea to look for a way to give access to the
  450. condition code left by the assembler instruction.  However, when we
  451. attempted to implement this, we found no way to make it work reliably. 
  452. The problem is that output operands might need reloading, which would
  453. result in additional following "store" instructions.  On most machines,
  454. these instructions would alter the condition code before there was time
  455. to test it.  This problem doesn't arise for ordinary "test" and
  456. "compare" instructions because they don't have any output operands.
  457.    If you are writing a header file that should be includable in ANSI C
  458. programs, write `__asm__' instead of `asm'.  *Note Alternate Keywords::.
  459. File: gcc.info,  Node: Asm Labels,  Next: Explicit Reg Vars,  Prev: Extended Asm,  Up: Extensions
  460. Controlling Names Used in Assembler Code
  461. ========================================
  462.    You can specify the name to be used in the assembler code for a C
  463. function or variable by writing the `asm' (or `__asm__') keyword after
  464. the declarator as follows:
  465.      int foo asm ("myfoo") = 2;
  466. This specifies that the name to be used for the variable `foo' in the
  467. assembler code should be `myfoo' rather than the usual `_foo'.
  468.    On systems where an underscore is normally prepended to the name of
  469. a C function or variable, this feature allows you to define names for
  470. the linker that do not start with an underscore.
  471.    You cannot use `asm' in this way in a function *definition*; but you
  472. can get the same effect by writing a declaration for the function
  473. before its definition and putting `asm' there, like this:
  474.      extern func () asm ("FUNC");
  475.      
  476.      func (x, y)
  477.           int x, y;
  478.      ...
  479.    It is up to you to make sure that the assembler names you choose do
  480. not conflict with any other assembler symbols.  Also, you must not use a
  481. register name; that would produce completely invalid assembler code. 
  482. GNU CC does not as yet have the ability to store static variables in
  483. registers. Perhaps that will be added.
  484. File: gcc.info,  Node: Explicit Reg Vars,  Next: Alternate Keywords,  Prev: Asm Labels,  Up: Extensions
  485. Variables in Specified Registers
  486. ================================
  487.    GNU C allows you to put a few global variables into specified
  488. hardware registers.  You can also specify the register in which an
  489. ordinary register variable should be allocated.
  490.    * Global register variables reserve registers throughout the program.
  491.      This may be useful in programs such as programming language
  492.      interpreters which have a couple of global variables that are
  493.      accessed very often.
  494.    * Local register variables in specific registers do not reserve the
  495.      registers.  The compiler's data flow analysis is capable of
  496.      determining where the specified registers contain live values, and
  497.      where they are available for other uses.
  498.      These local variables are sometimes convenient for use with the
  499.      extended `asm' feature (*note Extended Asm::.), if you want to
  500.      write one output of the assembler instruction directly into a
  501.      particular register. (This will work provided the register you
  502.      specify fits the constraints specified for that operand in the
  503.      `asm'.)
  504. * Menu:
  505. * Global Reg Vars::
  506. * Local Reg Vars::
  507. File: gcc.info,  Node: Global Reg Vars,  Next: Local Reg Vars,  Up: Explicit Reg Vars
  508. Defining Global Register Variables
  509. ----------------------------------
  510.    You can define a global register variable in GNU C like this:
  511.      register int *foo asm ("a5");
  512. Here `a5' is the name of the register which should be used.  Choose a
  513. register which is normally saved and restored by function calls on your
  514. machine, so that library routines will not clobber it.
  515.    Naturally the register name is cpu-dependent, so you would need to
  516. conditionalize your program according to cpu type.  The register `a5'
  517. would be a good choice on a 68000 for a variable of pointer type.  On
  518. machines with register windows, be sure to choose a "global" register
  519. that is not affected magically by the function call mechanism.
  520.    In addition, operating systems on one type of cpu may differ in how
  521. they name the registers; then you would need additional conditionals. 
  522. For example, some 68000 operating systems call this register `%a5'.
  523.    Eventually there may be a way of asking the compiler to choose a
  524. register automatically, but first we need to figure out how it should
  525. choose and how to enable you to guide the choice.  No solution is
  526. evident.
  527.    Defining a global register variable in a certain register reserves
  528. that register entirely for this use, at least within the current
  529. compilation. The register will not be allocated for any other purpose
  530. in the functions in the current compilation.  The register will not be
  531. saved and restored by these functions.  Stores into this register are
  532. never deleted even if they would appear to be dead, but references may
  533. be deleted or moved or simplified.
  534.    It is not safe to access the global register variables from signal
  535. handlers, or from more than one thread of control, because the system
  536. library routines may temporarily use the register for other things
  537. (unless you recompile them specially for the task at hand).
  538.    It is not safe for one function that uses a global register variable
  539. to call another such function `foo' by way of a third function `lose'
  540. that was compiled without knowledge of this variable (i.e. in a
  541. different source file in which the variable wasn't declared).  This is
  542. because `lose' might save the register and put some other value there.
  543. For example, you can't expect a global register variable to be
  544. available in the comparison-function that you pass to `qsort', since
  545. `qsort' might have put something else in that register.  (If you are
  546. prepared to recompile `qsort' with the same global register variable,
  547. you can solve this problem.)
  548.    If you want to recompile `qsort' or other source files which do not
  549. actually use your global register variable, so that they will not use
  550. that register for any other purpose, then it suffices to specify the
  551. compiler option `-ffixed-REG'.  You need not actually add a global
  552. register declaration to their source code.
  553.    A function which can alter the value of a global register variable
  554. cannot safely be called from a function compiled without this variable,
  555. because it could clobber the value the caller expects to find there on
  556. return. Therefore, the function which is the entry point into the part
  557. of the program that uses the global register variable must explicitly
  558. save and restore the value which belongs to its caller.
  559.    On most machines, `longjmp' will restore to each global register
  560. variable the value it had at the time of the `setjmp'.  On some
  561. machines, however, `longjmp' will not change the value of global
  562. register variables.  To be portable, the function that called `setjmp'
  563. should make other arrangements to save the values of the global register
  564. variables, and to restore them in a `longjmp'.  This way, the same
  565. thing will happen regardless of what `longjmp' does.
  566.    All global register variable declarations must precede all function
  567. definitions.  If such a declaration could appear after function
  568. definitions, the declaration would be too late to prevent the register
  569. from being used for other purposes in the preceding functions.
  570.    Global register variables may not have initial values, because an
  571. executable file has no means to supply initial contents for a register.
  572.    On the Sparc, there are reports that g3 ... g7 are suitable
  573. registers, but certain library functions, such as `getwd', as well as
  574. the subroutines for division and remainder, modify g3 and g4.  g1 and
  575. g2 are local temporaries.
  576.    On the 68000, a2 ... a5 should be suitable, as should d2 ... d7. Of
  577. course, it will not do to use more than a few of those.
  578. File: gcc.info,  Node: Local Reg Vars,  Prev: Global Reg Vars,  Up: Explicit Reg Vars
  579. Specifying Registers for Local Variables
  580. ----------------------------------------
  581.    You can define a local register variable with a specified register
  582. like this:
  583.      register int *foo asm ("a5");
  584. Here `a5' is the name of the register which should be used.  Note that
  585. this is the same syntax used for defining global register variables,
  586. but for a local variable it would appear within a function.
  587.    Naturally the register name is cpu-dependent, but this is not a
  588. problem, since specific registers are most often useful with explicit
  589. assembler instructions (*note Extended Asm::.).  Both of these things
  590. generally require that you conditionalize your program according to cpu
  591. type.
  592.    In addition, operating systems on one type of cpu may differ in how
  593. they name the registers; then you would need additional conditionals. 
  594. For example, some 68000 operating systems call this register `%a5'.
  595.    Eventually there may be a way of asking the compiler to choose a
  596. register automatically, but first we need to figure out how it should
  597. choose and how to enable you to guide the choice.  No solution is
  598. evident.
  599.    Defining such a register variable does not reserve the register; it
  600. remains available for other uses in places where flow control determines
  601. the variable's value is not live.  However, these registers are made
  602. unavailable for use in the reload pass.  I would not be surprised if
  603. excessive use of this feature leaves the compiler too few available
  604. registers to compile certain functions.
  605. File: gcc.info,  Node: Alternate Keywords,  Next: Incomplete Enums,  Prev: Explicit Reg Vars,  Up: Extensions
  606. Alternate Keywords
  607. ==================
  608.    The option `-traditional' disables certain keywords; `-ansi'
  609. disables certain others.  This causes trouble when you want to use GNU C
  610. extensions, or ANSI C features, in a general-purpose header file that
  611. should be usable by all programs, including ANSI C programs and
  612. traditional ones.  The keywords `asm', `typeof' and `inline' cannot be
  613. used since they won't work in a program compiled with `-ansi', while
  614. the keywords `const', `volatile', `signed', `typeof' and `inline' won't
  615. work in a program compiled with `-traditional'.
  616.    The way to solve these problems is to put `__' at the beginning and
  617. end of each problematical keyword.  For example, use `__asm__' instead
  618. of `asm', `__const__' instead of `const', and `__inline__' instead of
  619. `inline'.
  620.    Other C compilers won't accept these alternative keywords; if you
  621. want to compile with another compiler, you can define the alternate
  622. keywords as macros to replace them with the customary keywords.  It
  623. looks like this:
  624.      #ifndef __GNUC__
  625.      #define __asm__ asm
  626.      #endif
  627.    `-pedantic' causes warnings for many GNU C extensions.  You can
  628. prevent such warnings within one expression by writing `__extension__'
  629. before the expression.  `__extension__' has no effect aside from this.
  630. File: gcc.info,  Node: Incomplete Enums,  Prev: Alternate Keywords,  Up: Extensions
  631. Incomplete `enum' Types
  632. =======================
  633.    You can define an `enum' tag without specifying its possible values.
  634. This results in an incomplete type, much like what you get if you write
  635. `struct foo' without describing the elements.  A later declaration
  636. which does specify the possible values completes the type.
  637.    You can't allocate variables or storage using the type while it is
  638. incomplete.  However, you can work with pointers to that type.
  639.    This extension may not be very useful, but it makes the handling of
  640. `enum' more consistent with the way `struct' and `union' are handled.
  641. File: gcc.info,  Node: Trouble,  Next: Bugs,  Prev: Extensions,  Up: Top
  642. Known Causes of Trouble with GNU CC
  643. ***********************************
  644.    This section describes known problems that affect users of GNU CC. 
  645. Most of these are not GNU CC bugs per se--if they were, we would fix
  646. them. But the result for a user may be like the result of a bug.
  647.    Some of these problems are due to bugs in other software, some are
  648. missing features that are too much work to add, and some are places
  649. where people's opinions differ as to what is best.
  650. * Menu:
  651. * Actual Bugs::              Bugs we will fix later.
  652. * Installation Problems::     Problems that manifest when you install GNU CC.
  653. * Cross-Compiler Problems::   Common problems of cross compiling with GNU CC.
  654. * Interoperation::      Problems using GNU CC with other compilers,
  655.                and with certain linkers, assemblers and debuggers.
  656. * Incompatibilities::   GNU CC is incompatible with traditional C.
  657. * Disappointments::     Regrettable things we can't change, but not quite bugs.
  658. * Protoize Caveats::    Things to watch out for when using `protoize'.
  659. * Non-bugs::        Things we think are right, but some others disagree.
  660. File: gcc.info,  Node: Actual Bugs,  Next: Installation Problems,  Up: Trouble
  661. Actual Bugs We Haven't Fixed Yet
  662. ================================
  663.    * Loop unrolling doesn't work properly for certain C++ programs. 
  664.      This is because of difficulty in updating the debugging
  665.      information within the loop being unrolled.  We plan to revamp the
  666.      representation of debugging information so that this will work
  667.      properly, but we have not done this in version 2.3 because we
  668.      don't want to delay it any further.
  669. File: gcc.info,  Node: Installation Problems,  Next: Cross-Compiler Problems,  Prev: Actual Bugs,  Up: Trouble
  670. Installation Problems
  671. =====================
  672.    This is a list of problems (and some apparent problems which don't
  673. really mean anything is wrong) that show up during installation of GNU
  674.    * On certain systems, defining certain environment variables such as
  675.      `CC' can interfere with the functioning of `make'.
  676.    * If you encounter seemingly strange errors when trying to build the
  677.      compiler in a directory other than the source directory, it could
  678.      be because you have previously configured the compiler in the
  679.      source directory.  Make sure you have done all the necessary
  680.      preparations. *Note Other Dir::.
  681.    * In previous versions of GNU CC, the `gcc' driver program looked for
  682.      `as' and `ld' in various places such as files beginning with
  683.      `/usr/local/lib/gcc-'.  GNU CC version 2 looks for them in the
  684.      directory `/usr/local/lib/gcc-lib/TARGET/VERSION'.
  685.      Thus, to use a version of `as' or `ld' that is not the system
  686.      default, for example `gas' or GNU `ld', you must put them in that
  687.      directory (or make links to them from that directory).
  688.    * Some commands executed when making the compiler may fail (return a
  689.      non-zero status) and be ignored by `make'.  These failures, which
  690.      are often due to files that were not found, are expected, and can
  691.      safely be ignored.
  692.    * It is normal to have warnings in compiling certain files about
  693.      unreachable code and about enumeration type clashes.  These files'
  694.      names begin with `insn-'.
  695.    * Sometimes `make' recompiles parts of the compiler when installing
  696.      the compiler.  In one case, this was traced down to a bug in
  697.      `make'.  Either ignore the problem or switch to GNU Make.
  698.    * On some 386 systems, building the compiler never finishes because
  699.      `enquire' hangs due to a hardware problem in the motherboard--it
  700.      reports floating point exceptions to the kernel incorrectly.  You
  701.      can install GNU CC except for `float.h' by patching out the
  702.      command to run `enquire'.  You may also be able to fix the problem
  703.      for real by getting a replacement motherboard.  This problem was
  704.      observed in Revision E of the Micronics motherboard, and is fixed
  705.      in Revision F.
  706.    * On some 386 systems, GNU CC crashes trying to compile `enquire.c'.
  707.      This happens on machines that don't have a 387 FPU chip.  On 386
  708.      machines, the system kernel is supposed to emulate the 387 when you
  709.      don't have one.  The crash is due to a bug in the emulator.
  710.      One of these systems is the Unix from Interactive Systems: 386/ix.
  711.      On this system, an alternate emulator is provided, and it does
  712.      work. To use it, execute this command as super-user:
  713.           ln /etc/emulator.rel1 /etc/emulator
  714.      and then reboot the system.  (The default emulator file remains
  715.      present under the name `emulator.dflt'.)
  716.      If you have such a problem on the SCO system, try using
  717.      `/etc/emulator.att'.
  718.      Another system which has this problem is Esix.  We don't know
  719.      whether it has an alternate emulator that works.
  720.    * Sometimes on a Sun 4 you may observe a crash in the program
  721.      `genflags' or `genoutput' while building GNU CC.  This is said to
  722.      be due to a bug in `sh'.  You can probably get around it by running
  723.      `genflags' or `genoutput' manually and then retrying the `make'.
  724.    * If you use the 1.31 version of the MIPS assembler (such as was
  725.      shipped with Ultrix 3.1), you will need to use the
  726.      -fno-delayed-branch switch when optimizing floating point code. 
  727.      Otherwise, the assembler will complain when the GCC compiler fills
  728.      a branch delay slot with a floating point instruction, such as
  729.      add.d.
  730.    * Users have reported some problems with version 2.0 of the MIPS
  731.      compiler tools that were shipped with Ultrix 4.1.  Version 2.10
  732.      which came with Ultrix 4.2 seems to work fine.
  733.    * Some versions of the MIPS linker will issue an assertion failure
  734.      when linking code that uses `alloca' against shared libraries on
  735.      RISC-OS 5.0, and DEC's OSF/1 systems.  This is a bug in the
  736.      linker, that is supposed to be fixed in future revisions. To
  737.      protect against this, GCC passes `-non_shared' to the linker
  738.      unless you pass an explicit `-shared' switch.
  739.    * On System V release 3, you may get this error message while
  740.      linking:
  741.           ld fatal: failed to write symbol name SOMETHING
  742.            in strings table for file WHATEVER
  743.      This indicates that the disk is full or your ULIMIT won't allow
  744.      the file to be as large as it needs to be.
  745.    * On HP 9000 series 300 or 400 running HP-UX release 8.0, there is a
  746.      bug in the assembler that must be fixed before GNU CC can be
  747.      built.  This bug manifests itself during the first stage of
  748.      compilation, while building `libgcc2.a':
  749.           _floatdisf
  750.           cc1: warning: `-g' option not supported on this version of GCC
  751.           cc1: warning: `-g1' option not supported on this version of GCC
  752.           ./gcc: Internal compiler error: program as got fatal signal 11
  753.      A patched version of the assembler is available by anonymous ftp
  754.      from `altdorf.ai.mit.edu' as the file
  755.      `archive/cph/hpux-8.0-assembler'.  If you have HP software support,
  756.      the patch can also be obtained directly from HP, as described in
  757.      the following note:
  758.           This is the patched assembler, to patch SR#1653-010439, where
  759.           the assembler aborts on floating point constants.
  760.           The bug is not really in the assembler, but in the shared
  761.           library version of the function "cvtnum(3c)".  The bug on
  762.           "cvtnum(3c)" is SR#4701-078451.  Anyway, the attached
  763.           assembler uses the archive library version of "cvtnum(3c)"
  764.           and thus does not exhibit the bug.
  765.      This patch is also known as PHCO_0800.
  766.    * Another assembler problem on the HP PA results in an error message
  767.      like this while compiling part of `libgcc2.a':
  768.           as: /usr/tmp/cca08196.s @line#30 [err#1060]
  769.             Argument 1 or 3 in FARG upper
  770.                    - lookahead = RTNVAL=GR
  771.      This happens because HP changed the assembler syntax after system
  772.      release 8.02.  GNU CC assumes the newer syntax; if your assembler
  773.      wants the older syntax, comment out this line in the file
  774.      `pa1-hpux.h':
  775.           #define HP_FP_ARG_DESCRIPTOR_REVERSED
  776.    * Some versions of the Pyramid C compiler are reported to be unable
  777.      to compile GNU CC.  You must use an older version of GNU CC for
  778.      bootstrapping.  One indication of this problem is if you get a
  779.      crash when GNU CC compiles the function `muldi3' in file
  780.      `libgcc2.c'.
  781.      You may be able to succeed by getting GNU CC version 1, installing
  782.      it, and using it to compile GNU CC version 2.  The bug in the
  783.      Pyramid C compiler does not seem to affect GNU CC version 1.
  784.    * On the Tower models 4N0 and 6N0, by default a process is not
  785.      allowed to have more than one megabyte of memory.  GNU CC cannot
  786.      compile itself (or many other programs) with `-O' in that much
  787.      memory.
  788.      To solve this problem, reconfigure the kernel adding the following
  789.      line to the configuration file:
  790.           MAXUMEM = 4096
  791.    * On the Altos 3068, programs compiled with GNU CC won't work unless
  792.      you fix a kernel bug.  This happens using system versions V.2.2
  793.      1.0gT1 and V.2.2 1.0e and perhaps later versions as well.  See the
  794.      file `README.ALTOS'.
  795.    * You will get several sorts of compilation and linking errors on the
  796.      we32k if you don't follow the special instructions.  *Note WE32K
  797.      Install::.
  798. File: gcc.info,  Node: Cross-Compiler Problems,  Next: Interoperation,  Prev: Installation Problems,  Up: Trouble
  799. Cross-Compiler Problems
  800. =======================
  801.    * Cross compilation can run into trouble for certain machines because
  802.      some target machines' assemblers require floating point numbers to
  803.      be written as *integer* constants in certain contexts.
  804.      The compiler writes these integer constants by examining the
  805.      floating point value as an integer and printing that integer,
  806.      because this is simple to write and independent of the details of
  807.      the floating point representation.  But this does not work if the
  808.      compiler is running on a different machine with an incompatible
  809.      floating point format, or even a different byte-ordering.
  810.      In addition, correct constant folding of floating point values
  811.      requires representing them in the target machine's format. (The C
  812.      standard does not quite require this, but in practice it is the
  813.      only way to win.)
  814.      It is now possible to overcome these problems by defining macros
  815.      such as `REAL_VALUE_TYPE'.  But doing so is a substantial amount of
  816.      work for each target machine.  *Note Cross-compilation::.
  817.    * At present, the program `mips-tfile' which adds debug support to
  818.      object files on MIPS systems does not work in a cross compile
  819.      environment.
  820.