home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / gccdoc1.zip / EXTEND.TXT < prev    next >
Text File  |  1992-05-22  |  68KB  |  2,179 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.           1.  GNU Extensions to the C Language
  9.  
  10.                GNU C provides several language features not  found  in
  11.           ANSI  standard C.  (The `-pedantic' option directs GNU CC to
  12.           print a warning message if any of these features  is  used.)
  13.           To  test  for  the  availability of these features in condi-
  14.           tional compilation, check for a predefined  macro  __GNUC__,
  15.           which is always defined under GNU CC.
  16.  
  17.  
  18.  
  19.           1.1.  Statements and Declarations within Expressions
  20.  
  21.                A compound statement in parentheses may  appear  inside
  22.           an  expression  in  GNU C.  This allows you to declare vari-
  23.           ables within an expression.  For example:
  24.  
  25.  
  26.               ({ int y = foo (); int z;
  27.                  if (y > 0) z = y;
  28.                  else z = - y;
  29.                  z; })
  30.  
  31.  
  32.  
  33.           is a valid (though slightly  more  complex  than  necessary)
  34.           expression for the absolute value of foo ().
  35.  
  36.                This feature  is  especially  useful  in  making  macro
  37.           definitions  ``safe''  (so  that  they evaluate each operand
  38.           exactly once).  For example,  the  ``maximum''  function  is
  39.           commonly defined as a macro in standard C as follows:
  40.  
  41.  
  42.               #define max(a,b) ((a) > (b) ? (a) : (b))
  43.  
  44.  
  45.  
  46.           But this definition computes either a or b twice,  with  bad
  47.           results  if  the operand has side effects.  In GNU C, if you
  48.           know the type of the operands (here let's assume  int),  you
  49.           can define the macro safely as follows:
  50.  
  51.  
  52.               #define maxint(a,b) \
  53.                 ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
  54.  
  55.  
  56.  
  57.                Embedded statements are not allowed in constant expres-
  58.           sions,  such  as  the  value of an enumeration constant, the
  59.           width of a bit field, or the initial value of a static vari-
  60.           able.
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.                If you don't know the type  of  the  operand,  you  can
  75.           still do this, but you must use typeof (see section  Typeof)
  76.           or type naming (see section  Naming Types).
  77.  
  78.           1.2.  Locally Declared Labels
  79.  
  80.                Each statement expression is a  scope  in  which  local
  81.           labels can be declared.  A local label is simply an identif-
  82.           ier; you can jump to it with an ordinary goto statement, but
  83.           only from within the statement expression it belongs to.
  84.  
  85.                A local label declaration looks like this:
  86.  
  87.  
  88.               __label__ label;
  89.  
  90.  
  91.  
  92.           or
  93.  
  94.  
  95.               __label__ label1, label2, ...;
  96.  
  97.  
  98.  
  99.                Local label declarations must come at the beginning  of
  100.           the  statement  expression, right after the `({', before any
  101.           ordinary declarations.
  102.  
  103.                The label declaration defines the label name, but  does
  104.           not  define the label itself.  You must do this in the usual
  105.           way, with label:, within the  statements  of  the  statement
  106.           expression.
  107.  
  108.                The local label feature  is  useful  because  statement
  109.           expressions are often used in macros.  If the macro contains
  110.           nested loops, a goto can be useful for breaking out of them.
  111.           However, an ordinary label whose scope is the whole function
  112.           cannot be used: if the macro can be expanded  several  times
  113.           in  one function, the label will be multiply defined in that
  114.           function.  A local label avoids this problem.  For example:
  115.  
  116.  
  117.               #define SEARCH(array, target)                     \
  118.               ({                                               \
  119.                 __label__ found;                                \
  120.                 typeof (target) _SEARCH_target = (target);      \
  121.                 typeof (*(array)) *_SEARCH_array = (array);     \
  122.                 int i, j;                                       \
  123.                 int value;                                      \
  124.                 for (i = 0; i < max; i++)                       \
  125.                   for (j = 0; j < max; j++)                     \
  126.                     if (_SEARCH_array[i][j] == _SEARCH_target)  \
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.                       { value = i; goto found; }              \
  141.                 value = -1;                                     \
  142.                found:                                           \
  143.                 value;                                          \
  144.               })
  145.  
  146.  
  147.  
  148.           1.3.  Labels as Values
  149.  
  150.                You can get the address  of  a  label  defined  in  the
  151.           current  function  (or a containing function) with the unary
  152.           operator `&&'.  The value has type void *.  This value is  a
  153.           constant and can be used wherever a constant of that type is
  154.           valid.  For example:
  155.  
  156.  
  157.               void *ptr;
  158.               ...
  159.               ptr = &&foo;
  160.  
  161.  
  162.  
  163.                To use these values, you need to be  able  to  jump  to
  164.           one.  This is done with the  computed  goto  statementThe  ,
  165.           goto *exp;.  For example,
  166.  
  167.  
  168.               goto *ptr;
  169.  
  170.  
  171.  
  172.           Any expression of type void * is allowed.
  173.  
  174.                One way of using these constants is in  initializing  a
  175.           static array that will serve as a jump table:
  176.  
  177.  
  178.               static void *array[] = { &&foo, &&bar, &&hack };
  179.  
  180.  
  181.  
  182.                Then you can select a label with indexing, like this:
  183.  
  184.  
  185.               goto *array[i];
  186.  
  187.           ____________________
  188.              The analogous feature in Fortran is  called  an  assigned
  189.           goto,  but that name seems inappropriate in C, where one can
  190.           do more than simply store label  addresses  in  label  vari-
  191.           ables.
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.           Note that this does not check whether the  subscript  is  in
  209.           bounds---array indexing in C never does that.
  210.  
  211.                Such an array of label values  serves  a  purpose  much
  212.           like  that of the switch statement.  The switch statement is
  213.           cleaner, so use that rather than an array unless the problem
  214.           does not fit a switch statement very well.
  215.  
  216.                Another use of label values is in  an  interpreter  for
  217.           threaded  code.   The labels within the interpreter function
  218.           can be stored in the threaded code for super-fast  dispatch-
  219.           ing.
  220.  
  221.           1.4.  Nested Functions
  222.  
  223.                A nested function is a function defined inside  another
  224.           function.   The nested function's name is local to the block
  225.           where it is defined.  For example, here we define  a  nested
  226.           function named square, and call it twice:
  227.  
  228.  
  229.               foo (double a, double b)
  230.               {
  231.                 double square (double z) { return z * z; }
  232.  
  233.                 return square (a) + square (b);
  234.               }
  235.  
  236.  
  237.  
  238.                The nested function can access all the variables of the
  239.           containing  function  that  are  visible at the point of its
  240.           definition.  This is called lexical scoping.   For  example,
  241.           here we show a nested function which uses an inherited vari-
  242.           able named offset:
  243.  
  244.  
  245.               bar (int *array, int offset, int size)
  246.               {
  247.                 int access (int *array, int index)
  248.                   { return array[index + offset]; }
  249.                 int i;
  250.                 ...
  251.                 for (i = 0; i < size; i++)
  252.                   ... access (array, i) ...
  253.               }
  254.  
  255.  
  256.  
  257.                It is possible to call the nested function from outside
  258.           the  scope of its name by storing its address or passing the
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.           address to another function:
  273.  
  274.  
  275.               hack (int *array, int size)
  276.               {
  277.                 void store (int index, int value)
  278.                   { array[index] = value; }
  279.  
  280.                 intermediate (store, size);
  281.               }
  282.  
  283.  
  284.  
  285.                Here, the function intermediate receives the address of
  286.           store  as  an  argument.   If  intermediate calls store, the
  287.           arguments given to store are used to store into array.   But
  288.           this technique works only so long as the containing function
  289.           (hack, in this example) does not exit.  If you try  to  call
  290.           the nested function through its address after the containing
  291.           function has exited, all hell will break loose.
  292.  
  293.                A nested function can jump to a label inherited from  a
  294.           containing  function,  provided  the  label  was  explicitly
  295.           declared in the  containing  function  (see  section   Local
  296.           Labels).   Such  a  jump returns instantly to the containing
  297.           function, exiting the nested function which did the goto and
  298.           any intermediate functions as well.  Here is an example:
  299.  
  300.  
  301.               bar (int *array, int offset, int size)
  302.               {
  303.                 __label__ failure;
  304.                 int access (int *array, int index)
  305.                   {
  306.                     if (index > size)
  307.                       goto failure;
  308.                     return array[index + offset];
  309.                   }
  310.                 int i;
  311.                 ...
  312.                 for (i = 0; i < size; i++)
  313.                   ... access (array, i) ...
  314.                 ...
  315.                 return 0;
  316.  
  317.                /* Control comes here from access
  318.                   if it detects an error.  */
  319.                failure:
  320.                 return -1;
  321.               }
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.                A nested function always has internal linkage.  Declar-
  339.           ing  one  with  extern is erroneous.  If you need to declare
  340.           the nested function before its definition, use  auto  (which
  341.           is otherwise meaningless for function declarations).
  342.  
  343.  
  344.               bar (int *array, int offset, int size)
  345.               {
  346.                 __label__ failure;
  347.                 auto int access (int *, int);
  348.                 ...
  349.                 int access (int *array, int index)
  350.                   {
  351.                     if (index > size)
  352.                       goto failure;
  353.                     return array[index + offset];
  354.                   }
  355.                 ...
  356.               }
  357.  
  358.  
  359.  
  360.           1.5.  Naming an Expression's Type
  361.  
  362.                You can give a name to the type of an expression  using
  363.           a  typedef  declaration with an initializer.  Here is how to
  364.           define name as a type name for the type of exp:
  365.  
  366.  
  367.               typedef name = exp;
  368.  
  369.  
  370.  
  371.                This is useful  in  conjunction  with  the  statements-
  372.           within-expressions  feature.   Here  is how the two together
  373.           can be used to define a safe ``maximum'' macro that operates
  374.           on any arithmetic type:
  375.  
  376.  
  377.               #define max(a,b) \
  378.                 ({typedef _ta = (a), _tb = (b);  \
  379.                   _ta _a = (a); _tb _b = (b);     \
  380.                   _a > _b ? _a : _b; })
  381.  
  382.  
  383.  
  384.                The reason for using names that start with  underscores
  385.           for  the local variables is to avoid conflicts with variable
  386.           names that occur within the expressions that are substituted
  387.           for  a  and  b.   Eventually we hope to design a new form of
  388.           declaration syntax that  allows  you  to  declare  variables
  389.           whose  scopes start only after their initializers; this will
  390.           be a more reliable way to prevent such conflicts.
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.           1.6.  Referring to a Type with typeof
  405.  
  406.                Another way to refer to the type of  an  expression  is
  407.           with typeof.  The syntax of using of this keyword looks like
  408.           sizeof, but the construct acts semantically like a type name
  409.           defined with typedef.
  410.  
  411.                There are two ways of writing the argument  to  typeof:
  412.           with  an expression or with a type.  Here is an example with
  413.           an expression:
  414.  
  415.  
  416.               typeof (x[0](1))
  417.  
  418.  
  419.  
  420.           This assumes that x is  an  array  of  functions;  the  type
  421.           described is that of the values of the functions.
  422.  
  423.                Here is an example with a typename as the argument:
  424.  
  425.  
  426.               typeof (int *)
  427.  
  428.  
  429.  
  430.           Here the type described is that of pointers to int.
  431.  
  432.                If you are writing a header file that  must  work  when
  433.           included  in  ANSI  C  programs, write __typeof__ instead of
  434.           typeof.  See section Alternate Keywords.
  435.  
  436.                A typeof-construct can be used anywhere a typedef  name
  437.           could  be  used.   For example, you can use it in a declara-
  438.           tion, in a cast, or inside of sizeof or typeof.
  439.  
  440.                o+    This declares y with the type of what x points to.
  441.  
  442.  
  443.                         typeof (*x) y;
  444.  
  445.  
  446.  
  447.                o+    This declares y as an array of such values.
  448.  
  449.  
  450.                         typeof (*x) y[4];
  451.  
  452.  
  453.  
  454.                o+    This declares y as an  array  of  pointers  to
  455.                     characters:
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.                         typeof (typeof (char *)[4]) y;
  472.  
  473.  
  474.  
  475.                It is equivalent to the following traditional C de-
  476.                claration:
  477.  
  478.  
  479.                         char *y[4];
  480.  
  481.  
  482.  
  483.                     To see the meaning of  the  declaration  using
  484.                     typeof,  and  why  it might be a useful way to
  485.                     write, let's rewrite it with these macros:
  486.  
  487.  
  488.                         #define pointer(T)  typeof(T *)
  489.                         #define array(T, N) typeof(T [N])
  490.  
  491.  
  492.  
  493.                Now the declaration can be rewritten this way:
  494.  
  495.  
  496.                         array (pointer (char), 4) y;
  497.  
  498.  
  499.  
  500.                Thus, array (pointer (char), 4) is the type of  ar-
  501.                rays of 4 pointers to char.
  502.  
  503.  
  504.           1.7.  Generalized Lvalues     Compound  expressions,  condi-
  505.           tional expressions and casts are allowed as lvalues provided
  506.           their operands are lvalues.  This means that  you  can  take
  507.           their addresses or store values into them.
  508.  
  509.                For example, a compound  expression  can  be  assigned,
  510.           provided  the  last expression in the sequence is an lvalue.
  511.           These two expressions are equivalent:
  512.  
  513.  
  514.               (a, b) += 5
  515.               a, (b += 5)
  516.  
  517.  
  518.  
  519.                Similarly, the address of the compound  expression  can
  520.           be taken.  These two expressions are equivalent:
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.               &(a, b)
  538.               a, &b
  539.  
  540.  
  541.  
  542.                A conditional expression is a valid lvalue if its  type
  543.           is  not  void and the true and false branches are both valid
  544.           lvalues.  For example, these two expressions are equivalent:
  545.  
  546.  
  547.               (a ? b : c) = 5
  548.               (a ? b = 5 : (c = 5))
  549.  
  550.  
  551.  
  552.                A cast is a valid lvalue if its operand is  an  lvalue.
  553.           A  simple assignment whose left-hand side is a cast works by
  554.           converting the right-hand side first to the specified  type,
  555.           then  to  the  type  of the inner left-hand side expression.
  556.           After this is stored, the value is  converted  back  to  the
  557.           specified type to become the value of the assignment.  Thus,
  558.           if a has type char *,  the  following  two  expressions  are
  559.           equivalent:
  560.  
  561.  
  562.               (int)a = 5
  563.               (int)(a = (char *)(int)5)
  564.  
  565.  
  566.  
  567.                An assignment-with-arithmetic operation  such  as  `+='
  568.           applied  to  a  cast  performs the arithmetic using the type
  569.           resulting from the cast, and then continues as in the previ-
  570.           ous case.  Therefore, these two expressions are equivalent:
  571.  
  572.  
  573.               (int)a += 5
  574.               (int)(a = (char *)(int) ((int)a + 5))
  575.  
  576.  
  577.  
  578.                You cannot take the address of an lvalue cast,  because
  579.           the  use of its address would not work out coherently.  Sup-
  580.           pose that &(int)f were permitted, where f  has  type  float.
  581.           Then  the  following statement would try to store an integer
  582.           bit-pattern where a floating point number belongs:
  583.  
  584.  
  585.               *&(int)f = 1;
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.                This is quite different from what (int)f = 1 would  do-
  603.           --that  would  convert  1  to  floating  point and store it.
  604.           Rather than cause this inconsistancy, we think it is  better
  605.           to prohibit use of `&' on a cast.
  606.  
  607.                If you really do want an int * pointer with the address
  608.           of f, you can simply write (int *)&f.
  609.  
  610.           1.8.  Conditional Expressions with Omitted Operands
  611.  
  612.                The middle operand in a conditional expression  may  be
  613.           omitted.  Then if the first operand is nonzero, its value is
  614.           the value of the conditional expression.
  615.  
  616.                Therefore, the expression
  617.  
  618.  
  619.               x ? : y
  620.  
  621.  
  622.  
  623.           has the value of x if that is nonzero; otherwise, the  value
  624.           of y.
  625.  
  626.                This example is perfectly equivalent to
  627.  
  628.  
  629.               x ? x : y
  630.  
  631.  
  632.  
  633.           In this simple case, the ability to omit the middle  operand
  634.           is  not  especially  useful.  When it becomes useful is when
  635.           the first operand does, or may (if it is a macro  argument),
  636.           contain  a  side  effect.  Then repeating the operand in the
  637.           middle would perform the side effect  twice.   Omitting  the
  638.           middle  operand  uses the value already computed without the
  639.           undesirable effects of recomputing it.
  640.  
  641.           1.9.  Double-Word Integers
  642.  
  643.                GNU C supports data types for integers that  are  twice
  644.           as  long  as  long  int.   Simply  write long long int for a
  645.           signed integer, or unsigned long long int  for  an  unsigned
  646.           integer.
  647.  
  648.                You can use these types in arithmetic  like  any  other
  649.           integer  types.   Addition, subtraction, and bitwise boolean
  650.           operations on these types are open-coded  on  all  types  of
  651.           machines.   Multiplication is open-coded if the machine sup-
  652.           ports fullword-to-doubleword a  widening  multiply  instruc-
  653.           tion.   Division  and shifts are open-coded only on machines
  654.           that provide special support.  The operations that  are  not
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.           open-coded  use  special library routines that come with GNU
  669.           CC.
  670.  
  671.                There may be pitfalls when you use long long types  for
  672.           function  arguments, unless you declare function prototypes.
  673.           If a function expects type int for  its  argument,  and  you
  674.           pass  a  value  of type long long int, confusion will result
  675.           because the caller and the subroutine  will  disagree  about
  676.           the  number  of  bytes  for  the argument.  Likewise, if the
  677.           function expects long long int and you pass int.   The  best
  678.           way to avoid such problems is to use prototypes.
  679.  
  680.           1.10.  Arrays of Length Zero
  681.  
  682.                Zero-length arrays are allowed in GNU C.  They are very
  683.           useful  as the last element of a structure which is really a
  684.           header for a variable-length object:
  685.  
  686.  
  687.               struct line {
  688.                 int length;
  689.                 char contents[0];
  690.               };
  691.  
  692.               {
  693.                 struct line *thisline = (struct line *)
  694.                   malloc (sizeof (struct line) + this_length);
  695.                 thisline->length = this_length;
  696.               }
  697.  
  698.  
  699.  
  700.                In standard C, you would have to give contents a length
  701.           of  1,  which means either you waste space or complicate the
  702.           argument to malloc.
  703.  
  704.           1.11.  Arrays of Variable Length
  705.  
  706.                Variable-length automatic arrays are allowed in GNU  C.
  707.           These  arrays  are declared like any other automatic arrays,
  708.           but with a length that is not a  constant  expression.   The
  709.           storage is allocated at the point of declaration and deallo-
  710.           cated when the brace-level is exited.  For example:
  711.  
  712.  
  713.               FILE *
  714.               concat_fopen (char *s1, char *s2, char *mode)
  715.               {
  716.                 char str[strlen (s1) + strlen (s2) + 1];
  717.                 strcpy (str, s1);
  718.                 strcat (str, s2);
  719.                 return fopen (str, mode);
  720.               }
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733.  
  734.  
  735.  
  736.                Jumping or breaking out of the scope of the array  name
  737.           deallocates  the  storage.   Jumping  into  the scope is not
  738.           allowed; you get an error message for it.
  739.  
  740.                You can use the function alloca to get an  effect  much
  741.           like  variable-length arrays.  The function alloca is avail-
  742.           able in many other C implementations (but not in  all).   On
  743.           the other hand, variable-length arrays are more elegant.
  744.  
  745.                There are other differences between these two  methods.
  746.           Space  allocated  with  alloca  exists  until the containing
  747.           function returns.  The space for a variable-length array  is
  748.           deallocated as soon as the array name's scope ends.  (If you
  749.           use both variable-length arrays and alloca in the same func-
  750.           tion,  deallocation  of  a  variable-length  array will also
  751.           deallocate anything more recently allocated with alloca.)
  752.  
  753.                You can also use variable-length arrays as arguments to
  754.           functions:
  755.  
  756.  
  757.               struct entry
  758.               tester (int len, char data[len][len])
  759.               {
  760.                 ...
  761.               }
  762.  
  763.  
  764.  
  765.                The length of  an  array  is  computed  once  when  the
  766.           storage  is allocated and is remembered for the scope of the
  767.           array in case you access it with sizeof.
  768.  
  769.                If you want to pass the  array  first  and  the  length
  770.           afterward,  you can use a forward declaration in the parame-
  771.           ter list---another GNU extension.
  772.  
  773.  
  774.               struct entry
  775.               tester (int len; char data[len][len], int len)
  776.               {
  777.                 ...
  778.               }
  779.  
  780.  
  781.  
  782.                The `int len' before the semicolon is a parameter  for-
  783.           ward  declaration,  and  it serves the purpose of making the
  784.           name len known when the declaration of data is parsed.
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800.                You can write any  number  of  such  parameter  forward
  801.           declarations  in  the parameter list.  They can be separated
  802.           by commas or semicolons, but the last one must  end  with  a
  803.           semicolon,  which  is  followed  by  the  ``real'' parameter
  804.           declarations.   Each  forward  declaration  must   match   a
  805.           ``real'' declaration in parameter name and data type.
  806.  
  807.           1.12.  Non-Lvalue Arrays May Have Subscripts
  808.  
  809.                Subscripting is allowed on arrays that are not lvalues,
  810.           even  though  the  unary  `&' operator is not.  For example,
  811.           this is valid in GNU C though not valid in other C dialects:
  812.  
  813.  
  814.               struct foo {int a[4];};
  815.  
  816.               struct foo f();
  817.  
  818.               bar (int index)
  819.               {
  820.                 return f().a[index];
  821.               }
  822.  
  823.  
  824.  
  825.           1.13.  Arithmetic on void- and Function-Pointers
  826.  
  827.                In GNU C, addition and subtraction operations are  sup-
  828.           ported  on  pointers  to  void and on pointers to functions.
  829.           This is done by treating the size of a void or of a function
  830.           as 1.
  831.  
  832.                A consequence of this is that sizeof is also allowed on
  833.           void and on function types, and returns 1.
  834.  
  835.                The option  `-Wpointer-arith'  requests  a  warning  if
  836.           these extensions are used.
  837.  
  838.           1.14.  Non-Constant Initializers
  839.  
  840.                The  elements  of  an  aggregate  initializer  for   an
  841.           automatic  variable  are not required to be constant expres-
  842.           sions in GNU C.  Here is an example of an  initializer  with
  843.           run-time varying elements:
  844.  
  845.  
  846.               foo (float f, float g)
  847.               {
  848.                 float beat_freqs[2] = { f-g, f+g };
  849.                 ...
  850.               }
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864.  
  865.  
  866.           1.15.  Constructor Expressions
  867.  
  868.                GNU C supports constructor expressions.  A  constructor
  869.           looks  like  a cast containing an initializer.  Its value is
  870.           an object of the type specified in the cast, containing  the
  871.           elements specified in the initializer.
  872.  
  873.                Usually, the specified type  is  a  structure.   Assume
  874.           that struct foo and structure are declared as shown:
  875.  
  876.  
  877.               struct foo {int a; char b[2];} structure;
  878.  
  879.  
  880.  
  881.           Here is an example of constructing a struct foo with a  con-
  882.           structor:
  883.  
  884.  
  885.               structure = ((struct foo) {x + y, 'a', 0});
  886.  
  887.  
  888.  
  889.           This is equivalent to writing the following:
  890.  
  891.  
  892.               {
  893.                 struct foo temp = {x + y, 'a', 0};
  894.                 structure = temp;
  895.               }
  896.  
  897.  
  898.  
  899.                You can also construct an array.  If all  the  elements
  900.           of  the constructor are (made up of) simple constant expres-
  901.           sions, suitable for use in initializers, then the  construc-
  902.           tor  is  an  lvalue  and  can be coerced to a pointer to its
  903.           first element, as shown here:
  904.  
  905.  
  906.               char **foo = (char *[]) { "x", "y", "z" };
  907.  
  908.  
  909.  
  910.                Array constructors whose elements are not  simple  con-
  911.           stants  are  not very useful, because the constructor is not
  912.           an lvalue.  There are only two valid ways to use it: to sub-
  913.           script  it,  or  initialize  an array variable with it.  The
  914.           former is probably slower than a switch statement, while the
  915.           latter  does  the same thing an ordinary C initializer would
  916.           do.  Here is an example of subscripting an  array  construc-
  917.           tor:
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933.               output = ((int[]) { 2, x, 28 }) [input];
  934.  
  935.  
  936.  
  937.                Constructor expressions  for  scalar  types  and  union
  938.           types  are is also allowed, but then the constructor expres-
  939.           sion is equivalent to a cast.
  940.  
  941.           1.16.  Labeled Elements in Initializers
  942.  
  943.                Standard C requires the elements of an  initializer  to
  944.           appear  in  a fixed order, the same as the order of the ele-
  945.           ments in the array or structure being initialized.
  946.  
  947.                In GNU C you can give the elements in any order, speci-
  948.           fying  the array indices or structure field names they apply
  949.           to.
  950.  
  951.                To specify an array index, write `[index]'  before  the
  952.           element value.  For example,
  953.  
  954.  
  955.               int a[6] = { [4] 29, [2] 15 };
  956.  
  957.  
  958.  
  959.           is equivalent to
  960.  
  961.  
  962.               int a[6] = { 0, 0, 15, 0, 29, 0 };
  963.  
  964.  
  965.  
  966.           The index values must be constant expressions, even  if  the
  967.           array being initialized is automatic.
  968.  
  969.                In a structure initializer, specify the name of a field
  970.           to  initialize  with  `fieldname:' before the element value.
  971.           For example, given the following structure,
  972.  
  973.  
  974.               struct point { int x, y; };
  975.  
  976.  
  977.  
  978.           the following initialization
  979.  
  980.  
  981.               struct point p = { y: yvalue, x: xvalue };
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.           is equivalent to
  999.  
  1000.  
  1001.               struct point p = { xvalue, yvalue };
  1002.  
  1003.  
  1004.  
  1005.                You can also use an element label when  initializing  a
  1006.           union, to specify which element of the union should be used.
  1007.           For example,
  1008.  
  1009.  
  1010.               union foo { int i; double d; };
  1011.  
  1012.               union foo f = { d: 4 };
  1013.  
  1014.  
  1015.  
  1016.           will convert 4 to a double to store it in  the  union  using
  1017.           the  second  element.   By contrast, casting 4 to type union
  1018.           foo would store it into the union as the integer i, since it
  1019.           is an integer.  (See section Cast to Union.)
  1020.  
  1021.                You can combine this technique of naming elements  with
  1022.           ordinary C initialization of successive elements.  Each ini-
  1023.           tializer element that does not have a label applies  to  the
  1024.           next  consecutive  element  of  the array or structure.  For
  1025.           example,
  1026.  
  1027.  
  1028.               int a[6] = { [1] v1, v2, [4] v4 };
  1029.  
  1030.  
  1031.  
  1032.           is equivalent to
  1033.  
  1034.  
  1035.               int a[6] = { 0, v1, v2, 0, v4, 0 };
  1036.  
  1037.  
  1038.  
  1039.                Labeling the elements of an array initializer is  espe-
  1040.           cially  useful  when the indices are characters or belong to
  1041.           an enum type.  For example:
  1042.  
  1043.  
  1044.               int whitespace[256]
  1045.                 = { [' '] 1, ['\t'] 1, ['\h'] 1,
  1046.                     ['\f'] 1, ['\n'] 1, ['\r'] 1 };
  1047.  
  1048.  
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.  
  1061.  
  1062.  
  1063.  
  1064.           1.17.  Case Ranges
  1065.  
  1066.                You can specify a range of consecutive values in a sin-
  1067.           gle case label, like this:
  1068.  
  1069.  
  1070.               case low ... high:
  1071.  
  1072.  
  1073.  
  1074.           This has the same effect as the proper number of  individual
  1075.           case  labels,  one  for each integer value from low to high,
  1076.           inclusive.
  1077.  
  1078.                This feature is especially useful for ranges  of  ASCII
  1079.           character codes:
  1080.  
  1081.  
  1082.               case 'A' ... 'Z':
  1083.  
  1084.  
  1085.  
  1086.                Be careful: Write spaces around the ..., for  otherwise
  1087.           it  may be parsed wrong when you use it with integer values.
  1088.           For example, write this:
  1089.  
  1090.  
  1091.               case 1 ... 5:
  1092.  
  1093.  
  1094.  
  1095.            rather than this:
  1096.  
  1097.  
  1098.               case 1...5:
  1099.  
  1100.  
  1101.  
  1102.           1.18.  Cast to a Union Type
  1103.  
  1104.                A cast to union type is like  any  other  cast,  except
  1105.           that  the  type  specified is a union type.  You can specify
  1106.           the type either with union tag or with a typedef name.
  1107.  
  1108.                The types that may be cast to the union type are  those
  1109.           of  the  members  of  the  union.  Thus, given the following
  1110.           union and variables:
  1111.  
  1112.  
  1113.               union foo { int i; double d; };
  1114.               int x;
  1115.               double y;
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.           both x and y can be cast to type union foo.
  1133.  
  1134.                Using the cast as the right-hand side of an  assignment
  1135.           to  a  variable  of union type is equivalent to storing in a
  1136.           member of the union:
  1137.  
  1138.  
  1139.               union foo u;
  1140.               ...
  1141.               u = (union foo) x  =_  u.i = x
  1142.               u = (union foo) y  =_  u.d = y
  1143.  
  1144.  
  1145.  
  1146.                You can also use the union cast as a function argument:
  1147.  
  1148.  
  1149.               void hack (union foo);
  1150.               ...
  1151.               hack ((union foo) x);
  1152.  
  1153.  
  1154.  
  1155.           1.19.  Declaring Attributes of Functions
  1156.  
  1157.                In GNU C, you declare certain  things  about  functions
  1158.           called  in  your  program  which  help the compiler optimize
  1159.           function calls.
  1160.  
  1161.                A few standard library functions,  such  as  abort  and
  1162.           exit, cannot return.  GNU CC knows this automatically.  Some
  1163.           programs define their own functions that never return.   You
  1164.           can  declare  them  volatile to tell the compiler this fact.
  1165.           For example,
  1166.  
  1167.  
  1168.               extern void volatile fatal ();
  1169.  
  1170.               void
  1171.               fatal (...)
  1172.               {
  1173.                 ... /* Print error message. */ ...
  1174.                 exit (1);
  1175.               }
  1176.  
  1177.  
  1178.  
  1179.                The volatile keyword tells the compiler to assume  that
  1180.           fatal  cannot  return.  This makes slightly better code, but
  1181.           more importantly it helps avoid spurious warnings of  unini-
  1182.           tialized variables.
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194.  
  1195.  
  1196.                It does not make sense for a volatile function to  have
  1197.           a return type other than void.
  1198.  
  1199.                Many functions do not examine any values  except  their
  1200.           arguments,  and  have  no  effects  except the return value.
  1201.           Such a function can be subject to common subexpression elim-
  1202.           ination and loop optimization just as an arithmetic operator
  1203.           would be.  These functions should be  declared  const.   For
  1204.           example,
  1205.  
  1206.  
  1207.               extern int const square ();
  1208.  
  1209.  
  1210.  
  1211.           says that the hypothetical function square is safe  to  call
  1212.           fewer times than the program says.
  1213.  
  1214.                Note that a function that  has  pointer  arguments  and
  1215.           examines  the  data  pointed  to must not be declared const.
  1216.           Likewise, a function that calls a non-const function usually
  1217.           must not be const.  It does not make sense for a const func-
  1218.           tion to return void.
  1219.  
  1220.                We  recommend  placing  the  keyword  const  after  the
  1221.           function's return type.  It makes no difference in the exam-
  1222.           ple above, but when the return type is a pointer, it is  the
  1223.           only way to make the function itself const.  For example,
  1224.  
  1225.  
  1226.               const char *mincp (int);
  1227.  
  1228.  
  1229.  
  1230.           says that mincp returns const char *---a pointer to a  const
  1231.           object.  To declare mincp const, you must write this:
  1232.  
  1233.  
  1234.               char * const mincp (int);
  1235.  
  1236.                 Some people object to this  feature,  suggesting  that
  1237.           ANSI C's #pragma should be used instead.  There are two rea-
  1238.           sons for not doing this.
  1239.  
  1240.                1.   It is impossible to generate #pragma commands from
  1241.                     a macro.
  1242.  
  1243.                2.   The #pragma command is just  as  likely  as  these
  1244.                     keywords  to  mean  something else in another com-
  1245.                     piler.
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.  
  1259.  
  1260.  
  1261.  
  1262.                These two reasons apply to almost any application  that
  1263.           might be proposed for #pragma.  It is basically a mistake to
  1264.           use #pragma for anything.
  1265.  
  1266.           1.20.  Dollar Signs in Identifier Names
  1267.  
  1268.                In GNU C, you may use dollar signs in identifier names.
  1269.           This  is  because  many  traditional C implementations allow
  1270.           such identifiers.
  1271.  
  1272.                Dollar signs are allowed on  certain  machines  if  you
  1273.           specify  `-traditional'.   On a few systems they are allowed
  1274.           by default, even if `-traditional' is not  used.   But  they
  1275.           are never allowed if you specify `-ansi'.
  1276.  
  1277.                There are certain ANSI C programs (obscure, to be sure)
  1278.           that  would compile incorrectly if dollar signs were permit-
  1279.           ted in identifiers.  For example:
  1280.  
  1281.  
  1282.               #define foo(a) #a
  1283.               #define lose(b) foo (b)
  1284.               #define test$
  1285.               lose (test)
  1286.  
  1287.  
  1288.  
  1289.           1.21.  The Character ESC in Constants
  1290.  
  1291.                You can use the sequence `\e' in a string or  character
  1292.           constant to stand for the ASCII character ESC.
  1293.  
  1294.           1.22.  Inquiring on Alignment of Types or Variables
  1295.  
  1296.                The keyword __alignof__ allows you to inquire about how
  1297.           an  object  is  aligned,  or  the  minimum alignment usually
  1298.           required by a type.  Its syntax is just like sizeof.
  1299.  
  1300.                For example, if the target machine  requires  a  double
  1301.           value  to be aligned on an 8-byte boundary, then __alignof__
  1302.           (double) is 8.  This is true on many RISC machines.  On more
  1303.           traditional  machine  designs,  __alignof__ (double) is 4 or
  1304.           even 2.
  1305.  
  1306.                Some machines never actually  require  alignment;  they
  1307.           allow  reference  to any data type even at an odd addresses.
  1308.           For these  machines,  __alignof__  reports  the  recommended
  1309.           alignment of a type.
  1310.  
  1311.                When the operand of __alignof__  is  an  lvalue  rather
  1312.           than  a  type,  the  value is the largest alignment that the
  1313.           lvalue is known to have.  It may have this  alignment  as  a
  1314.           result  of  its  data  type,  or  because  it  is  part of a
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.           structure and inherits alignment from  that  structure.  For
  1329.           example, after this declaration:
  1330.  
  1331.  
  1332.               struct foo { int x; char y; } foo1;
  1333.  
  1334.  
  1335.  
  1336.           the value of __alignof__ (foo1.y) is probably 2  or  4,  the
  1337.           same  as  __alignof__  (int),  even  though the data type of
  1338.           foo1.y does not itself demand any alignment.
  1339.  
  1340.           1.23.  Specifying Attributes of Variables
  1341.  
  1342.                The keyword __attribute__ allows you to specify special
  1343.           attributes  of  variables  or  structure  fields.   The only
  1344.           attributes currently defined  are  the  aligned  and  format
  1345.           attributes.
  1346.  
  1347.                The aligned attribute specifies the  alignment  of  the
  1348.           variable or structure field.  For example, the declaration:
  1349.  
  1350.  
  1351.               int x __attribute__ ((aligned (16))) = 0;
  1352.  
  1353.  
  1354.  
  1355.           causes the compiler to allocate the global variable x  on  a
  1356.           16-byte  boundary.   On  a 68000, this could be used in con-
  1357.           junction  with  an  asm  expression  to  access  the  move16
  1358.           instruction which requires 16-byte aligned operands.
  1359.  
  1360.                You can also specify the alignment of structure fields.
  1361.           For  example,  to create a double-word aligned int pair, you
  1362.           could write:
  1363.  
  1364.  
  1365.               struct foo { int x[2] __attribute__ ((aligned (8))); };
  1366.  
  1367.  
  1368.  
  1369.           This is an alternative to creating a  union  with  a  double
  1370.           member that forces the union to be double-word aligned.
  1371.  
  1372.                It is not possible to specify the  alignment  of  func-
  1373.           tions;  the  alignment  of  functions  is  determined by the
  1374.           machine's requirements and cannot be changed.
  1375.  
  1376.                The format attribute specifies that  a  function  takes
  1377.           printf or scanf style arguments which should be type-checked
  1378.           against a format string.  For example, the declaration:
  1379.  
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.               extern int
  1396.               my_printf (void *my_object, const char *my_format, ...)
  1397.                     __attribute__ ((format (printf, 2, 3)));
  1398.  
  1399.  
  1400.  
  1401.           causes the compiler to  check  the  arguments  in  calls  to
  1402.           my_printf  for  consistency  with  the  printf  style format
  1403.           string argument my_format.
  1404.  
  1405.                The first parameter of the format attribute  determines
  1406.           how  the  format string is interpreted, and should be either
  1407.           printf or scanf.  The second parameter specifies the  number
  1408.           of  the format string argument (starting from 1).  The third
  1409.           parameter specifies the number of the first  argument  which
  1410.           should  be checked against the format string.  For functions
  1411.           where the arguments are not available to be checked (such as
  1412.           vprintf), specify the third parameter as zero.  In this case
  1413.           the compiler only checks the format string for consistency.
  1414.  
  1415.                In the example above, the format string (my_format)  is
  1416.           the  second  argument to my_print and the arguments to check
  1417.           start with the third argument, so the correct parameters for
  1418.           the format attribute are 2 and 3.
  1419.  
  1420.                The format attribute allows you to  identify  your  own
  1421.           functions  which  take  format strings as arguments, so that
  1422.           GNU CC can check the calls to these  functions  for  errors.
  1423.           The  compiler  always  checks  formats  for the ANSI library
  1424.           functions printf, fprintf, sprintf, scanf,  fscanf,  sscanf,
  1425.           vprintf,  vfprintf  and  vsprintf whenever such warnings are
  1426.           requested (using `-Wformat'), so there is no need to  modify
  1427.           the header file `stdio.h'.
  1428.  
  1429.           1.24.  An Inline Function is As Fast As a Macro
  1430.  
  1431.                By declaring a function inline, you can direct  GNU  CC
  1432.           to  integrate  that  function's  code  into the code for its
  1433.           callers.  This makes execution  faster  by  eliminating  the
  1434.           function-call  overhead;  in  addition, if any of the actual
  1435.           argument values are constant, their known values may  permit
  1436.           simplifications  at  compile  time  so  that  not all of the
  1437.           inline function's code needs to be included.
  1438.  
  1439.                To declare a function inline, use the inline keyword in
  1440.           its declaration, like this:
  1441.  
  1442.  
  1443.               inline int
  1444.               inc (int *a)
  1445.               {
  1446.                 (*a)++;
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.  
  1458.  
  1459.  
  1460.               }
  1461.  
  1462.  
  1463.  
  1464.                (If you are writing a header file  to  be  included  in
  1465.           ANSI  C  programs,  write __inline__ instead of inline.  See
  1466.           section Alternate Keywords.)
  1467.  
  1468.                You can  also  make  all  ``simple  enough''  functions
  1469.           inline with the option `-finline-functions'.  Note that cer-
  1470.           tain usages in a function definition can make it  unsuitable
  1471.           for inline substitution.
  1472.  
  1473.                When a function is both inline and static, if all calls
  1474.           to  the  function  are  integrated  into the caller, and the
  1475.           function's address is never used, then  the  function's  own
  1476.           assembler  code  is  never referenced.  In this case, GNU CC
  1477.           does not actually output assembler code  for  the  function,
  1478.           unless  you  specify  the  option `-fkeep-inline-functions'.
  1479.           Some calls cannot be integrated for various reasons (in par-
  1480.           ticular, calls that precede the function's definition cannot
  1481.           be integrated, and neither can recursive  calls  within  the
  1482.           definition).   If  there  is  a nonintegrated call, then the
  1483.           function is compiled to assembler code as usual.  The  func-
  1484.           tion must also be compiled as usual if the program refers to
  1485.           its address, because that can't be inlined.
  1486.  
  1487.                When an inline function is not static,  then  the  com-
  1488.           piler  must assume that there may be calls from other source
  1489.           files; since a global symbol can be defined only once in any
  1490.           program,  the  function  must  not  be  defined in the other
  1491.           source files, so the calls  therein  cannot  be  integrated.
  1492.           Therefore,  a  non-static inline function is always compiled
  1493.           on its own in the usual fashion.
  1494.  
  1495.                If you specify both inline and extern in  the  function
  1496.           definition,  then  the definition is used only for inlining.
  1497.           In no case is the function compiled on its own, not even  if
  1498.           you  refer  to  its  address  explicitly.   Such  an address
  1499.           becomes an external reference, as if you had  only  declared
  1500.           the function, and had not defined it.
  1501.  
  1502.                This combination of inline and extern  has  almost  the
  1503.           effect  of  a macro.  The way to use it is to put a function
  1504.           definition in a header file with  these  keywords,  and  put
  1505.           another  copy  of the definition (lacking inline and extern)
  1506.           in a library file.  The definition in the header  file  will
  1507.           cause most calls to the function to be inlined.  If any uses
  1508.           of the function remain, they will refer to the  single  copy
  1509.           in the library.
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526.           1.25.  Assembler Instructions with C Expression Operands
  1527.  
  1528.                In an assembler instruction  using  asm,  you  can  now
  1529.           specify the operands of the instruction using C expressions.
  1530.           This means no more guessing which registers or memory  loca-
  1531.           tions will contain the data you want to use.
  1532.  
  1533.                You must specify an assembler instruction template much
  1534.           like  what appears in a machine description, plus an operand
  1535.           constraint string for each operand.
  1536.  
  1537.                For example, here is  how  to  use  the  68881's  fsinx
  1538.           instruction:
  1539.  
  1540.  
  1541.               asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
  1542.  
  1543.  
  1544.  
  1545.            INTERNALS Here angle is the  C  expression  for  the  input
  1546.           operand  while  result  is that of the output operand.  Each
  1547.           has `"f"' as its operand constraint, saying that a  floating
  1548.           point  register is required.  The `=' in `=f' indicates that
  1549.           the operand is an output; all output  operands'  constraints
  1550.           must use `='.  The constraints use the same language used in
  1551.           the machine description (see section  Constraints).
  1552.            INTERNALS Here angle is the  C  expression  for  the  input
  1553.           operand  while  result  is that of the output operand.  Each
  1554.           has `"f"' as its operand constraint, saying that a  floating
  1555.           point  register is required.  The `=' in `=f' indicates that
  1556.           the operand is an output; all output  operands'  constraints
  1557.           must use `='.  The constraints use the same language used in
  1558.           the machine description (see  section   Constraints,,Operand
  1559.           Constraints, gcc.info, Using and Porting GCC).
  1560.  
  1561.                Each operand  is  described  by  an  operand-constraint
  1562.           string followed by the C expression in parentheses.  A colon
  1563.           separates the  assembler  template  from  the  first  output
  1564.           operand,  and another separates the last output operand from
  1565.           the first input, if any.  Commas  separate  output  operands
  1566.           and  separate  inputs.  The total number of operands is lim-
  1567.           ited to ten or to the maximum  number  of  operands  in  any
  1568.           instruction pattern in the machine description, whichever is
  1569.           greater.
  1570.  
  1571.                If there are no output operands, and  there  are  input
  1572.           operands,  then  there  must  be two consecutive colons sur-
  1573.           rounding the place where the output operands would go.
  1574.  
  1575.                Output operand expressions must be  lvalues;  the  com-
  1576.           piler  can  check  this.   The  input  operands  need not be
  1577.           lvalues.  The compiler cannot  check  whether  the  operands
  1578.           have  data  types  that  are  reasonable for the instruction
  1579.  
  1580.  
  1581.  
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587.  
  1588.  
  1589.  
  1590.  
  1591.  
  1592.           being executed.  It does not parse the assembler instruction
  1593.           template  and  does not know what it means, or whether it is
  1594.           valid assembler input.  The extended  asm  feature  is  most
  1595.           often used for machine instructions that the compiler itself
  1596.           does not know exist.
  1597.  
  1598.                The output operands must be  write-only;  GNU  CC  will
  1599.           assume that the values in these operands before the instruc-
  1600.           tion are dead and need not be generated.  Extended asm  does
  1601.           not  support  input-output or read-write operands.  For this
  1602.           reason, the constraint character `+', which  indicates  such
  1603.           an operand, may not be used.
  1604.  
  1605.                When  the  assembler  instruction  has   a   read-write
  1606.           operand, or an operand in which only some of the bits are to
  1607.           be changed, you must logically split its function  into  two
  1608.           separate operands, one input operand and one write-only out-
  1609.           put operand.  The connection between them  is  expressed  by
  1610.           constraints  which  say they need to be in the same location
  1611.           when the instruction executes.   You  can  use  the  same  C
  1612.           expression for both operands, or different expressions.  For
  1613.           example, here we write the (fictitious)  `combine'  instruc-
  1614.           tion with bar as its read-only source operand and foo as its
  1615.           read-write destination:
  1616.  
  1617.  
  1618.               asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar));
  1619.  
  1620.  
  1621.  
  1622.           The constraint `"0"' for operand 1 says that it must  occupy
  1623.           the  same  location  as operand 0.  A digit in constraint is
  1624.           allowed only in an input operand, and it must  refer  to  an
  1625.           output operand.
  1626.  
  1627.                Only a digit in the constraint can guarantee  that  one
  1628.           operand will be in the same place as another.  The mere fact
  1629.           that foo is the value of both  operands  is  not  enough  to
  1630.           guarantee  that  they  will be in the same place in the gen-
  1631.           erated assembler code.  The following would not work:
  1632.  
  1633.  
  1634.               asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar));
  1635.  
  1636.  
  1637.  
  1638.                Various optimizations or reloading could cause operands
  1639.           0 and 1 to be in different registers; GNU CC knows no reason
  1640.           not to do so.  For example, the compiler might find  a  copy
  1641.           of  the  value of foo in one register and use it for operand
  1642.           1, but generate the output operand 0 in a different register
  1643.           (copying  it  afterward  to  foo's own address).  Of course,
  1644.           since the register for operand 1 is not  even  mentioned  in
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.           the  assembler  code,  the  result will not work, but GNU CC
  1659.           can't tell that.
  1660.  
  1661.                Some instructions clobber specific hard registers.   To
  1662.           describe this, write a third colon after the input operands,
  1663.           followed by the names of the clobbered hard registers (given
  1664.           as strings).  Here is a realistic example for the Vax:
  1665.  
  1666.  
  1667.               asm volatile ("movc3 %0,%1,%2"
  1668.                             : /* no outputs */
  1669.                             : "g" (from), "g" (to), "g" (count)
  1670.                             : "r0", "r1", "r2", "r3", "r4", "r5");
  1671.  
  1672.  
  1673.  
  1674.                If you refer to a particular hardware register from the
  1675.           assembler  code,  then  you  will  probably have to list the
  1676.           register after the third colon to tell the compiler that the
  1677.           register's  value  is  modified.   In  many  assemblers, the
  1678.           register names begin with `%'; to produce  one  `%'  in  the
  1679.           assembler code, you must write `%%' in the input.
  1680.  
  1681.                You can put multiple assembler instructions together in
  1682.           a single asm template, separated either with newlines (writ-
  1683.           ten as `\n') or with semicolons if the assembler allows such
  1684.           semicolons.   The  GNU  assembler  allows semicolons and all
  1685.           Unix assemblers seem to  do  so.   The  input  operands  are
  1686.           guaranteed  not  to  use any of the clobbered registers, and
  1687.           neither will the output operands' addresses, so you can read
  1688.           and write the clobbered registers as many times as you like.
  1689.           Here is an example of multiple instructions in  a  template;
  1690.           it  assumes  that  the  subroutine _foo accepts arguments in
  1691.           registers 9 and 10:
  1692.  
  1693.  
  1694.               asm ("movl %0,r9;movl %1,r10;call _foo"
  1695.                    : /* no outputs */
  1696.                    : "g" (from), "g" (to)
  1697.                    : "r9", "r10");
  1698.  
  1699.  
  1700.  
  1701.                 INTERNALS Unless an output operand has  the  `&'  con-
  1702.           straint  modifier, GNU CC may allocate it in the same regis-
  1703.           ter as an unrelated input operand, on  the  assumption  that
  1704.           the  inputs  are  consumed  before the outputs are produced.
  1705.           This assumption may be false if the assembler code  actually
  1706.           consists  of more than one instruction.  In such a case, use
  1707.           `&' for each output operand that may not overlap  an  input.
  1708.           See section Modifiers.
  1709.            INTERNALS Unless an output operand has the  `&'  constraint
  1710.           modifier,  GNU CC may allocate it in the same register as an
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.           unrelated input operand, on the assumption that  the  inputs
  1725.           are  consumed before the outputs are produced.  This assump-
  1726.           tion may be false if the assembler code actually consists of
  1727.           more than one instruction.  In such a case, use `&' for each
  1728.           output operand that may not overlap an input.   See  section
  1729.           Modifiers,,Constraint Modifier Characters,gcc.info,Using and
  1730.           Porting GCC.
  1731.  
  1732.                If you want to test the condition code produced  by  an
  1733.           assembler instruction, you must include a branch and a label
  1734.           in the asm construct, as follows:
  1735.  
  1736.  
  1737.               asm ("clr %0;frob %1;beq 0f;mov #1,%0;0:"
  1738.                    : "g" (result)
  1739.                    : "g" (input));
  1740.  
  1741.  
  1742.  
  1743.           This assumes your assembler supports local  labels,  as  the
  1744.           GNU assembler and most Unix assemblers do.
  1745.  
  1746.                Usually the  most  convenient  way  to  use  these  asm
  1747.           instructions is to encapsulate them in macros that look like
  1748.           functions.  For example,
  1749.  
  1750.  
  1751.               #define sin(x)       \
  1752.               ({ double __value, __arg = (x);   \
  1753.                  asm ("fsinx %1,%0": "=f" (__value): "f" (__arg));  \
  1754.                  __value; })
  1755.  
  1756.  
  1757.  
  1758.           Here the variable __arg  is  used  to  make  sure  that  the
  1759.           instruction operates on a proper double value, and to accept
  1760.           only those arguments x which can convert automatically to  a
  1761.           double.
  1762.  
  1763.                Another way to make sure the  instruction  operates  on
  1764.           the  correct data type is to use a cast in the asm.  This is
  1765.           different from using a variable __arg in  that  it  converts
  1766.           more different types.  For example, if the desired type were
  1767.           int, casting the argument to int would accept a pointer with
  1768.           no  complaint,  while assigning the argument to an int vari-
  1769.           able named __arg would warn about using a pointer unless the
  1770.           caller explicitly casts it.
  1771.  
  1772.                If an asm has  output  operands,  GNU  CC  assumes  for
  1773.           optimization  purposes  that  the  instruction  has  no side
  1774.           effects except to change the output operands.  This does not
  1775.           mean  that  instructions  with a side effect cannot be used,
  1776.           but you must be careful, because the compiler may  eliminate
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.           them if the output operands aren't used, or move them out of
  1791.           loops, or replace two with one if they constitute  a  common
  1792.           subexpression.   Also,  if your instruction does have a side
  1793.           effect on a variable that otherwise appears not  to  change,
  1794.           the old value of the variable may be reused later if it hap-
  1795.           pens to be found in a register.
  1796.  
  1797.                You can prevent an asm instruction from being  deleted,
  1798.           moved  significantly,  or  combined,  by writing the keyword
  1799.           volatile after the asm.  For example:
  1800.  
  1801.  
  1802.               #define set_priority(x)  \
  1803.               asm volatile ("set_priority %0": /* no outputs */ : "g" (x))
  1804.  
  1805.  
  1806.  
  1807.           An instruction without output operands will not  be  deleted
  1808.           or  moved  significantly,  regardless, unless it is unreach-
  1809.           able.
  1810.  
  1811.                Note that even a volatile asm instruction can be  moved
  1812.           in  ways  that appear insignificant to the compiler, such as
  1813.           across jump instructions.  You can't expect  a  sequence  of
  1814.           volatile  asm  instructions to remain perfectly consecutive.
  1815.           If you want consecutive output, use a single asm.
  1816.  
  1817.                It is a natural idea to look for a way to  give  access
  1818.           to  the  condition  code  left by the assembler instruction.
  1819.           However, when we attempted to implement this,  we  found  no
  1820.           way  to  make  it work reliably.  The problem is that output
  1821.           operands might need reloading, which would result  in  addi-
  1822.           tional  following ``store'' instructions.  On most machines,
  1823.           these instructions would alter  the  condition  code  before
  1824.           there  was  time to test it.  This problem doesn't arise for
  1825.           ordinary ``test'' and ``compare'' instructions because  they
  1826.           don't have any output operands.
  1827.  
  1828.                If you are writing a header file that should be includ-
  1829.           able  in ANSI C programs, write __asm__ instead of asm.  See
  1830.           section Alternate Keywords.
  1831.  
  1832.           1.26.  Controlling Names Used in Assembler Code
  1833.  
  1834.                You can specify the name to be used  in  the  assembler
  1835.           code  for  a  C  function or variable by writing the asm (or
  1836.           __asm__) keyword after the declarator as follows:
  1837.  
  1838.  
  1839.               int foo asm ("myfoo") = 2;
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.  
  1852.  
  1853.  
  1854.  
  1855.  
  1856.           This specifies that the name to be used for the variable foo
  1857.           in  the  assembler  code  should  be `myfoo' rather than the
  1858.           usual `_foo'.
  1859.  
  1860.                On systems where an underscore is normally prepended to
  1861.           the  name  of  a C function or variable, this feature allows
  1862.           you to define names for the linker that do not start with an
  1863.           underscore.
  1864.  
  1865.                You cannot use asm in this way in  a  function  defini-
  1866.           tion;  but you can get the same effect by writing a declara-
  1867.           tion for the function before its definition and putting  asm
  1868.           there, like this:
  1869.  
  1870.  
  1871.               extern func () asm ("FUNC");
  1872.  
  1873.               func (x, y)
  1874.                    int x, y;
  1875.               ...
  1876.  
  1877.  
  1878.  
  1879.                It is up to you to make sure that the  assembler  names
  1880.           you choose do not conflict with any other assembler symbols.
  1881.           Also, you must not use a register name; that  would  produce
  1882.           completely  invalid  assembler code.  GNU CC does not as yet
  1883.           have the ability to store  static  variables  in  registers.
  1884.           Perhaps that will be added.
  1885.  
  1886.           1.27.  Variables in Specified Registers
  1887.  
  1888.                GNU C allows you to put a  few  global  variables  into
  1889.           specified  hardware  registers.   You  can  also specify the
  1890.           register in which an ordinary register  variable  should  be
  1891.           allocated.
  1892.  
  1893.                o+    Global  register   variables   reserve   registers
  1894.                     throughout  the  program.   This  may be useful in
  1895.                     programs such as programming language interpreters
  1896.                     which  have  a couple of global variables that are
  1897.                     accessed very often.
  1898.  
  1899.                o+    Local register variables in specific registers  do
  1900.                     not  reserve  the  registers.  The compiler's data
  1901.                     flow analysis is capable of determining where  the
  1902.                     specified registers contain live values, and where
  1903.                     they are available for other uses.
  1904.  
  1905.                     These local variables are sometimes convenient for
  1906.                     use  with  the  extended  asm feature (see section
  1907.                     Extended Asm), if you want to write one output  of
  1908.                     the assembler instruction directly into a particu-
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.  
  1916.  
  1917.  
  1918.  
  1919.  
  1920.  
  1921.  
  1922.                     lar register.  (This will work provided the regis-
  1923.                     ter you specify fits the constraints specified for
  1924.                     that operand in the asm.)
  1925.  
  1926.  
  1927.           1.27.1.  Defining Global Register Variables
  1928.  
  1929.                You can define a global register variable in GNU C like
  1930.           this:
  1931.  
  1932.  
  1933.               register int *foo asm ("a5");
  1934.  
  1935.  
  1936.  
  1937.           Here a5 is the name of the register which  should  be  used.
  1938.           Choose  a  register  which is normally saved and restored by
  1939.           function calls on your machine,  so  that  library  routines
  1940.           will not clobber it.
  1941.  
  1942.                Naturally the register name is  cpu-dependent,  so  you
  1943.           would  need  to conditionalize your program according to cpu
  1944.           type.  The register a5 would be a good choice on a 68000 for
  1945.           a  variable of pointer type.  On machines with register win-
  1946.           dows, be sure to choose a ``global'' register  that  is  not
  1947.           affected magically by the function call mechanism.
  1948.  
  1949.                In addition, operating systems on one type of  cpu  may
  1950.           differ  in  how they name the registers; then you would need
  1951.           additional conditionals.  For example, some 68000  operating
  1952.           systems call this register %a5.
  1953.  
  1954.                Eventually there may be a way of asking the compiler to
  1955.           choose a register automatically, but first we need to figure
  1956.           out how it should choose and how to enable you to guide  the
  1957.           choice.  No solution is evident.
  1958.  
  1959.                Defining a global register variable in a certain regis-
  1960.           ter  reserves  that register entirely for this use, at least
  1961.           within the current compilation.  The register  will  not  be
  1962.           allocated  for  any  other  purpose  in the functions in the
  1963.           current compilation.  The register will  not  be  saved  and
  1964.           restored  by these functions.  Stores into this register are
  1965.           never deleted even if they would  appear  to  be  dead,  but
  1966.           references may be deleted or moved or simplified.
  1967.  
  1968.                It is not safe to access the global register  variables
  1969.           from  signal  handlers, or from more than one thread of con-
  1970.           trol, because the system library  routines  may  temporarily
  1971.           use the register for other things (unless you recompile them
  1972.           specially for the task at hand).
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.  
  1988.                It is not safe for one  function  that  uses  a  global
  1989.           register  variable  to call another such function foo by way
  1990.           of a third function lose that was compiled without knowledge
  1991.           of  this  variable (i.e. in a different source file in which
  1992.           the variable wasn't declared).  This is because  lose  might
  1993.           save the register and put some other value there.  For exam-
  1994.           ple, you can't expect  a  global  register  variable  to  be
  1995.           available in the comparison-function that you pass to qsort,
  1996.           since qsort might have put something else in that  register.
  1997.           (If you are prepared to recompile qsort with the same global
  1998.           register variable, you can solve this problem.)
  1999.  
  2000.                If you want to recompile qsort or  other  source  files
  2001.           which  do not actually use your global register variable, so
  2002.           that they will not use that register for any other  purpose,
  2003.           then  it  suffices  to specify the compiler option `-ffixed-
  2004.           reg'.  You need not actually add a global register  declara-
  2005.           tion to their source code.
  2006.  
  2007.                A function which can alter the value of a global regis-
  2008.           ter  variable  cannot  safely be called from a function com-
  2009.           piled without this variable, because it  could  clobber  the
  2010.           value  the  caller  expects to find there on return.  There-
  2011.           fore, the function which is the entry point into the part of
  2012.           the  program  that  uses  the  global register variable must
  2013.           explicitly save and restore the value which belongs  to  its
  2014.           caller.
  2015.  
  2016.                On most machines, longjmp will restore to  each  global
  2017.           register  variable  the  value  it  had  at  the time of the
  2018.           setjmp.  On some machines, however, longjmp will not  change
  2019.           the value of global register variables.  To be portable, the
  2020.           function that called setjmp should make  other  arrangements
  2021.           to  save the values of the global register variables, and to
  2022.           restore them in a longjmp.  This way, the  same  thing  will
  2023.           happen regardless of what longjmp does.
  2024.  
  2025.                All global register variable declarations must  precede
  2026.           all  function  definitions.   If  such  a  declaration could
  2027.           appear after function definitions, the declaration would  be
  2028.           too  late  to prevent the register from being used for other
  2029.           purposes in the preceding functions.
  2030.  
  2031.                Global register variables may not have initial  values,
  2032.           because  an  executable  file has no means to supply initial
  2033.           contents for a register.
  2034.  
  2035.                On the Sparc, there are reports  that  g3  ...  g7  are
  2036.           suitable  registers,  but certain library functions, such as
  2037.           getwd,  as  well  as  the  subroutines  for   division   and
  2038.           remainder,  modify  g3  and  g4.   g1  and g2 are local tem-
  2039.           poraries.
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.  
  2054.                On the 68000, a2 ... a5 should be suitable,  as  should
  2055.           d2 ... d7.  Of course, it will not do to use more than a few
  2056.           of those.
  2057.  
  2058.           1.27.2.  Specifying Registers for Local Variables
  2059.  
  2060.                You can define a local register variable with a  speci-
  2061.           fied register like this:
  2062.  
  2063.  
  2064.               register int *foo asm ("a5");
  2065.  
  2066.  
  2067.  
  2068.           Here a5 is the name of the register which  should  be  used.
  2069.           Note  that  this is the same syntax used for defining global
  2070.           register variables, but for a local variable it would appear
  2071.           within a function.
  2072.  
  2073.                Naturally the register name is cpu-dependent, but  this
  2074.           is  not  a  problem, since specific registers are most often
  2075.           useful with explicit  assembler  instructions  (see  section
  2076.           Extended  Asm).  Both of these things generally require that
  2077.           you conditionalize your program according to cpu type.
  2078.  
  2079.                In addition, operating systems on one type of  cpu  may
  2080.           differ  in  how they name the registers; then you would need
  2081.           additional conditionals.  For example, some 68000  operating
  2082.           systems call this register %a5.
  2083.  
  2084.                Eventually there may be a way of asking the compiler to
  2085.           choose a register automatically, but first we need to figure
  2086.           out how it should choose and how to enable you to guide  the
  2087.           choice.  No solution is evident.
  2088.  
  2089.                Defining such a register variable does not reserve  the
  2090.           register;  it  remains  available  for  other uses in places
  2091.           where flow control determines the variable's  value  is  not
  2092.           live.  However, these registers are made unavailable for use
  2093.           in the reload pass.  I would not be surprised  if  excessive
  2094.           use  of  this  feature leaves the compiler too few available
  2095.           registers to compile certain functions.
  2096.  
  2097.           1.28.  Alternate Keywords
  2098.  
  2099.                The option `-traditional'  disables  certain  keywords;
  2100.           `-ansi'  disables  certain others.  This causes trouble when
  2101.           you want to use GNU C extensions, or ANSI C features,  in  a
  2102.           general-purpose  header  file  that  should be usable by all
  2103.           programs, including ANSI C programs  and  traditional  ones.
  2104.           The  keywords  asm,  typeof  and inline cannot be used since
  2105.           they won't work in a program compiled  with  `-ansi',  while
  2106.           the  keywords  const,  volatile,  signed,  typeof and inline
  2107.  
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118.  
  2119.  
  2120.           won't work in a program compiled with `-traditional'.
  2121.  
  2122.                The way to solve these problems is to put `__'  at  the
  2123.           beginning  and end of each problematical keyword.  For exam-
  2124.           ple, use __asm__ instead of asm, __const__ instead of const,
  2125.           and __inline__ instead of inline.
  2126.  
  2127.                Other C compilers won't accept these  alternative  key-
  2128.           words; if you want to compile with another compiler, you can
  2129.           define the alternate keywords as macros to replace them with
  2130.           the customary keywords.  It looks like this:
  2131.  
  2132.  
  2133.               #ifndef __GNUC__
  2134.               #define __asm__ asm
  2135.               #endif
  2136.  
  2137.  
  2138.  
  2139.                `-pedantic' causes warnings for many GNU C  extensions.
  2140.           You can prevent such warnings within one expression by writ-
  2141.           ing __extension__ before the expression.  __extension__  has
  2142.           no effect aside from this.
  2143.  
  2144.           1.29.  Incomplete enum Types
  2145.  
  2146.                You can define an enum tag without specifying its  pos-
  2147.           sible values.  This results in an incomplete type, much like
  2148.           what you get if you write struct foo without describing  the
  2149.           elements.  A later declaration which does specify the possi-
  2150.           ble values completes the type.
  2151.  
  2152.                You can't allocate variables or storage using the  type
  2153.           while it is incomplete.  However, you can work with pointers
  2154.           to that type.
  2155.  
  2156.                This extension may not be very useful, but it makes the
  2157.           handling  of  enum  more  consistent with the way struct and
  2158.           union are handled.
  2159.  
  2160.  
  2161.  
  2162.  
  2163.  
  2164.  
  2165.  
  2166.  
  2167.  
  2168.  
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.