comparison docs/ccguide/creference.appendix @ 1065:63fc27187545

Appendix A from "The C Programming Language, 1978" found on the Internet
author roug
date Sun, 30 Mar 2003 08:27:32 +0000
parents
children c8fcb9426d8b
comparison
equal deleted inserted replaced
1064:8a74e490c334 1065:63fc27187545
1 <appendix>
2 <title>C Reference Manual</title>
3 <sect1><title>Introduction</title>
4 <para>
5 This manual describes the C language on the DEC PDP-11<footnote><para>
6 DEC PDP-11, and DEC VAX-11 are trademarks of Digital Equipment Corporation.
7 </para></footnote>, the DEC VAX-11,
8 and the 6809<footnote><para>
9 6809 is a trademark of Motorola.
10 </para></footnote>.
11 Where differences exist, it concentrates on the VAX, but tries to point
12 out implementation-dependent details. With few execptions, these dependencies
13 follow directly from the underlying properties of the hardware; the various
14 compilers are generally quite compatible.
15 </para></sect1>
16 <sect1><title>Lexical Conventions</title>
17 <para>
18 There are six classes of tokens -
19 identifiers, keywords, constants, strings, operators, and other separators.
20 Blanks, tabs, newlines,
21 and comments (collectively, <quote>white space</quote>) as described below
22 are ignored except as they serve to separate
23 tokens.
24 Some white space is required to separate
25 otherwise adjacent identifiers,
26 keywords, and constants.
27 </para><para>
28 If the input stream has been parsed into tokens
29 up to a given character, the next token is taken
30 to include the longest string of characters
31 which could possibly constitute a token.
32 </para>
33 <sect2><title>Comments</title>
34 <para>
35 The characters
36 <literal>
37 /*
38 </literal>
39 introduce a comment which terminates
40 with the characters
41 <literal>*/</literal>.
42 Comments do not nest.
43 </para></sect2>
44 <sect2><title>Identifiers (Names)</title>
45 <para>
46 An identifier is a sequence of letters and digits.
47 The first character must be a letter.
48 The underscore
49 (<literal>_</literal>)
50 counts as a letter.
51 Uppercase and lowercase letters
52 are different.
53 Although there is no limit on the length of a name,
54 only initial characters are significant: at least
55 eight characters of a non-external name, and perhaps
56 fewer for external names.
57 Moreover, some implementations may collapse case
58 distinctions for external names.
59 The external name sizes include:
60 <informaltable frame="none">
61 <tgroup cols="2">
62 <tbody>
63 <row>
64 <entry>PDP-11</entry>
65 <entry>7 characters, 2 cases</entry>
66 </row>
67 <row>
68 <entry>VAX-11</entry>
69 <entry>>100 characters, 2 cases</entry>
70 </row>
71 <row>
72 <entry>Motorola 6809</entry>
73 <entry>7 characters, 2 cases</entry>
74 </row>
75 </tbody>
76 </tgroup>
77 </informaltable>
78 </para></sect2>
79 <sect2><title>Keywords</title>
80 <para>
81 The following identifiers are reserved for use
82 as keywords and may not be used otherwise:
83 <informaltable frame="none">
84 <tgroup cols="5">
85 <tbody>
86 <row>
87 <entry>auto</entry>
88 <entry>do</entry>
89 <entry>for</entry>
90 <entry>return</entry>
91 <entry>typedef</entry>
92 </row>
93 <row>
94 <entry>break</entry>
95 <entry>double</entry>
96 <entry>goto</entry>
97 <entry>short</entry>
98 <entry>union</entry>
99 </row>
100 <row>
101 <entry>case</entry>
102 <entry>else</entry>
103 <entry>if</entry>
104 <entry>sizeof</entry>
105 <entry>unsigned</entry>
106 </row>
107 <row>
108 <entry>char</entry>
109 <entry>enum</entry>
110 <entry>int</entry>
111 <entry>static</entry>
112 <entry>direct</entry>
113 </row>
114 <row>
115 <entry>continue</entry>
116 <entry>external</entry>
117 <entry>long</entry>
118 <entry>struct</entry>
119 <entry>while</entry>
120 </row>
121 <row>
122 <entry>default</entry>
123 <entry>float</entry>
124 <entry>register</entry>
125 <entry>switch</entry>
126 <entry></entry>
127 </row>
128 </tbody>
129 </tgroup>
130 </informaltable>
131 </para><para>
132 Some implementations also reserve the words
133 <literal>fortran</literal>
134 and
135 <literal>asm</literal>
136 </para></sect2>
137 <sect2><title>Constants</title>
138 <para>
139 There are several kinds
140 of constants.
141 Each has a type; an introduction to types is given in <quote>NAMES.</quote>
142 Hardware characteristics that affect sizes are summarized in
143 <quote>Hardware Characteristics</quote> under <quote>LEXICAL CONVENTIONS.</quote>
144 </para>
145 <sect3><title>Integer Constants</title>
146 <para>
147 An integer constant consisting of a sequence of digits
148 is taken
149 to be octal if it begins with
150 <literal>
151 0
152 </literal>
153 (digit zero).
154 An octal constant consists of the digits <literal>0</literal> through <literal>7</literal> only.
155 A sequence of digits preceded by
156 <literal>0x</literal>
157 or
158 <literal>0X</literal>
159 (digit zero) is taken to be a hexadecimal integer.
160 The hexadecimal digits include
161 <literal>
162 a
163 </literal>
164 or
165 <literal>A</literal>
166 through
167 <literal>f</literal>
168 or
169 <literal>F</literal>
170 with values 10 through 15.
171 Otherwise, the integer constant is taken to be decimal.
172 A decimal constant whose value exceeds the largest
173 signed machine integer is taken to be
174 <literal>long</literal>;
175 an octal or hex constant which exceeds the largest unsigned machine integer
176 is likewise taken to be
177 <literal>long</literal>.
178 </para></sect3>
179 <sect3><title>Explicit Long Constants</title>
180 <para>
181 A decimal, octal, or hexadecimal integer constant immediately followed
182 by
183 <literal>
184 l
185 </literal>
186 (letter ell)
187 or
188 <literal>
189 L
190 </literal>
191 is a long constant.
192 As discussed below,
193 on some machines
194 integer and long values may be considered identical.
195 </para></sect3>
196 <sect3><title>Character Constants</title>
197 <para>
198 A character constant is a character enclosed in single quotes,
199 as in '<literal>x</literal>'.
200 The value of a character constant is the numerical value of the
201 character in the machine's character set.
202 </para><para>
203 Certain nongraphic characters,
204 the single quote
205 (<literal>'</literal>)
206 and the backslash
207 (<literal>\</literal>),
208 may be represented according to the following table
209 of escape sequences:
210 <informaltable frame="none">
211 <tgroup cols="3">
212 <colspec colwidth="2in"/>
213 <colspec colwidth="1in"/>
214 <colspec colwidth="1in"/>
215 <tbody>
216 <row>
217 <entry>newline</entry>
218 <entry>NL (LF)</entry>
219 <entry>\n</entry>
220 </row>
221 <row>
222 <entry>horizontal tab</entry>
223 <entry>HT</entry>
224 <entry>\t</entry>
225 </row>
226 <row>
227 <entry>vertical tab</entry>
228 <entry>VT</entry>
229 <entry>\v</entry>
230 </row>
231 <row>
232 <entry>backspace</entry>
233 <entry>BS</entry>
234 <entry>\b</entry>
235 </row>
236 <row>
237 <entry>carriage return</entry>
238 <entry>CR</entry>
239 <entry>\r</entry>
240 </row>
241 <row>
242 <entry>form feed</entry>
243 <entry>FF</entry>
244 <entry>\f</entry>
245 </row>
246 <row>
247 <entry>backslash</entry>
248 <entry>\</entry>
249 <entry>\\</entry>
250 </row>
251 <row>
252 <entry>single quote</entry>
253 <entry>'</entry>
254 <entry>\'</entry>
255 </row>
256 <row>
257 <entry>bit pattern</entry>
258 <entry><emphasis>ddd</emphasis></entry>
259 <entry>\<emphasis>ddd</emphasis></entry>
260 </row>
261 </tbody>
262 </tgroup>
263 </informaltable>
264 </para><para>
265 The escape
266 \<emphasis>ddd</emphasis>
267 consists of the backslash followed by 1, 2, or 3 octal digits
268 which are taken to specify the value of the
269 desired character.
270 A special case of this construction is
271 <literal>
272 \0
273 </literal>
274 (not followed
275 by a digit), which indicates the character
276 <literal>
277 NUL</literal>.
278 If the character following a backslash is not one
279 of those specified, the
280 behavior is undefined.
281 A new-line character is illegal in a character constant.
282 The type of a character constant is <literal>int</literal>.
283 </para></sect3>
284 <sect3><title>Floating Constants</title>
285 <para>
286 A floating constant consists of
287 an integer part, a decimal point, a fraction part,
288 an
289 <literal>
290 e
291 </literal>
292 or
293 <literal>E</literal>,
294 and an optionally signed integer exponent.
295 The integer and fraction parts both consist of a sequence
296 of digits.
297 Either the integer part or the fraction
298 part (not both) may be missing.
299 Either the decimal point or
300 the
301 <literal>
302 e
303 </literal>
304 and the exponent (not both) may be missing.
305 Every floating constant has type <literal>double</literal>.
306 </para></sect3>
307 <sect3><title>Enumeration Constants</title>
308 <para>
309 Names declared as enumerators
310 (see <quote>Structure, Union, and Enumeration Declarations</quote> under
311 <quote>DECLARATIONS</quote>)
312 have type <literal>int</literal>.
313 </para></sect3></sect2>
314 <sect2><title>Strings</title>
315 <para>
316 A string is a sequence of characters surrounded by
317 double quotes,
318 as in
319 <literal>&quot;...&quot;</literal>.
320 A string has type
321 <quote>array of <literal>char</literal></quote> and storage class
322 <literal>static</literal>
323 (see <quote>NAMES</quote>)
324 and is initialized with
325 the given characters.
326 The compiler places
327 a null byte
328 (<literal>\0</literal>)
329 at the end of each string so that programs
330 which scan the string can
331 find its end.
332 In a string, the double quote character
333 (<literal>&quot;</literal>)
334 must be preceded by
335 a
336 <literal>\</literal>;
337 in addition, the same escapes as described for character
338 constants may be used.
339 </para><para>
340 A
341 <literal>
342 \
343 </literal>
344 and
345 the immediately following newline are ignored.
346 All strings, even when written identically, are distinct.
347 </para></sect2>
348 <sect2><title>Hardware Characteristics</title>
349 <para>
350 The following figure summarize
351 certain hardware properties that vary from machine to machine.
352 <table frame="none">
353 <title>DEC PDP-11 HARDWARE CHARACTERISTICS</title>
354 <tgroup cols="4">
355 <thead>
356 <row>
357 <entry></entry>
358 <entry>DEC PDP\-11</entry>
359 <entry>DEC VAX-11</entry>
360 <entry>6809</entry>
361 </row>
362 <row>
363 <entry></entry>
364 <entry>(ASCII)</entry>
365 <entry>(ASCII)</entry>
366 <entry>(ASCII)</entry>
367 </row>
368 </thead>
369 <tbody>
370 <row>
371 <entry>char</entry>
372 <entry>8 bits</entry>
373 <entry>8 bits</entry>
374 <entry>8 bits</entry>
375 </row>
376 <row>
377 <entry>int</entry>
378 <entry>16</entry>
379 <entry>32</entry>
380 <entry>16</entry>
381 </row>
382 <row>
383 <entry>short</entry>
384 <entry>16</entry>
385 <entry>16</entry>
386 <entry>16</entry>
387 </row>
388 <row>
389 <entry>long</entry>
390 <entry>32</entry>
391 <entry>32</entry>
392 <entry>32</entry>
393 </row>
394 <row>
395 <entry>float</entry>
396 <entry>32</entry>
397 <entry>32</entry>
398 <entry>32</entry>
399 </row>
400 <row>
401 <entry>double</entry>
402 <entry>64</entry>
403 <entry>64</entry>
404 <entry>64</entry>
405 </row>
406 <row>
407 <entry>float range</entry>
408 <entry>&plusmn;10<superscript>&plusmn;38</superscript></entry>
409 <entry>&plusmn;10<superscript>&plusmn;38</superscript></entry>
410 <entry>&plusmn;10<superscript>&plusmn;38</superscript></entry>
411 </row>
412 <row>
413 <entry>double range</entry>
414 <entry>&plusmn;10<superscript>&plusmn;38</superscript></entry>
415 <entry>&plusmn;10<superscript>&plusmn;38</superscript></entry>
416 <entry>&plusmn;10<superscript>&plusmn;38</superscript></entry>
417 </row>
418 </tbody>
419 </tgroup>
420 </table>
421 </para><para>
422 </para></sect2></sect1>
423 <sect1><title>
424 Syntax Notation
425 </title><para>
426 Syntactic categories are indicated by
427 <emphasis>
428 italic
429 </emphasis>
430 type
431 and literal words and characters
432 in
433 <literal>bold</literal>
434 type.
435 Alternative categories are listed on separate lines.
436 An optional terminal or nonterminal symbol is
437 indicated by the subscript <quote>opt,</quote> so that
438 <literallayout>
439 { <emphasis>expression<subscript>opt</subscript></emphasis> }
440 </literallayout>
441
442 indicates an optional expression enclosed in braces.
443 The syntax is summarized in <quote>SYNTAX SUMMARY</quote>.
444 </para></sect1>
445 <sect1><title>
446 What's in a name?
447 </title><para>
448 C bases the interpretation of an
449 identifier upon two attributes of the identifier: its
450 <emphasis>storage class</emphasis>
451 and its
452 <emphasis>type</emphasis>.
453 The storage class determines the location and lifetime
454 of the storage associated with an identifier;
455 the type determines
456 the meaning of the values
457 found in the identifier's storage.
458 </para>
459 <para>
460 There are four declarable storage classes:
461 automatic, static, external, and register.
462 Automatic variables are local to each invocation of
463 a block (see <quote>Compound Statement or Block</quote> in
464 <quote>STATEMENTS</quote>) and are discarded upon exit from the block.
465 Static variables are local to a block but retain
466 their values upon reentry to a block even after control
467 has left the block.
468 External variables exist and retain their values throughout
469 the execution of the entire program and
470 may be used for communication between
471 functions, even separately compiled functions.
472 Register variables are (if possible) stored in the fast registers
473 of the machine; like automatic
474 variables, they are local to each block and disappear on exit from the block.
475 </para>
476 <para>
477 C supports several fundamental types of objects:
478 </para>
479 <para>
480 Objects declared as characters
481 (<literal>char</literal>)
482 are large enough to store any member of the implementation's
483 character set,
484 and if a genuine character from that character set is
485 stored in a <literal>char</literal> variable,
486 its value is equivalent to the integer code for that character.
487 Other quantities may be stored into character variables, but
488 the implementation is machine dependent.
489 </para><para>
490 Up to three sizes of integer, declared
491 <literal>short int</literal>,
492 <literal>int</literal>,
493 and
494 <literal>long int</literal>,
495 are available.
496 Longer integers provide no less storage than shorter ones,
497 but the implementation may make either short integers or long integers,
498 or both, equivalent to plain integers.
499 <quote>Plain</quote> integers have the natural size suggested
500 by the host machine architecture.
501 The other sizes are provided to meet special needs.
502 </para><para>
503 Unsigned
504 integers, declared
505 <literal>unsigned</literal>,
506 obey the laws of arithmetic modulo
507 2<superscript><emphasis>n</emphasis></superscript>
508 where <emphasis>n</emphasis> is the number of bits in the representation.
509 (On the
510 PDP-11,
511 unsigned long quantities are not supported.)
512 </para><para>
513 Single-precision floating point
514 (<literal>float</literal>)
515 and double precision floating point
516 (<literal>double</literal>)
517 may be synonymous in some implementations.
518 </para><para>
519 Because objects of the foregoing types can usefully be interpreted
520 as numbers, they will be referred to as
521 <emphasis>
522 arithmetic
523 </emphasis>
524 types.
525 Types
526 <literal>char</literal>,
527 <literal>int</literal>
528 of all sizes whether <literal>unsigned</literal> or not, and
529 <literal>
530 enum
531 </literal>
532 will collectively be called
533 <emphasis>
534 integral
535 </emphasis>
536 types.
537 The
538 <literal>float</literal>
539 and
540 <literal>double</literal>
541 types will collectively be called
542 <emphasis>floating</emphasis>
543 types.
544 </para><para>
545 Besides the fundamental arithmetic types, there is a
546 conceptually infinite class of derived types constructed
547 from the fundamental types in the following ways:
548 <itemizedlist>
549 <listitem><para>
550 <emphasis>Arrays</emphasis>
551 of objects of most types
552 </para></listitem>
553 <listitem><para>
554 <emphasis>Functions</emphasis>
555 which return objects of a given type
556 </para></listitem>
557 <listitem><para>
558 <emphasis>Pointers</emphasis>
559 to objects of a given type
560 </para></listitem>
561 <listitem><para>
562 <emphasis>Structures</emphasis>
563 containing a sequence of objects of various types
564 </para></listitem>
565 <listitem><para>
566 <emphasis>Unions</emphasis>
567 capable of containing any one of several objects of various types.
568 </para></listitem>
569 </itemizedlist>
570 </para><para>
571 In general these methods
572 of constructing objects can
573 be applied recursively.
574 </para></sect1>
575 <sect1><title>Objects and lvalues</title>
576 <para>
577 An
578 <emphasis>
579 object
580 </emphasis>
581 is a manipulatable region of storage.
582 An
583 <emphasis>
584 lvalue
585 </emphasis>
586 is an expression referring to an object.
587 An obvious example of an lvalue
588 expression is an identifier.
589 There are operators which yield lvalues:
590 for example,
591 if
592 <literal>
593 E
594 </literal>
595 is an expression of pointer type, then
596 <literal>
597 *E
598 </literal>
599 is an lvalue
600 expression referring to the object to which
601 <literal>
602 E
603 </literal>
604 points.
605 The name <quote>lvalue</quote> comes from the assignment expression
606 <literal>
607 E1\ =\ E2
608 </literal>
609 in which the left operand
610 <literal>
611 E1
612 </literal>
613 must be
614 an lvalue expression.
615 The discussion of each operator
616 below indicates whether it expects lvalue operands and whether it
617 yields an lvalue.
618 </para></sect1>
619 <sect1><title>
620 Conversions
621 </title><para>
622 A number of operators may, depending on their operands,
623 cause conversion of the value of an operand from one type to another.
624 This part explains the result to be expected from such
625 conversions.
626 The conversions demanded by most ordinary operators are summarized under
627 <quote>Arithmetic Conversions.</quote>
628 The summary will be supplemented
629 as required by the discussion
630 of each operator.
631 </para>
632 <sect2><title>Characters and Integers</title>
633 <para>
634 A character or a short integer may be used wherever an
635 integer may be used.
636 In all cases
637 the value is converted to an integer.
638 Conversion of a shorter integer
639 to a longer preserves sign.
640 Whether or not sign-extension occurs for characters is machine
641 dependent, but it is guaranteed that a member of the
642 standard character set is non-negative.
643 Of the machines treated here,
644 only the
645 PDP-11
646 and
647 VAX-11
648 sign-extend.
649 On these machines,
650 <literal>char</literal>
651 variables range in value from
652 -128 to 127.
653 The more explicit type
654 <literal>unsigned</literal>
655 <literal>char</literal>
656 forces the values to range from 0 to 255.
657 </para><para>
658 On machines that treat characters as signed,
659 the characters of the
660 ASCII
661 set are all non-negative.
662 However, a character constant specified
663 with an octal escape suffers sign extension
664 and may appear negative;
665 for example,
666 <literal>'\377'</literal>
667 has the value
668 <literal>
669 -1</literal>.
670 </para><para>
671 When a longer integer is converted to a shorter
672 integer
673 or to a
674 <literal>char</literal>,
675 it is truncated on the left.
676 Excess bits are simply discarded.
677 </para></sect2>
678 <sect2><title>Float and Double</title>
679 <para>
680 All floating arithmetic in C is carried out in double precision.
681 Whenever a
682 <literal>float</literal>
683 appears in an expression it is lengthened to
684 <literal>double</literal>
685 by zero padding its fraction.
686 When a
687 <literal>double</literal>
688 must be
689 converted to
690 <literal>float</literal>,
691 for example by an assignment,
692 the
693 <literal>double</literal>
694 is rounded before
695 truncation to
696 <literal>float</literal>
697 length.
698 This result is undefined if it cannot be represented as a float.
699 On the VAX, the compiler can be directed to use single percision for expressions
700 containing only float and interger operands.
701 </para></sect2>
702 <sect2><title>Floating and Integral</title>
703 <para>
704 Conversions of floating values to integral type
705 are rather machine dependent.
706 In particular, the direction of truncation of negative numbers
707 varies.
708 The result is undefined if
709 it will not fit in the space provided.
710 </para><para>
711 Conversions of integral values to floating type
712 are well behaved.
713 Some loss of accuracy occurs
714 if the destination lacks sufficient bits.
715 </para></sect2>
716 <sect2><title>Pointers and Integers</title>
717 <para>
718 An expression of integral type may be added to or subtracted from
719 a pointer; in such a case,
720 the first is converted as
721 specified in the discussion of the addition operator.
722 Two pointers to objects of the same type may be subtracted;
723 in this case, the result is converted to an integer
724 as specified in the discussion of the subtraction
725 operator.
726 </para></sect2>
727 <sect2><title>Unsigned</title>
728 <para>
729 Whenever an unsigned integer and a plain integer
730 are combined, the plain integer is converted to unsigned
731 and the result is unsigned.
732 The value
733 is the least unsigned integer congruent to the signed
734 integer (modulo 2<superscript>wordsize</superscript>).
735 In a 2's complement representation,
736 this conversion is conceptual; and there is no actual change in the
737 bit pattern.
738 </para><para>
739 When an unsigned <literal>short</literal> integer is converted to
740 <literal>long</literal>,
741 the value of the result is the same numerically as that of the
742 unsigned integer.
743 Thus the conversion amounts to padding with zeros on the left.
744 </para></sect2>
745 <sect2><title>Arithmetic Conversions</title>
746 <para>
747 A great many operators cause conversions
748 and yield result types in a similar way.
749 This pattern will be called the <quote>usual arithmetic conversions.</quote>
750 <orderedlist numeration="loweralpha">
751 <listitem><para>
752 First, any operands of type
753 <literal>char</literal>
754 or
755 <literal>short</literal>
756 are converted to
757 <literal>int</literal>,
758 and any operands of type <literal>unsigned char</literal>
759 or <literal>unsigned short</literal> are converted
760 to <literal>unsigned int</literal>.
761 </para></listitem>
762 <listitem><para>
763 Then, if either operand is
764 <literal>double</literal>,
765 the other is converted to
766 <literal>double</literal>
767 and that is the type of the result.
768 </para></listitem>
769 <listitem><para>
770 Otherwise, if either operand is <literal>unsigned long</literal>,
771 the other is converted to <literal>unsigned long</literal> and that
772 is the type of the result.
773 </para></listitem>
774 <listitem><para>
775 Otherwise, if either operand is
776 <literal>long</literal>,
777 the other is converted to
778 <literal>long</literal>
779 and that is the type of the result.
780 </para></listitem>
781 <listitem><para>
782 Otherwise, if one operand is <literal>long</literal>, and
783 the other is <literal>unsigned int</literal>, they are both
784 converted to <literal>unsigned long</literal> and that is
785 the type of the result.
786 </para></listitem>
787 <listitem><para>
788 Otherwise, if either operand is
789 <literal>unsigned</literal>,
790 the other is converted to
791 <literal>unsigned</literal>
792 and that is the type of the result.
793 </para></listitem>
794 <listitem><para>
795 Otherwise, both operands must be
796 <literal>int</literal>,
797 and that is the type of the result.
798 </para></listitem>
799 </orderedlist>
800 </para></sect2></sect1>
801 <sect1><title>
802 Expressions
803 </title><para>
804 The precedence of expression operators is the same
805 as the order of the major
806 subsections of this section, highest precedence first.
807 Thus, for example, the expressions referred to as the operands of
808 <literal>
809 +
810 </literal>
811 (see <quote>Additive Operators</quote>)
812 are those expressions defined under <quote>Primary Expressions</quote>,
813 <quote>Unary Operators</quote>, and <quote>Multiplicative Operators</quote>.
814 Within each subpart, the operators have the same
815 precedence.
816 Left- or right-associativity is specified
817 in each subsection for the operators
818 discussed therein.
819 The precedence and associativity of all the expression
820 operators are summarized in the
821 grammar of <quote>SYNTAX SUMMARY</quote>.
822 </para><para>
823 Otherwise, the order of evaluation of expressions
824 is undefined. In particular, the compiler
825 considers itself free to
826 compute subexpressions in the order it believes
827 most efficient
828 even if the subexpressions
829 involve side effects.
830 The order in which subexpression evaluation takes place is unspecified.
831 Expressions involving a commutative and associative
832 operator
833 (<literal>*,</literal>
834 <literal>+</literal>,
835 <literal>&amp;</literal>,
836 <literal>|</literal>,
837 <literal>^</literal>)
838 may be rearranged arbitrarily even in the presence
839 of parentheses;
840 to force a particular order of evaluation,
841 an explicit temporary must be used.
842 </para><para>
843 The handling of overflow and divide check
844 in expression evaluation
845 is undefined.
846 Most existing implementations of C ignore integer overflows;
847 treatment of
848 division by 0 and all floating-point exceptions
849 varies between machines and is usually
850 adjustable by a library function.
851 </para>
852 <sect2><title>Primary Expressions</title>
853 <para>
854 Primary expressions
855 involving <literal>.</literal>,
856 <literal>-></literal>,
857 subscripting, and function calls
858 group left to right.
859 <literallayout>
860 <emphasis>primary-expression:
861 identifier
862 constant
863 string
864 ( expression )
865 primary-expression [ expression ]
866 primary-expression ( expression-list<subscript>opt</subscript> )
867 primary-expression . identifier
868 primary-expression -> identifier</emphasis>
869 </literallayout>
870 <literallayout>
871 <emphasis>expression-list:
872 expression
873 expression-list , expression</emphasis>
874 </literallayout>
875 </para><para>
876 An identifier is a primary expression provided it has been
877 suitably declared as discussed below.
878 Its type is specified by its declaration.
879 If the type of the identifier is <quote>array of ...</quote>,
880 then the value of the identifier expression
881 is a pointer
882 to the first object in the array; and the
883 type of the expression is
884 <quote>pointer to ...</quote>.
885 Moreover, an array identifier is not an lvalue
886 expression.
887 Likewise, an identifier which is declared
888 <quote>function returning ...</quote>,
889 when used except in the function-name position
890 of a call, is converted to <quote>pointer to function returning ...</quote>.
891 </para><para>
892 A
893 constant is a primary expression.
894 Its type may be
895 <literal>int</literal>,
896 <literal>long</literal>,
897 or
898 <literal>double</literal>
899 depending on its form.
900 Character constants have type
901 <literal>int</literal>
902 and floating constants have type
903 <literal>double</literal>.
904 </para><para>
905 A string is a primary expression.
906 Its type is originally <quote>array of
907 <literal>char</literal></quote>,
908 but following
909 the same rule given above for identifiers,
910 this is modified to <quote>pointer to
911 <literal>char</literal></quote> and
912 the
913 result is a pointer to the first character
914 in the string.
915 (There is an exception in certain initializers;
916 see <quote>Initialization</quote> under <quote>DECLARATIONS.</quote>)
917 </para><para>
918 A parenthesized expression is a primary expression
919 whose type and value are identical
920 to those of the unadorned expression.
921 The presence of parentheses does
922 not affect whether the expression is an
923 lvalue.
924 </para><para>
925 A primary expression followed by an expression in square
926 brackets is a primary expression.
927 The intuitive meaning is that of a subscript.
928 Usually, the primary expression has type <quote>pointer to ...</quote>,
929 the subscript expression is
930 <literal>int</literal>,
931 and the type of the result is <quote>...</quote>.
932 The expression
933 <literal>
934 E1[E2]
935 </literal>
936 is
937 identical (by definition) to
938 <literal>
939 *((E1)+E2))</literal>.
940 All the clues
941 needed to understand
942 this notation are contained in this subpart together
943 with the discussions
944 in <quote>Unary Operators</quote> and <quote>Additive Operators</quote> on identifiers,
945 <literal>
946 *
947 </literal>
948 and
949 <literal>
950 +
951 </literal>
952 respectively.
953 The implications are summarized under <quote>Arrays, Pointers, and Subscripting</quote>
954 under <quote>TYPES REVISITED.</quote>
955 </para><para>
956 A function call is a primary expression followed by parentheses
957 containing a possibly
958 empty, comma-separated list of expressions
959 which constitute the actual arguments to the
960 function.
961 The primary expression must be of type <quote>function returning ...,</quote>
962 and the result of the function call is of type <quote>...</quote>.
963 As indicated
964 below, a hitherto unseen identifier followed
965 immediately by a left parenthesis
966 is contextually declared
967 to represent a function returning
968 an integer;
969 thus in the most common case, integer-valued functions
970 need not be declared.
971 </para><para>
972 Any actual arguments of type
973 <literal>float</literal>
974 are
975 converted to
976 <literal>double</literal>
977 before the call.
978 Any of type
979 <literal>char</literal>
980 or
981 <literal>short</literal>
982 are converted to
983 <literal>int</literal>.
984 Array names are converted to pointers.
985 No other conversions are performed automatically;
986 in particular, the compiler does not compare
987 the types of actual arguments with those of formal
988 arguments.
989 If conversion is needed, use a cast;
990 see <quote>Unary Operators</quote> and <quote>Type Names</quote> under
991 <quote>DECLARATIONS.</quote>
992 </para><para>
993 In preparing for the call to a function,
994 a copy is made of each actual parameter.
995 Thus, all argument passing in C is strictly by value.
996 A function may
997 change the values of its formal parameters, but
998 these changes cannot affect the values
999 of the actual parameters.
1000 It is possible
1001 to pass a pointer on the understanding
1002 that the function may change the value
1003 of the object to which the pointer points.
1004 An array name is a pointer expression.
1005 The order of evaluation of arguments is undefined by the language;
1006 take note that the various compilers differ.
1007 Recursive calls to any
1008 function are permitted.
1009 </para><para>
1010 A primary expression followed by a dot followed by an identifier
1011 is an expression.
1012 The first expression must be a structure or a union, and the identifier
1013 must name a member of the structure or union.
1014 The value is the named member of the structure or union, and it is
1015 an lvalue if the first expression is an lvalue.
1016 </para><para>
1017 A primary expression followed by an arrow (built from
1018 <literal>
1019 -
1020 </literal>
1021 and
1022 <literal>
1023 >
1024 </literal>
1025 )
1026 followed by an identifier
1027 is an expression.
1028 The first expression must be a pointer to a structure or a union
1029 and the identifier must name a member of that structure or union.
1030 The result is an lvalue referring to the named member
1031 of the structure or union
1032 to which the pointer expression points.
1033 Thus the expression
1034 <literal>
1035 E1->MOS
1036 </literal>
1037 is the same as
1038 <literal>
1039 (*E1).MOS</literal>.
1040 Structures and unions are discussed in
1041 <quote>Structure, Union, and Enumeration Declarations</quote> under
1042 <quote>DECLARATIONS.</quote>
1043 </para></sect2>
1044 <sect2><title>Unary Operators</title>
1045 <para>
1046 Expressions with unary operators
1047 group right to left.
1048 <literallayout>
1049 <emphasis>unary-expression:
1050 * expression
1051 &amp; lvalue
1052 - expression
1053 ! expression
1054 ~ expression
1055 ++ lvalue
1056 --lvalue
1057 lvalue ++
1058 lvalue --
1059 ( type-name ) expression</emphasis>
1060 sizeof<emphasis> expression</emphasis>
1061 sizeof<emphasis> ( type-name )</emphasis>
1062 </literallayout>
1063 </para><para>
1064 The unary
1065 <literal>
1066 *
1067 </literal>
1068 operator
1069 means
1070 <emphasis>
1071 indirection
1072 </emphasis>
1073 ;
1074 the expression must be a pointer, and the result
1075 is an lvalue referring to the object to
1076 which the expression points.
1077 If the type of the expression is <quote>pointer to ...,</quote>
1078 the type of the result is <quote>...</quote>.
1079 </para><para>
1080 The result of the unary
1081 <literal>
1082 &amp;
1083 </literal>
1084 operator is a pointer
1085 to the object referred to by the
1086 lvalue.
1087 If the type of the lvalue is <quote>...</quote>,
1088 the type of the result is <quote>pointer to ...</quote>.
1089 </para><para>
1090 The result
1091 of the unary
1092 <literal>
1093 -
1094 </literal>
1095 operator
1096 is the negative of its operand.
1097 The usual arithmetic conversions are performed.
1098 The negative of an unsigned quantity is computed by
1099 subtracting its value from
1100 2<superscript><emphasis>n</emphasis></superscript> where <emphasis>n</emphasis> is the number of bits in
1101 the corresponding signed type.
1102
1103 There is no unary
1104 <literal>
1105 +
1106 </literal>
1107 operator.
1108 </para><para>
1109 The result of the logical negation operator
1110 <literal>
1111 !
1112 </literal>
1113 is one if the value of its operand is zero, zero if the value of its
1114 operand is nonzero.
1115 The type of the result is
1116 <literal>int</literal>.
1117 It is applicable to any arithmetic type
1118 or to pointers.
1119 </para><para>
1120 The
1121 <literal>
1122 ~
1123 </literal>
1124 operator yields the one's complement of its operand.
1125 The usual arithmetic conversions are performed.
1126 The type of the operand must be integral.
1127 </para><para>
1128 The object referred to by the lvalue operand of prefix
1129 <literal>
1130 ++
1131 </literal>
1132 is incremented.
1133 The value is the new value of the operand
1134 but is not an lvalue.
1135 The expression
1136 <literal>
1137 ++x
1138 </literal>
1139 is equivalent to
1140 <literal>x=x+1</literal>.
1141 See the discussions <quote>Additive Operators</quote> and <quote>Assignment
1142 Operators</quote> for information on conversions.
1143 </para><para>
1144 The lvalue operand of prefix
1145 <literal>
1146 --
1147 </literal>
1148 is decremented
1149 analogously to the
1150 prefix
1151 <literal>
1152 ++
1153 </literal>
1154 operator.
1155 </para><para>
1156 When postfix
1157 <literal>
1158 ++
1159 </literal>
1160 is applied to an lvalue,
1161 the result is the value of the object referred to by the lvalue.
1162 After the result is noted, the object
1163 is incremented in the same
1164 manner as for the prefix
1165 <literal>
1166 ++
1167 </literal>
1168 operator.
1169 The type of the result is the same as the type of the lvalue expression.
1170 </para><para>
1171 When postfix
1172 <literal>
1173 --
1174 </literal>
1175 is applied to an lvalue,
1176 the result is the value of the object referred to by the lvalue.
1177 After the result is noted, the object
1178 is decremented in the manner as for the prefix
1179 <literal>
1180 --
1181 </literal>
1182 operator.
1183 The type of the result is the same as the type of the lvalue
1184 expression.
1185 </para><para>
1186 An expression preceded by the parenthesized name of a data type
1187 causes conversion of the value of the expression to the named type.
1188 This construction is called a
1189 <emphasis>
1190 cast</emphasis>.
1191 Type names are described in <quote>Type Names</quote> under <quote>Declarations.</quote>
1192 </para><para>
1193 The
1194 <literal>
1195 sizeof
1196 </literal>
1197 operator yields the size
1198 in bytes of its operand.
1199 (A
1200 <emphasis>
1201 byte
1202 </emphasis>
1203 is undefined by the language
1204 except in terms of the value of
1205 <literal>
1206 sizeof</literal>.
1207 However, in all existing implementations,
1208 a byte is the space required to hold a
1209 <literal>char</literal>.)
1210 When applied to an array, the result is the total
1211 number of bytes in the array.
1212 The size is determined from
1213 the declarations of
1214 the objects in the expression.
1215 This expression is semantically an
1216 <literal>unsigned</literal>
1217 constant and may
1218 be used anywhere a constant is required.
1219 Its major use is in communication with routines
1220 like storage allocators and I/O systems.
1221 </para><para>
1222 The
1223 <literal>
1224 sizeof
1225 </literal>
1226 operator
1227 may also be applied to a parenthesized type name.
1228 In that case it yields the size in bytes of an object
1229 of the indicated type.
1230 </para><para>
1231 The construction
1232 <literal>sizeof(</literal><emphasis>type</emphasis><literal>)</literal>
1233 is taken to be a unit,
1234 so the expression
1235 <literal>sizeof(</literal><emphasis>type</emphasis><literal>)-2</literal>
1236 is the same as
1237 <literal>(sizeof(</literal><emphasis>type</emphasis><literal>))-2</literal>.
1238 </para></sect2>
1239 <sect2><title>Multiplicative Operators</title>
1240 <para>
1241 The multiplicative operators
1242 <literal>*</literal>,
1243 <literal>/</literal>,
1244 and
1245 <literal>
1246 %
1247 </literal>
1248 group left to right.
1249 The usual arithmetic conversions are performed.
1250 <literallayout>
1251 <emphasis>multiplicative expression:
1252 expression * expression
1253 expression / expression
1254 expression % expression</emphasis>
1255 </literallayout>
1256 </para><para>
1257 The binary
1258 <literal>
1259 *
1260 </literal>
1261 operator indicates multiplication.
1262 The
1263 <literal>
1264 *
1265 </literal>
1266 operator is associative,
1267 and expressions with several multiplications at the same
1268 level may be rearranged by the compiler.
1269 The binary
1270 <literal>
1271 /
1272 </literal>
1273 operator indicates division.
1274 </para><para>
1275 The binary
1276 <literal>
1277 %
1278 </literal>
1279 operator yields the remainder
1280 from the division of the first expression by the second.
1281 The operands must be integral.
1282 </para><para>
1283 When positive integers are divided, truncation is toward 0;
1284 but the form of truncation is machine-dependent
1285 if either operand is negative.
1286 On all machines covered by this manual,
1287 the remainder has the same sign as the dividend.
1288 It is always true that
1289 <literal>
1290 (a/b)*b\ + a%b
1291 </literal>
1292 is equal to
1293 <literal>
1294 a
1295 </literal>
1296 (if
1297 <literal>
1298 b
1299 </literal>
1300 is not 0).
1301 </para></sect2>
1302 <sect2><title>Additive Operators</title>
1303 <para>
1304 The additive operators
1305 <literal>
1306 +
1307 </literal>
1308 and
1309 <literal>
1310 -
1311 </literal>
1312 group left to right.
1313 The usual arithmetic conversions are performed.
1314 There are some additional type possibilities for each operator.
1315 <literallayout>
1316 <emphasis>additive-expression:
1317 expression + expression
1318 expression - expression</emphasis>
1319 </literallayout>
1320 </para><para>
1321 The result of the
1322 <literal>
1323 +
1324 </literal>
1325 operator is the sum of the operands.
1326 A pointer to an object in an array and
1327 a value of any integral type
1328 may be added.
1329 The latter is in all cases converted to
1330 an address offset
1331 by multiplying it
1332 by the length of the object to which the
1333 pointer points.
1334 The result is a pointer
1335 of the same type as the original pointer
1336 which points to another object in the same array,
1337 appropriately offset from the original object.
1338 Thus if
1339 <literal>
1340 P
1341 </literal>
1342 is a pointer
1343 to an object in an array, the expression
1344 <literal>
1345 P+1
1346 </literal>
1347 is a pointer
1348 to the next object in the array.
1349 No further type combinations are allowed for pointers.
1350 </para><para>
1351 The
1352 <literal>
1353 +
1354 </literal>
1355 operator is associative,
1356 and expressions with several additions at the same level may
1357 be rearranged by the compiler.
1358 </para><para>
1359 The result of the
1360 <literal>
1361 -
1362 </literal>
1363 operator is the difference of the operands.
1364 The usual arithmetic conversions are performed.
1365 Additionally,
1366 a value of any integral type
1367 may be subtracted from a pointer,
1368 and then the same conversions for addition apply.
1369 </para><para>
1370 If two pointers to objects of the same type are subtracted,
1371 the result is converted
1372 (by division by the length of the object)
1373 to an
1374 <literal>int</literal>
1375 representing the number of
1376 objects separating
1377 the pointed-to objects.
1378 This conversion will in general give unexpected
1379 results unless the pointers point
1380 to objects in the same array, since pointers, even
1381 to objects of the same type, do not necessarily differ
1382 by a multiple of the object length.
1383 </para></sect2>
1384 <sect2><title>Shift Operators</title>
1385 <para>
1386 The shift operators
1387 <literal>
1388 &lt;&lt;
1389 </literal>
1390 and
1391 <literal>
1392 >>
1393 </literal>
1394 group left to right.
1395 Both perform the usual arithmetic conversions on their operands,
1396 each of which must be integral.
1397 Then the right operand is converted to
1398 <literal>int</literal>;
1399 the type of the result is that of the left operand.
1400 The result is undefined if the right operand is negative
1401 or greater than or equal to the length of the object in bits.
1402 On the VAX a negative right operand is interpreted as reversing
1403 the direction of the shift.
1404 <literallayout>
1405 <emphasis>shift-expression:
1406 expression &lt;&lt; expression
1407 expression >> expression</emphasis>
1408 </literallayout>
1409 </para><para>
1410 The value of
1411 <literal>
1412 E1&lt;&lt;E2
1413 </literal>
1414 is
1415 <literal>
1416 E1
1417 </literal>
1418 (interpreted as a bit
1419 pattern) left-shifted
1420 <literal>
1421 E2
1422 </literal>
1423 bits.
1424 Vacated bits are 0 filled.
1425 The value of
1426 <literal>
1427 E1>>E2
1428 </literal>
1429 is
1430 <literal>
1431 E1
1432 </literal>
1433 right-shifted
1434 <literal>
1435 E2
1436 </literal>
1437 bit positions.
1438 The right shift is guaranteed to be logical
1439 (0 fill)
1440 if
1441 <literal>
1442 E1
1443 </literal>
1444 is
1445 <literal>unsigned</literal>;
1446 otherwise, it may be
1447 arithmetic.
1448 </para></sect2>
1449 <sect2><title>Relational Operators</title>
1450 <para>
1451 The relational operators group left to right.
1452 <literallayout>
1453 <emphasis>relational-expression:
1454 expression &lt; expression
1455 expression > expression
1456 expression &lt;= expression
1457 expression >= expression</emphasis>
1458 </literallayout>
1459 </para><para>
1460 The operators
1461 <literal>
1462 &lt;
1463 </literal>
1464 (less than),
1465 <literal>
1466 >
1467 </literal>
1468 (greater than), <literal>&lt;=</literal>
1469 (less than
1470 or equal to), and
1471 <literal>
1472 >=
1473 </literal>
1474 (greater than or equal to)
1475 all yield 0 if the specified relation is false
1476 and 1 if it is true.
1477 The type of the result is
1478 <literal>int</literal>.
1479 The usual arithmetic conversions are performed.
1480 Two pointers may be compared;
1481 the result depends on the relative locations in the address space
1482 of the pointed-to objects.
1483 Pointer comparison is portable only when the pointers point to objects
1484 in the same array.
1485 </para></sect2>
1486 <sect2><title>Equality Operators</title>
1487 <para>
1488 <literallayout>
1489 <emphasis>equality-expression:
1490 expression == expression
1491 expression != expression</emphasis>
1492 </literallayout>
1493 </para><para>
1494 The
1495 <literal>
1496 ==
1497 </literal>
1498 (equal to) and the
1499 <literal>
1500 !=
1501 </literal>
1502 (not equal to) operators
1503 are exactly analogous to the relational
1504 operators except for their lower
1505 precedence.
1506 (Thus
1507 <literal>
1508 a&lt;b\ ==\ c&lt;d
1509 </literal>
1510 is 1 whenever
1511 <literal>
1512 a&lt;b
1513 </literal>
1514 and
1515 <literal>
1516 c&lt;d
1517 </literal>
1518 have the same truth value).
1519 </para><para>
1520 A pointer may be compared to an integer
1521 only if the
1522 integer is the constant 0.
1523 A pointer to which 0 has been assigned is guaranteed
1524 not to point to any object
1525 and will appear to be equal to 0.
1526 In conventional usage, such a pointer is considered to be null.
1527 </para></sect2>
1528 <sect2><title>Bitwise AND Operator</title>
1529 <para>
1530 <literallayout>
1531 <emphasis>and-expression:
1532 expression &amp; expression</emphasis>
1533 </literallayout>
1534 </para><para>
1535 The
1536 <literal>
1537 &amp;
1538 </literal>
1539 operator is associative,
1540 and expressions involving
1541 <literal>
1542 &amp;
1543 </literal>
1544 may be rearranged.
1545 The usual arithmetic conversions are performed.
1546 The result is the bitwise
1547 AND
1548 function of the operands.
1549 The operator applies only to integral
1550 operands.
1551 </para></sect2>
1552 <sect2><title>Bitwise Exclusive OR Operator</title>
1553 <literallayout>
1554 <emphasis>exclusive-or-expression:
1555 expression ^ expression</emphasis>
1556 </literallayout>
1557 <para>
1558 The
1559 <literal>
1560 ^
1561 </literal>
1562 operator is associative,
1563 and expressions involving
1564 <literal>
1565 ^
1566 </literal>
1567 may be rearranged.
1568 The usual arithmetic conversions are performed;
1569 the result is
1570 the bitwise exclusive
1571 OR
1572 function of
1573 the operands.
1574 The operator applies only to integral
1575 operands.
1576 </para></sect2>
1577 <sect2><title>Bitwise Inclusive OR Operator</title>
1578 <literallayout>
1579 <emphasis>inclusive-or-expression:
1580 expression | expression</emphasis>
1581 </literallayout>
1582 <para>
1583 The
1584 <literal>
1585 |
1586 </literal>
1587 operator is associative,
1588 and expressions involving
1589 <literal>
1590 |
1591 </literal>
1592 may be rearranged.
1593 The usual arithmetic conversions are performed;
1594 the result is the bitwise inclusive
1595 OR
1596 function of its operands.
1597 The operator applies only to integral
1598 operands.
1599 </para></sect2>
1600 <sect2><title>Logical AND Operator</title>
1601 <literallayout>
1602 <emphasis>logical-and-expression:
1603 expression &amp;&amp; expression</emphasis>
1604 </literallayout>
1605 <para>
1606 The
1607 <literal>
1608 &amp;&amp;
1609 </literal>
1610 operator groups left to right.
1611 It returns 1 if both its operands
1612 evaluate to nonzero, 0 otherwise.
1613 Unlike
1614 <literal>&amp;</literal>,
1615 <literal>
1616 &amp;&amp;
1617 </literal>
1618 guarantees left to right
1619 evaluation; moreover, the second operand is not evaluated
1620 if the first operand is 0.
1621 </para><para>
1622 The operands need not have the same type, but each
1623 must have one of the fundamental
1624 types or be a pointer.
1625 The result is always
1626 <literal>int</literal>.
1627 </para></sect2>
1628 <sect2><title>Logical OR Operator</title>
1629 <literallayout>
1630 <emphasis>logical-or-expression:
1631 expression || expression</emphasis>
1632 </literallayout>
1633 <para>
1634 The
1635 <literal>
1636 ||
1637 </literal>
1638 operator groups left to right.
1639 It returns 1 if either of its operands
1640 evaluates to nonzero, 0 otherwise.
1641 Unlike
1642 <literal>|</literal>,
1643 <literal>
1644 ||
1645 </literal>
1646 guarantees left to right evaluation; moreover,
1647 the second operand is not evaluated
1648 if the value of the first operand is nonzero.
1649 </para><para>
1650 The operands need not have the same type, but each
1651 must
1652 have one of the fundamental types
1653 or be a pointer.
1654 The result is always
1655 <literal>int</literal>.
1656 </para></sect2>
1657 <sect2><title>Conditional Operator</title>
1658 <literallayout>
1659 <emphasis>conditional-expression:
1660 expression ? expression : expression</emphasis>
1661 </literallayout>
1662 <para>
1663 Conditional expressions group right to left.
1664 The first expression is evaluated;
1665 and if it is nonzero, the result is the value of the
1666 second expression, otherwise that of third expression.
1667 If possible, the usual arithmetic conversions are performed
1668 to bring the second and third expressions to a common type.
1669 If both are structures or unions of the same type,
1670 the result has the type of the structure or union.
1671 If both pointers are of the same type,
1672 the result has the common type.
1673 Otherwise, one must be a pointer and the other the constant 0,
1674 and the result has the type of the pointer.
1675 Only one of the second and third
1676 expressions is evaluated.
1677 </para></sect2>
1678 <sect2><title>Assignment Operators</title>
1679 <para>
1680 There are a number of assignment operators,
1681 all of which group right to left.
1682 All require an lvalue as their left operand,
1683 and the type of an assignment expression is that
1684 of its left operand.
1685 The value is the value stored in the
1686 left operand after the assignment has taken place.
1687 The two parts of a compound assignment operator are separate
1688 tokens.
1689 <literallayout>
1690 <emphasis>assignment-expression:
1691 lvalue = expression
1692 lvalue += expression
1693 lvalue -= expression
1694 lvalue *= expression
1695 lvalue /= expression
1696 lvalue %= expression
1697 lvalue >>= expression
1698 lvalue &lt;&lt;= expression
1699 lvalue &amp;= expression
1700 lvalue ^= expression
1701 lvalue |= expression</emphasis>
1702 </literallayout>
1703 </para><para>
1704 In the simple assignment with
1705 <literal>=</literal>,
1706 the value of the expression replaces that of the object
1707 referred
1708 to by the lvalue.
1709 If both operands have arithmetic type,
1710 the right operand is converted to the type of the left
1711 preparatory to the assignment.
1712 Second, both operands may be structures or unions of the same type.
1713 Finally, if the left operand is a pointer, the right operand must in general be a pointer
1714 of the same type.
1715 However, the constant 0 may be assigned to a pointer;
1716 it is guaranteed that this value will produce a null
1717 pointer distinguishable from a pointer to any object.
1718 </para><para>
1719 The behavior of an expression
1720 of the form
1721 <literal>E1</literal> <emphasis>op</emphasis> = <literal>E2</literal>
1722 may be inferred by
1723 taking it as equivalent to
1724 <literal>E1 = E1</literal> <emphasis>op</emphasis> (<literal>E2</literal>);
1725 however,
1726 <literal>
1727 E1
1728 </literal>
1729 is evaluated only once.
1730 In
1731 <literal>
1732 +=
1733 </literal>
1734 and
1735 <literal>-=</literal>,
1736 the left operand may be a pointer; in which case, the (integral) right
1737 operand is converted as explained
1738 in <quote>Additive Operators.</quote>
1739 All right operands and all nonpointer left operands must
1740 have arithmetic type.
1741 </para></sect2>
1742 <sect2><title>Comma Operator</title>
1743 <literallayout>
1744 <emphasis>comma-expression:
1745 expression , expression</emphasis>
1746 </literallayout>
1747 <para>
1748 A pair of expressions separated by a comma is evaluated
1749 left to right, and the value of the left expression is
1750 discarded.
1751 The type and value of the result are the
1752 type and value of the right operand.
1753 This operator groups left to right.
1754 In contexts where comma is given a special meaning,
1755 e.g., in lists of actual arguments
1756 to functions (see <quote>Primary Expressions</quote>) and lists
1757 of initializers (see <quote>Initialization</quote> under <quote>DECLARATIONS</quote>),
1758 the comma operator as described in this subpart
1759 can only appear in parentheses. For example,
1760 <literallayout>
1761 <literal>f(a, (t=3, t+2), c)</literal>
1762 </literallayout>
1763 has three arguments, the second of which has the value 5.
1764 </para></sect2></sect1>
1765 <sect1><title>
1766 Declarations
1767 </title><para>
1768 Declarations are used to specify the interpretation
1769 which C gives to each identifier; they do not necessarily
1770 reserve storage associated with the identifier.
1771 Declarations have the form
1772 <literallayout>
1773 <emphasis>declaration:
1774 decl-specifiers declarator-list<subscript>opt</subscript> ;</emphasis>
1775 </literallayout>
1776 </para><para>
1777 The declarators in the declarator-list
1778 contain the identifiers being declared.
1779 The decl-specifiers
1780 consist of a sequence of type and storage class specifiers.
1781 <literallayout>
1782 <emphasis>decl-specifiers:
1783 type-specifier decl-specifiers<subscript>opt</subscript>
1784 sc-specifier decl-specifiers<subscript>opt</subscript></emphasis>
1785 </literallayout>
1786 </para><para>
1787 The list must be self-consistent in a way described below.
1788 </para>
1789 <sect2><title>Storage Class Specifiers</title>
1790 <para>
1791 The sc-specifiers are:
1792 <literallayout>
1793 <emphasis>sc-specifier:</emphasis><literal>
1794 auto
1795 static
1796 extern
1797 register
1798 typedef</literal>
1799 </literallayout>
1800 </para><para>
1801 The
1802 <literal>typedef</literal>
1803 specifier does not reserve storage
1804 and is called a <quote>storage class specifier</quote> only for syntactic convenience.
1805 See <quote>Typedef</quote> for more information.
1806 The meanings of the various storage classes were discussed in <quote>Names.</quote>
1807 </para><para>
1808 The
1809 <literal>auto</literal>,
1810 <literal>static</literal>,
1811 and
1812 <literal>register</literal>
1813 declarations also serve as definitions
1814 in that they cause an appropriate amount of storage to be reserved.
1815 In the
1816 <literal>extern</literal>
1817 case,
1818 there must be an external definition (see <quote>External Definitions</quote>)
1819 for the given identifiers
1820 somewhere outside the function in which they are declared.
1821 </para><para>
1822 A
1823 <literal>register</literal>
1824 declaration is best thought of as an
1825 <literal>auto</literal>
1826 declaration, together with a hint to the compiler
1827 that the variables declared will be heavily used.
1828 Only the first few
1829 such declarations in each function are effective.
1830 Moreover, only variables of certain types will be stored in registers;
1831 on the
1832 PDP-11,
1833 they are
1834 <literal>int</literal>
1835 or pointer.
1836 One other restriction applies to register variables:
1837 the address-of operator
1838 <literal>
1839 &amp;
1840 </literal>
1841 cannot be applied to them.
1842 Smaller, faster programs can be expected if register declarations
1843 are used appropriately,
1844 but future improvements in code generation
1845 may render them unnecessary.
1846 </para><para>
1847 At most, one sc-specifier may be given in a declaration.
1848 If the sc-specifier is missing from a declaration, it
1849 is taken to be
1850 <literal>auto</literal>
1851 inside a function,
1852 <literal>extern</literal>
1853 outside.
1854 Exception:
1855 functions are never automatic.
1856 </para></sect2>
1857 <sect2><title>Type Specifiers</title>
1858 <para>
1859 The type-specifiers are
1860 <literallayout>
1861 <emphasis>type-specifier:</emphasis>
1862 <literal>char
1863 short
1864 int
1865 long
1866 unsigned
1867 float
1868 double</literal>
1869 <emphasis>struct-or-union-specifier
1870 typedef-name</emphasis>
1871 </literallayout>
1872 </para><para>
1873 At most one of the words <literal>long</literal> or <literal>short</literal>
1874 may be specified in conjunction with <literal>int</literal>;
1875 the meaning is the same as if <literal>int</literal> were not mentioned.
1876 The word <literal>long</literal> may be specified in conjunction with
1877 <literal>float</literal>;
1878 the meaning is the same as <literal>double</literal>.
1879 The word <literal>unsigned</literal> may be specified alone, or
1880 in conjunction with <literal>int</literal> or any of its short
1881 or long varieties, or with <literal>char</literal>.
1882 </para><para>
1883 Otherwise, at most on type-specifier may be
1884 given in a declaration.
1885 In particular, adjectival use of <literal>long</literal>,
1886 <literal>short</literal>, or <literal>unsigned</literal> is not permitted
1887 with <literal>typedef</literal> names.
1888 If the type-specifier is missing from a declaration,
1889 it is taken to be <literal>int</literal>.
1890 </para><para>
1891 Specifiers for structures, unions, and enumerations are discussed in
1892 <quote>Structure, Union, and Enumeration Declarations.</quote>
1893 Declarations with
1894 <literal>
1895 typedef
1896 </literal>
1897 names are discussed in <quote>Typedef.</quote>
1898 </para></sect2>
1899 <sect2><title>Declarators</title>
1900 <para>
1901 The declarator-list appearing in a declaration
1902 is a comma-separated sequence of declarators,
1903 each of which may have an initializer.
1904 <literallayout>
1905 <emphasis>declarator-list:
1906 init-declarator
1907 init-declarator , declarator-list</emphasis>
1908 </literallayout>
1909 <literallayout>
1910 <emphasis>init-declarator:
1911 declarator initializer<subscript>opt</subscript></emphasis>
1912 </literallayout>
1913 </para><para>
1914 Initializers are discussed in <quote>Initialization</quote>.
1915 The specifiers in the declaration
1916 indicate the type and storage class of the objects to which the
1917 declarators refer.
1918 Declarators have the syntax:
1919 <literallayout>
1920 <emphasis>declarator:
1921 identifier
1922 ( declarator )
1923 * declarator
1924 declarator ()
1925 declarator [ constant-expression<subscript>opt</subscript> ]</emphasis>
1926 </literallayout>
1927 </para><para>
1928 The grouping is
1929 the same as in expressions.
1930 </para></sect2>
1931 <sect2><title>Meaning of Declarators</title>
1932 <para>
1933 Each declarator is taken to be
1934 an assertion that when a construction of
1935 the same form as the declarator appears in an expression,
1936 it yields an object of the indicated
1937 type and storage class.
1938 </para><para>
1939 Each declarator contains exactly one identifier; it is this identifier that
1940 is declared.
1941 If an unadorned identifier appears
1942 as a declarator, then it has the type
1943 indicated by the specifier heading the declaration.
1944 </para><para>
1945 A declarator in parentheses is identical to the unadorned declarator,
1946 but the binding of complex declarators may be altered by parentheses.
1947 See the examples below.
1948 </para><para>
1949 Now imagine a declaration
1950 <literallayout>
1951 <literal>T D1</literal>
1952 </literallayout>
1953 where
1954 <literal>
1955 T
1956 </literal>
1957 is a type-specifier (like
1958 <literal>int</literal>,
1959 etc.)
1960 and
1961 <literal>
1962 D1
1963 </literal>
1964 is a declarator.
1965 Suppose this declaration makes the identifier have type
1966 <quote>...
1967 <literal>
1968 T
1969 </literal>
1970 ,</quote>
1971 where the <quote>...</quote> is empty if
1972 <literal>
1973 D1
1974 </literal>
1975 is just a plain identifier
1976 (so that the type of
1977 <literal>
1978 x
1979 </literal>
1980 in
1981 <quote><literal>int x</literal></quote>
1982 is just
1983 <literal>int</literal>).
1984 Then if
1985 <literal>
1986 D1
1987 </literal>
1988 has the form
1989 <literallayout>
1990 <literal>*D</literal>
1991 </literallayout>
1992 the type of the contained identifier is
1993 <quote>... pointer to
1994 <literal>
1995 T
1996 </literal>
1997 \&amp;.</quote>
1998 </para><para>
1999 If
2000 <literal>
2001 D1
2002 </literal>
2003 has the form
2004 <literallayout>
2005 <literal>D()</literal>
2006 </literallayout>
2007 then the contained identifier has the type
2008 <quote>... function returning
2009 <literal>T</literal>.</quote>
2010 If
2011 <literal>
2012 D1
2013 </literal>
2014 has the form
2015 <literallayout>
2016 <literal>D[</literal><emphasis>constant-expression</emphasis><literal>]</literal>
2017 </literallayout>
2018 or
2019 <literallayout>
2020 <literal>D[]</literal>
2021 </literallayout>
2022 then the contained identifier has type
2023 <quote>... array of
2024 <literal>T</literal>.</quote>
2025 In the first case, the constant
2026 expression
2027 is an expression
2028 whose value is determinable at compile time
2029 , whose type is
2030 <literal>int</literal>,
2031 and whose value is positive.
2032 (Constant expressions are defined precisely in <quote>Constant Expressions.</quote>)
2033 When several <quote>array of</quote> specifications are adjacent, a multidimensional
2034 array is created;
2035 the constant expressions which specify the bounds
2036 of the arrays may be missing only for the first member of the sequence.
2037 This elision is useful when the array is external
2038 and the actual definition, which allocates storage,
2039 is given elsewhere.
2040 The first constant expression may also be omitted
2041 when the declarator is followed by initialization.
2042 In this case the size is calculated from the number
2043 of initial elements supplied.
2044 </para><para>
2045 An array may be constructed from one of the basic types, from a pointer,
2046 from a structure or union,
2047 or from another array (to generate a multidimensional array).
2048 </para><para>
2049 Not all the possibilities
2050 allowed by the syntax above are actually
2051 permitted.
2052 The restrictions are as follows:
2053 functions may not return
2054 arrays or functions
2055 although they may return pointers;
2056 there are no arrays of functions although
2057 there may be arrays of pointers to functions.
2058 Likewise, a structure or union may not contain a function;
2059 but it may contain a pointer to a function.
2060 </para><para>
2061 As an example, the declaration
2062 <literallayout>
2063 <literal>int i, *ip, f(), *fip(), (*pfi)();</literal>
2064 </literallayout>
2065 declares an integer
2066 <literal>i</literal>,
2067 a pointer
2068 <literal>
2069 ip
2070 </literal>
2071 to an integer,
2072 a function
2073 <literal>
2074 f
2075 </literal>
2076 returning an integer,
2077 a function
2078 <literal>
2079 fip
2080 </literal>
2081 returning a pointer to an integer,
2082 and a pointer
2083 <literal>
2084 pfi
2085 </literal>
2086 to a function which
2087 returns an integer.
2088 It is especially useful to compare the last two.
2089 The binding of
2090 <literal>
2091 *fip()
2092 </literal>
2093 is
2094 <literal>
2095 *(fip())</literal>.
2096 The declaration suggests,
2097 and the same construction in an expression
2098 requires, the calling of a function
2099 <literal>
2100 fip</literal>.
2101 Using indirection through the (pointer) result
2102 to yield an integer.
2103 In the declarator
2104 <literal>(*pfi)()</literal>,
2105 the extra parentheses are necessary, as they are also
2106 in an expression, to indicate that indirection through
2107 a pointer to a function yields a function, which is then called;
2108 it returns an integer.
2109 </para><para>
2110 As another example,
2111 <literallayout>
2112 <literal>float fa[17], *afp[17];</literal>
2113 </literallayout>
2114 declares an array of
2115 <literal>float</literal>
2116 numbers and an array of
2117 pointers to
2118 <literal>float</literal>
2119 numbers.
2120 Finally,
2121 <literallayout>
2122 <literal>static int x3d[3][5][7];</literal>
2123 </literallayout>
2124 declares a static 3-dimensional array of integers,
2125 with rank 3&times;5&times;7.
2126 In complete detail,
2127 <literal>
2128 x3d
2129 </literal>
2130 is an array of three items;
2131 each item is an array of five arrays;
2132 each of the latter arrays is an array of seven
2133 integers.
2134 Any of the expressions
2135 <literal>x3d</literal>,
2136 <literal>x3d[i]</literal>,
2137 <literal>x3d[i][j]</literal>,
2138 <literal>
2139 x3d[i][j][k]
2140 </literal>
2141 may reasonably appear in an expression.
2142 The first three have type <quote>array</quote>
2143 and the last has type
2144 <literal>int</literal>.
2145 </para></sect2>
2146 <sect2><title>Structure and Union Declarations</title>
2147 <para>
2148 A structure
2149 is an object consisting of a sequence of named members.
2150 Each member may have any type.
2151 A union is an object which may, at a given time, contain any one
2152 of several members.
2153 Structure and union specifiers have the same form.
2154 <literallayout>
2155 <emphasis>struct-or-union-specifier:
2156 struct-or-union { struct-decl-list }
2157 struct-or-union identifier { struct-decl-list }
2158 struct-or-union identifier</emphasis>
2159 </literallayout>
2160 <literallayout>
2161 <emphasis>struct-or-union:</emphasis><literal>
2162 struct
2163 union</literal>
2164 </literallayout>
2165 </para><para>
2166 The
2167 struct-decl-list
2168
2169 is a sequence of declarations for the members of the structure or union:
2170 <literallayout>
2171 <emphasis>struct-decl-list:
2172 struct-declaration
2173 struct-declaration struct-decl-list</emphasis>
2174 </literallayout>
2175 <literallayout>
2176 <emphasis>struct-declaration:
2177 type-specifier struct-declarator-list ;</emphasis>
2178 </literallayout>
2179 <literallayout>
2180 <emphasis>struct-declarator-list:
2181 struct-declarator
2182 struct-declarator , struct-declarator-list</emphasis>
2183 </literallayout>
2184 </para><para>
2185 In the usual case, a struct-declarator is just a declarator
2186 for a member of a structure or union.
2187 A structure member may also consist of a specified number of bits.
2188 Such a member is also called a
2189 <emphasis>
2190 field ;
2191 </emphasis>
2192 its length,
2193 a non-negative constant expression,
2194 is set off from the field name by a colon.
2195 <literallayout>
2196 <emphasis>struct-declarator:
2197 declarator
2198 declarator : constant-expression
2199 : constant-expression</emphasis>
2200 </literallayout>
2201 </para><para>
2202 Within a structure, the objects declared
2203 have addresses which increase as the declarations
2204 are read left to right.
2205 Each nonfield member of a structure
2206 begins on an addressing boundary appropriate
2207 to its type;
2208 therefore, there may
2209 be unnamed holes in a structure.
2210 Field members are packed into machine integers;
2211 they do not straddle words.
2212 A field which does not fit into the space remaining in a word
2213 is put into the next word.
2214 No field may be wider than a word.
2215 </para><para>
2216 Fields are assigned right to left
2217 on the
2218 PDP-11
2219 and
2220 VAX-11,
2221 left to right on the 3B 20.
2222 </para><para>
2223 A struct-declarator with no declarator, only a colon and a width,
2224 indicates an unnamed field useful for padding to conform
2225 to externally-imposed layouts.
2226 As a special case, a field with a width of 0
2227 specifies alignment of the next field at an implementation dependant boundary.
2228 </para><para>
2229 The language does not restrict the types of things that
2230 are declared as fields,
2231 but implementations are not required to support any but
2232 integer fields.
2233 Moreover,
2234 even
2235 <literal>int</literal>
2236 fields may be considered to be unsigned.
2237 On the
2238 PDP-11,
2239 fields are not signed and have only integer values;
2240 on the
2241 VAX-11,
2242 fields declared with
2243 <literal>int</literal>
2244 are treated as containing a sign.
2245 For these reasons,
2246 it is strongly recommended that fields be declared as
2247 <literal>unsigned</literal>.
2248 In all implementations,
2249 there are no arrays of fields,
2250 and the address-of operator
2251 <literal>
2252 &amp;
2253 </literal>
2254 may not be applied to them, so that there are no pointers to
2255 fields.
2256 </para><para>
2257 A union may be thought of as a structure all of whose members
2258 begin at offset 0 and whose size is sufficient to contain
2259 any of its members.
2260 At most, one of the members can be stored in a union
2261 at any time.
2262 </para><para>
2263 A structure or union specifier of the second form, that is, one of
2264 <literallayout>
2265 <literal>struct</literal> <emphasis>identifier { struct-decl-list </emphasis>}
2266 <literal>union</literal> <emphasis>identifier { struct-decl-list </emphasis>}
2267 </literallayout>
2268 declares the identifier to be the
2269 <emphasis>
2270 structure tag
2271 </emphasis>
2272 (or union tag)
2273 of the structure specified by the list.
2274 A subsequent declaration may then use
2275 the third form of specifier, one of
2276 <literallayout>
2277 <literal>struct</literal> <emphasis>identifier</emphasis>
2278 <literal>union</literal> <emphasis>identifier</emphasis>
2279 </literallayout>
2280 </para><para>
2281 Structure tags allow definition of self-referential
2282 structures. Structure tags also
2283 permit the long part of the declaration to be
2284 given once and used several times.
2285 It is illegal to declare a structure or union
2286 which contains an instance of
2287 itself, but a structure or union may contain a pointer to an instance of itself.
2288 </para><para>
2289 The third form of a structure or union specifier may be
2290 used prior to a declaration which gives the complete specification
2291 of the structure or union in situations in which the size
2292 of the structure or union is unnecessary.
2293 The size is unnecessary in two situations: when a
2294 pointer to a structure or union is being declared and
2295 when a <literal>typedef</literal> name is declared to be a synonym
2296 for a structure or union.
2297 This, for example, allows the declaration of a pair
2298 of structures which contain pointers to each other.
2299 </para><para>
2300 The names of members and tags do not conflict
2301 with each other or with ordinary variables.
2302 A particular name may not be used twice
2303 in the same structure,
2304 but the same name may be used in several different structures in the same scope.
2305 </para><para>
2306 A simple but important example of a structure declaration is
2307 the following binary tree structure:
2308 <literallayout>
2309 <literal>struct tnode
2310 {
2311 char tword[20];
2312 int count;
2313 struct tnode *left;
2314 struct tnode *right;
2315 };</literal>
2316 </literallayout>
2317 which contains an array of 20 characters, an integer, and two pointers
2318 to similar structures.
2319 Once this declaration has been given, the
2320 declaration
2321 <literallayout>
2322 <literal>struct tnode s, *sp;</literal>
2323 </literallayout>
2324 declares
2325 <literal>
2326 s
2327 </literal>
2328 to be a structure of the given sort
2329 and
2330 <literal>
2331 sp
2332 </literal>
2333 to be a pointer to a structure
2334 of the given sort.
2335 With these declarations, the expression
2336 <literallayout>
2337 <literal>sp->count</literal>
2338 </literallayout>
2339 refers to the
2340 <literal>
2341 count
2342 </literal>
2343 field of the structure to which
2344 <literal>
2345 sp
2346 </literal>
2347 points;
2348 <literallayout>
2349 <literal>s.left</literal>
2350 </literallayout>
2351 refers to the left subtree pointer
2352 of the structure
2353 <literal>s</literal>;
2354 and
2355 <literallayout>
2356 <literal>s.right->tword[0]</literal>
2357 </literallayout>
2358 refers to the first character of the
2359 <literal>
2360 tword
2361 </literal>
2362 member of the right subtree of
2363 <literal>
2364 s</literal>.
2365 </para><para>
2366 </para></sect2>
2367 <sect2><title>Initialization</title>
2368 <para>
2369 A declarator may specify an initial value for the
2370 identifier being declared.
2371 The initializer is preceded by
2372 <literal>
2373 =
2374 </literal>
2375 and
2376 consists of an expression or a list of values nested in braces.
2377 <literallayout>
2378 <emphasis>initializer:
2379 = expression
2380 = { initializer-list }
2381 = { initializer-list , }</emphasis>
2382 </literallayout>
2383 <literallayout>
2384 <emphasis>initializer-list:
2385 expression
2386 initializer-list , initializer-list</emphasis>
2387 { <emphasis>initializer-list </emphasis>}
2388 { <emphasis>initializer-list</emphasis> , }
2389 </literallayout>
2390 </para><para>
2391 All the expressions in an initializer
2392 for a static or external variable must be constant
2393 expressions, which are described in <quote>CONSTANT EXPRESSIONS</quote>,
2394 or expressions which reduce to the address of a previously
2395 declared variable, possibly offset by a constant expression.
2396 Automatic or register variables may be initialized by arbitrary
2397 expressions involving constants and previously declared variables and functions.
2398 </para><para>
2399 Static and external variables that are not initialized are
2400 guaranteed to start off as zero.
2401 Automatic and register variables that are not initialized
2402 are guaranteed to start off as garbage.
2403 </para><para>
2404 When an initializer applies to a
2405 <emphasis>
2406 scalar
2407 </emphasis>
2408 (a pointer or an object of arithmetic type),
2409 it consists of a single expression, perhaps in braces.
2410 The initial value of the object is taken from
2411 the expression; the same conversions as for assignment are performed.
2412 </para><para>
2413 When the declared variable is an
2414 <emphasis>
2415 aggregate
2416 </emphasis>
2417 (a structure or array),
2418 the initializer consists of a brace-enclosed, comma-separated list of
2419 initializers for the members of the aggregate
2420 written in increasing subscript or member order.
2421 If the aggregate contains subaggregates, this rule
2422 applies recursively to the members of the aggregate.
2423 If there are fewer initializers in the list than there are members of the aggregate,
2424 then the aggregate is padded with zeros.
2425 It is not permitted to initialize unions or automatic aggregates.
2426 </para><para>
2427 Braces may in some cases be omitted.
2428 If the initializer begins with a left brace, then
2429 the succeeding comma-separated list of initializers initializes
2430 the members of the aggregate;
2431 it is erroneous for there to be more initializers than members.
2432 If, however, the initializer does not begin with a left brace,
2433 then only enough elements from the list are taken to account
2434 for the members of the aggregate; any remaining members
2435 are left to initialize the next member of the aggregate of which
2436 the current aggregate is a part.
2437 </para><para>
2438 A final abbreviation allows a
2439 <literal>char</literal>
2440 array to be initialized by a string.
2441 In this case successive characters of the string
2442 initialize the members of the array.
2443 </para><para>
2444 For example,
2445 <literallayout>
2446 <literal>int x[] = { 1, 3, 5 };</literal>
2447 </literallayout>
2448 declares and initializes
2449 <literal>
2450 x
2451 </literal>
2452 as a one-dimensional array which has three members, since no size was specified
2453 and there are three initializers.
2454 <programlisting>
2455 float y[4][3] =
2456 {
2457 { 1, 3, 5 },
2458 { 2, 4, 6 },
2459 { 3, 5, 7 },
2460 };
2461 </programlisting>
2462 is a completely-bracketed initialization:
2463 1, 3, and 5 initialize the first row of
2464 the array
2465 <literal>y[0]</literal>,
2466 namely
2467 <literal>y[0][0]</literal>,
2468 <literal>y[0][1]</literal>,
2469 and
2470 <literal>
2471 y[0][2]</literal>.
2472 Likewise, the next two lines initialize
2473 <literal>
2474 y[1]
2475 </literal>
2476 and
2477 <literal>
2478 y[2]</literal>.
2479 The initializer ends early and therefore
2480 <literal>
2481 y[3]
2482 </literal>
2483 is initialized with 0.
2484 Precisely, the same effect could have been achieved by
2485 <literallayout>
2486 <literal>float y[4][3] =
2487 {
2488 1, 3, 5, 2, 4, 6, 3, 5, 7
2489 };</literal>
2490 </literallayout>
2491 </para><para>
2492 The initializer for
2493 <literal>
2494 y
2495 </literal>
2496 begins with a left brace but that for
2497 <literal>
2498 y[0]
2499 </literal>
2500 does not;
2501 therefore, three elements from the list are used.
2502 Likewise, the next three are taken successively for
2503 <literal>
2504 y[1]
2505 </literal>
2506 and
2507 <literal>
2508 y[2]</literal>.
2509 Also,
2510 <literallayout>
2511 <literal>float y[4][3] =
2512 {
2513 { 1 }, { 2 }, { 3 }, { 4 }
2514 };</literal>
2515 </literallayout>
2516 initializes the first column of
2517 <literal>
2518 y
2519 </literal>
2520 (regarded as a two-dimensional array)
2521 and leaves the rest 0.
2522 </para><para>
2523 Finally,
2524 <literallayout>
2525 <literal>char msg[] = "Syntax error on line %s\n";</literal>
2526 </literallayout>
2527 shows a character array whose members are initialized
2528 with a string.
2529 </para></sect2>
2530 <sect2><title>Type Names</title>
2531 <para>
2532 In two contexts (to specify type conversions explicitly
2533 by means of a cast
2534 and as an argument of
2535 <literal>sizeof</literal>),
2536 it is desired to supply the name of a data type.
2537 This is accomplished using a <quote>type name</quote>, which in essence
2538 is a declaration for an object of that type which omits the name of
2539 the object.
2540 <literallayout>
2541 <emphasis>type-name:
2542 type-specifier abstract-declarator</emphasis>
2543 </literallayout>
2544 <literallayout>
2545 <emphasis>abstract-declarator:
2546 empty
2547 ( abstract-declarator )
2548 * abstract-declarator
2549 abstract-declarator ()
2550 abstract-declarator</emphasis> [ <emphasis>constant-expression<subscript>opt</subscript> </emphasis>]
2551 </literallayout>
2552 </para><para>
2553 To avoid ambiguity,
2554 in the construction
2555 <literallayout>
2556 <emphasis>( abstract-declarator </emphasis>)
2557 </literallayout>
2558 the
2559 abstract-declarator
2560 is required to be nonempty.
2561 Under this restriction,
2562 it is possible to identify uniquely the location in the abstract-declarator
2563 where the identifier would appear if the construction were a declarator
2564 in a declaration.
2565 The named type is then the same as the type of the
2566 hypothetical identifier.
2567 For example,
2568 <programlisting>
2569 int
2570 int *
2571 int *[3]
2572 int (*)[3]
2573 int *()
2574 int (*)()
2575 int (*[3])()
2576 </programlisting>
2577 name respectively the types <quote>integer,</quote> <quote>pointer to integer,</quote>
2578 <quote>array of three pointers to integers,</quote>
2579 <quote>pointer to an array of three integers,</quote>
2580 <quote>function returning pointer to integer,</quote>
2581 <quote>pointer to function returning an integer,</quote>
2582 and <quote>array of three pointers to functions returning an integer.</quote>
2583 </para></sect2>
2584 <sect2><title>Typedef</title>
2585 <para>
2586 Declarations whose <quote>storage class</quote> is
2587 <literal>typedef</literal>
2588 do not define storage but instead
2589 define identifiers which can be used later
2590 as if they were type keywords naming fundamental
2591 or derived types.
2592 <literallayout>
2593 <emphasis>typedef-name:</emphasis>
2594 <emphasis>identifier</emphasis>
2595 </literallayout>
2596 </para><para>
2597 Within the scope of a declaration involving
2598 <literal>typedef</literal>,
2599 each identifier appearing as part of
2600 any declarator therein becomes syntactically
2601 equivalent to the type keyword
2602 naming the type
2603 associated with the identifier
2604 in the way described in <quote>Meaning of Declarators.</quote>
2605 For example,
2606 after
2607 <programlisting>
2608 typedef int MILES, *KLICKSP;
2609 typedef struct { double re, im; } complex;
2610 </programlisting>
2611 the constructions
2612 <literallayout>
2613 <literal>MILES distance;
2614 extern KLICKSP metricp;
2615 complex z, *zp;</literal>
2616 </literallayout>
2617 are all legal declarations; the type of
2618 <literal>
2619 distance
2620 </literal>
2621 is
2622 <literal>int</literal>,
2623 that of
2624 <literal>
2625 metricp
2626 </literal>
2627 is <quote>pointer to <literal>int</literal>, </quote>
2628 and that of
2629 <literal>
2630 z
2631 </literal>
2632 is the specified structure.
2633 The
2634 <literal>
2635 zp
2636 </literal>
2637 is a pointer to such a structure.
2638 </para><para>
2639 The
2640 <literal>typedef</literal>
2641 does not introduce brand-new types, only synonyms for
2642 types which could be specified in another way.
2643 Thus
2644 in the example above
2645 <literal>
2646 distance
2647 </literal>
2648 is considered to have exactly the same type as
2649 any other
2650 <literal>int</literal>
2651 object.
2652 </para></sect2></sect1>
2653 <sect1><title>
2654 Statements
2655 </title><para>
2656 Except as indicated, statements are executed in sequence.
2657 </para>
2658 <sect2><title>Expression Statement</title>
2659 <para>
2660 Most statements are expression statements, which have
2661 the form
2662 <literallayout>
2663 <emphasis>expression </emphasis>;
2664 </literallayout>
2665 </para><para>
2666 Usually expression statements are assignments or function
2667 calls.
2668 </para></sect2>
2669 <sect2><title>Compound Statement or Block</title>
2670 <para>
2671 So that several statements can be used where one is expected,
2672 the compound statement (also, and equivalently, called <quote>block</quote>) is provided:
2673 <literallayout>
2674 <emphasis>compound-statement:
2675 { declaration-list<subscript>opt</subscript> statement-list<subscript>opt</subscript> }</emphasis>
2676 </literallayout>
2677 <literallayout>
2678 <emphasis>declaration-list:
2679 declaration
2680 declaration declaration-list</emphasis>
2681 </literallayout>
2682 <literallayout>
2683 <emphasis>statement-list:
2684 statement
2685 statement statement-list</emphasis>
2686 </literallayout>
2687 </para><para>
2688 If any of the identifiers
2689 in the declaration-list were previously declared,
2690 the outer declaration is pushed down for the duration of the block,
2691 after which it resumes its force.
2692 </para><para>
2693 Any initializations of
2694 <literal>auto</literal>
2695 or
2696 <literal>register</literal>
2697 variables are performed each time the block is entered at the top.
2698 It is currently possible
2699 (but a bad practice)
2700 to transfer into a block;
2701 in that case the initializations are not performed.
2702 Initializations of
2703 <literal>static</literal>
2704 variables are performed only once when the program
2705 begins execution.
2706 Inside a block,
2707 <literal>extern</literal>
2708 declarations do not reserve storage
2709 so initialization is not permitted.
2710 </para></sect2>
2711 <sect2><title>Conditional Statement</title>
2712 <para>
2713 The two forms of the conditional statement are
2714 <literallayout>
2715 <literal>if</literal> ( <emphasis>expression</emphasis> ) <emphasis>statement</emphasis>
2716 <literal>if</literal> ( <emphasis>expression</emphasis> ) <emphasis>statement</emphasis> <literal>else</literal> <emphasis>statement</emphasis>
2717 </literallayout>
2718 </para><para>
2719 In both cases, the expression is evaluated;
2720 and if it is nonzero, the first substatement
2721 is executed.
2722 In the second case, the second substatement is executed
2723 if the expression is 0.
2724 The <quote>else</quote> ambiguity is resolved by connecting
2725 an
2726 <literal>
2727 else
2728 </literal>
2729 with the last encountered
2730 <literal>else</literal>-less
2731 <literal>
2732 if</literal>.
2733 </para></sect2>
2734 <sect2><title>While Statement</title>
2735 <para>
2736 The
2737 <literal>
2738 while
2739 </literal>
2740 statement has the form
2741 <literallayout>
2742 <literal>while</literal> ( <emphasis>expression</emphasis> ) <emphasis>statement</emphasis>
2743 </literallayout>
2744 </para><para>
2745 The substatement is executed repeatedly
2746 so long as the value of the
2747 expression remains nonzero.
2748 The test takes place before each execution of the
2749 statement.
2750 </para></sect2>
2751 <sect2><title>Do Statement</title>
2752 <para>
2753 The
2754 <literal>
2755 do
2756 </literal>
2757 statement has the form
2758 <literallayout>
2759 <literal>do</literal> <emphasis>statement</emphasis> <literal>while</literal> ( <emphasis>expression </emphasis>) ;
2760 </literallayout>
2761 </para><para>
2762 The substatement is executed repeatedly until
2763 the value of the expression becomes 0.
2764 The test takes place after each execution of the
2765 statement.
2766 </para></sect2>
2767 <sect2><title>For Statement</title>
2768 <para>
2769 The
2770 <literal>
2771 for
2772 </literal>
2773 statement has the form:
2774 <literallayout>
2775 <literal>for</literal><emphasis> ( exp-1<subscript>opt</subscript> ; exp-2<subscript>opt</subscript> ; exp-3<subscript>opt</subscript> ) statement</emphasis>
2776 </literallayout>
2777 </para><para>
2778 Except for the behavior of <literal>continue</literal>,
2779 this statement is equivalent to
2780 <literallayout>
2781 <emphasis>exp-1 </emphasis>;
2782 <literal>while</literal> ( <emphasis>exp-2\ ) </emphasis>
2783 {
2784 <emphasis>statement
2785 exp-3 ;</emphasis>
2786 }
2787 </literallayout>
2788 </para><para>
2789 Thus the first expression specifies initialization
2790 for the loop; the second specifies
2791 a test, made before each iteration, such
2792 that the loop is exited when the expression becomes
2793 0.
2794 The third expression often specifies an incrementing
2795 that is performed after each iteration.
2796 </para><para>
2797 Any or all of the expressions may be dropped.
2798 A missing
2799 <emphasis>
2800 exp-2
2801 </emphasis>
2802 makes the
2803 implied
2804 <literal>
2805 while
2806 </literal>
2807 clause equivalent to
2808 <literal>while(1)</literal>;
2809 other missing expressions are simply
2810 dropped from the expansion above.
2811 </para></sect2>
2812 <sect2><title>Switch Statement</title>
2813 <para>
2814 The
2815 <literal>
2816 switch
2817 </literal>
2818 statement causes control to be transferred
2819 to one of several statements depending on
2820 the value of an expression.
2821 It has the form
2822 <literallayout>
2823 <literal>switch</literal> ( <emphasis>expression</emphasis> ) <emphasis>statement</emphasis>
2824 </literallayout>
2825 </para><para>
2826 The usual arithmetic conversion is performed on the
2827 expression, but the result must be
2828 <literal>int</literal>.
2829 The statement is typically compound.
2830 Any statement within the statement
2831 may be labeled with one or more case prefixes
2832 as follows:
2833 <literallayout>
2834 <literal>case</literal> <emphasis>constant-expression </emphasis>:
2835 </literallayout>
2836 where the constant
2837 expression
2838 must be
2839 <literal>int</literal>.
2840 No two of the case constants in the same switch
2841 may have the same value.
2842 Constant expressions are precisely defined in <quote>CONSTANT EXPRESSIONS.</quote>
2843 </para><para>
2844 There may also be at most one statement prefix of the
2845 form
2846 <literallayout>
2847 <literal>default :</literal>
2848 </literallayout>
2849 </para><para>
2850 When the
2851 <literal>
2852 switch
2853 </literal>
2854 statement is executed, its expression
2855 is evaluated and compared with each case constant.
2856 If one of the case constants is
2857 equal to the value of the expression,
2858 control is passed to the statement
2859 following the matched case prefix.
2860 If no case constant matches the expression
2861 and if there is a
2862 <literal>default</literal>,
2863 prefix, control
2864 passes to the prefixed
2865 statement.
2866 If no case matches and if there is no
2867 <literal>default</literal>,
2868 then
2869 none of the statements in the
2870 switch is executed.
2871 </para><para>
2872 The prefixes
2873 <literal>
2874 case
2875 </literal>
2876 and
2877 <literal>
2878 default
2879 </literal>
2880 do not alter the flow of control,
2881 which continues unimpeded across such prefixes.
2882 To exit from a switch, see
2883 <quote>Break Statement.</quote>
2884 </para><para>
2885 Usually, the statement that is the subject of a switch is compound.
2886 Declarations may appear at the head of this
2887 statement,
2888 but
2889 initializations of automatic or register variables
2890 are ineffective.
2891 </para></sect2>
2892 <sect2><title>Break Statement</title>
2893 <para>
2894 The statement
2895 <literallayout>
2896 <literal>break ;</literal>
2897 </literallayout>
2898 causes termination of the smallest enclosing
2899 <literal>while</literal>,
2900 <literal>do</literal>,
2901 <literal>for</literal>,
2902 or
2903 <literal>switch</literal>
2904 statement;
2905 control passes to the
2906 statement following the terminated statement.
2907 </para></sect2>
2908 <sect2><title>Continue Statement</title>
2909 <para>
2910 The statement
2911 <literallayout>
2912 <literal>continue ;</literal>
2913 </literallayout>
2914 causes control to pass to the loop-continuation portion of the
2915 smallest enclosing
2916 <literal>while</literal>,
2917 <literal>do</literal>,
2918 or
2919 <literal>for</literal>
2920 statement; that is to the end of the loop.
2921 More precisely, in each of the statements
2922 <informaltable frame="none">
2923 <tgroup cols="3">
2924 <colspec colwidth="2in"/>
2925 <colspec colwidth="2in"/>
2926 <colspec colwidth="2in"/>
2927 <tbody>
2928 <row>
2929 <entry>while (...) {</entry>
2930 <entry>do {</entry>
2931 <entry>for (...) {</entry>
2932 </row>
2933 <row>
2934 <entry>statement ;</entry>
2935 <entry>statement ;</entry>
2936 <entry>statement ;</entry>
2937 </row>
2938 <row>
2939 <entry>contin: ;</entry>
2940 <entry> contin: ;</entry>
2941 <entry> contin: ;</entry>
2942 </row>
2943 <row>
2944 <entry>}</entry>
2945 <entry>} while (...);</entry>
2946 <entry>}</entry>
2947 </row>
2948 </tbody>
2949 </tgroup>
2950 </informaltable>
2951 a
2952 <literal>
2953 continue
2954 </literal>
2955 is equivalent to
2956 <literal>
2957 goto\ contin</literal>.
2958 (Following the
2959 <literal>
2960 contin:
2961 </literal>
2962 is a null statement, see <quote>Null Statement</quote>.)
2963 </para></sect2>
2964 <sect2><title>Return Statement</title>
2965 <para>
2966 A function returns to its caller by means of
2967 the
2968 <literal>
2969 return
2970 </literal>
2971 statement which has one of the
2972 forms
2973 <literallayout>
2974 <literal>return ;
2975 return </literal><emphasis>expression </emphasis>;
2976 </literallayout>
2977 </para><para>
2978 In the first case, the returned value is undefined.
2979 In the second case, the value of the expression
2980 is returned to the caller
2981 of the function.
2982 If required, the expression is converted,
2983 as if by assignment, to the type of
2984 function in which it appears.
2985 Flowing off the end of a function is
2986 equivalent to a return with no returned value.
2987 The expression may be parenthesized.
2988 </para></sect2>
2989 <sect2><title>Goto Statement</title>
2990 <para>
2991 Control may be transferred unconditionally by means of
2992 the statement
2993 <literallayout>
2994 <literal>goto</literal> <emphasis>identifier </emphasis>;
2995 </literallayout>
2996 </para><para>
2997 The identifier must be a label
2998 (see <quote>Labeled Statement</quote>)
2999 located in the current function.
3000 </para></sect2>
3001 <sect2><title>Labeled Statement</title>
3002 <para>
3003 Any statement may be preceded by
3004 label prefixes of the form
3005 <literallayout>
3006 <emphasis>identifier </emphasis>:
3007 </literallayout>
3008 which serve to declare the identifier
3009 as a label.
3010 The only use of a label is as a target of a
3011 <literal>
3012 goto</literal>.
3013 The scope of a label is the current function,
3014 excluding any subblocks in which the same identifier has been redeclared.
3015 See <quote>SCOPE RULES.</quote>
3016 </para></sect2>
3017 <sect2><title>Null Statement</title>
3018 <para>
3019 The null statement has the form
3020 <literallayout>
3021 <literal>;</literal>
3022 </literallayout>
3023 </para><para>
3024 A null statement is useful to carry a label just before the
3025 <literal>
3026 }
3027 </literal>
3028 of a compound statement or to supply a null
3029 body to a looping statement such as
3030 <literal>
3031 while</literal>.
3032 </para></sect2></sect1>
3033 <sect1><title>
3034 External Definitions
3035 </title><para>
3036 A C program consists of a sequence of external definitions.
3037 An external definition declares an identifier to
3038 have storage class
3039 <literal>extern</literal>
3040 (by default)
3041 or perhaps
3042 <literal>static</literal>,
3043 and
3044 a specified type.
3045 The type-specifier (see <quote>Type Specifiers</quote> in
3046 <quote>DECLARATIONS</quote>) may also be empty, in which
3047 case the type is taken to be
3048 <literal>int</literal>.
3049 The scope of external definitions persists to the end
3050 of the file in which they are declared just as the effect
3051 of declarations persists to the end of a block.
3052 The syntax of external definitions is the same
3053 as that of all declarations except that
3054 only at this level may the code for functions be given.
3055 </para>
3056 <sect2><title>External Function Definitions</title>
3057 <para>
3058 Function definitions have the form
3059 <literallayout>
3060 <emphasis>function-definition:
3061 decl-specifiers<subscript>opt</subscript> function-declarator function-body</emphasis>
3062 </literallayout>
3063 </para><para>
3064 The only sc-specifiers
3065 allowed
3066 among the decl-specifiers
3067 are
3068 <literal>extern</literal>
3069 or
3070 <literal>static</literal>;
3071 see <quote>Scope of Externals</quote> in
3072 <quote>SCOPE RULES</quote> for the distinction between them.
3073 A function declarator is similar to a declarator
3074 for a <quote>function returning ...</quote> except that
3075 it lists the formal parameters of
3076 the function being defined.
3077 <literallayout>
3078 <emphasis>function-declarator:
3079 declarator ( parameter-list<subscript>opt</subscript> )</emphasis>
3080 </literallayout>
3081 <literallayout>
3082 <emphasis>parameter-list:
3083 identifier
3084 identifier , parameter-list</emphasis>
3085 </literallayout>
3086 </para><para>
3087 The function-body
3088 has the form
3089 <literallayout>
3090 <emphasis>function-body:
3091 declaration-list<subscript>opt</subscript> compound-statement</emphasis>
3092 </literallayout>
3093 </para><para>
3094 The identifiers in the parameter list, and only those identifiers,
3095 may be declared in the declaration list.
3096 Any identifiers whose type is not given are taken to be
3097 <literal>int</literal>.
3098 The only storage class which may be specified is
3099 <literal>register</literal>;
3100 if it is specified, the corresponding actual parameter
3101 will be copied, if possible, into a register
3102 at the outset of the function.
3103 </para><para>
3104 A simple example of a complete function definition is
3105 <literallayout>
3106 <literal>int max(a, b, c)
3107 int a, b, c;
3108 {
3109 int m;
3110
3111 m = (a > b) ? a : b;
3112 return((m > c) ? m : c);
3113 }</literal>
3114 </literallayout>
3115 </para><para>
3116 Here
3117 <literal>int</literal>
3118 is the type-specifier;
3119 <literal>
3120 max(a, b, c)
3121 </literal>
3122 is the function-declarator;
3123 <literal>
3124 int a, b, c;
3125 </literal>
3126 is the declaration-list for
3127 the formal
3128 parameters;
3129 <literal>{ ... }</literal>
3130 is the
3131 block giving the code for the statement.
3132 </para><para>
3133 The C program converts all
3134 <literal>float</literal>
3135 actual parameters
3136 to
3137 <literal>double</literal>,
3138 so formal parameters declared
3139 <literal>float</literal>
3140 have their declaration adjusted to read
3141 <literal>double</literal>.
3142 All <literal>char</literal> and <literal>short</literal> formal parameter
3143 declarations are similarly adjusted
3144 to read <literal>int</literal>.
3145 Also, since a reference to an array in any context
3146 (in particular as an actual parameter)
3147 is taken to mean
3148 a pointer to the first element of the array,
3149 declarations of formal parameters declared <quote>array of ...</quote>
3150 are adjusted to read <quote>pointer to ....</quote>
3151 </para></sect2>
3152 <sect2><title>External Data Definitions</title>
3153 <para>
3154 An external data definition has the form
3155 <literallayout>
3156 <emphasis>data-definition:
3157 declaration</emphasis>
3158 </literallayout>
3159 </para><para>
3160 The storage class of such data may be
3161 <literal>extern</literal>
3162 (which is the default)
3163 or
3164 <literal>static</literal>
3165 but not
3166 <literal>auto</literal>
3167 or
3168 <literal>register</literal>.
3169 </para></sect2></sect1>
3170 <sect1><title>
3171 Scope Rules
3172 </title><para>
3173 A C program need not all
3174 be compiled at the same time. The source text of the
3175 program
3176 may be kept in several files, and precompiled
3177 routines may be loaded from
3178 libraries.
3179 Communication among the functions of a program
3180 may be carried out both through explicit calls
3181 and through manipulation of external data.
3182 </para><para>
3183 Therefore, there are two kinds of scopes to consider:
3184 first, what may be called the
3185 <emphasis>lexical scope</emphasis>
3186 of an identifier, which is essentially the
3187 region of a program during which it may
3188 be used without drawing <quote>undefined identifier</quote>
3189 diagnostics;
3190 and second, the scope
3191 associated with external identifiers,
3192 which is characterized by the rule
3193 that references to the same external
3194 identifier are references to the same object.
3195 </para>
3196 <sect2><title>Lexical Scope</title>
3197 <para>
3198 The lexical scope of identifiers declared in external definitions
3199 persists from the definition through
3200 the end of the source file
3201 in which they appear.
3202 The lexical scope of identifiers which are formal parameters
3203 persists through the function with which they are
3204 associated.
3205 The lexical scope of identifiers declared at the head of a block
3206 persists until the end of the block.
3207 The lexical scope of labels is the whole of the
3208 function in which they appear.
3209 </para><para>
3210 In all cases, however,
3211 if an identifier is explicitly declared at the head of a block,
3212 including the block constituting a function,
3213 any declaration of that identifier outside the block
3214 is suspended until the end of the block.
3215 </para><para>
3216 Remember also (see <quote>Structure, Union, and Enumeration Declarations</quote> in
3217 <quote>DECLARATIONS</quote>) that tags, identifiers associated with
3218 ordinary variables,
3219 and identities associated with structure and union members
3220 form three disjoint classes
3221 which do not conflict.
3222 Members and tags follow the same scope rules
3223 as other identifiers.
3224 The <literal>enum</literal> constants are in the same
3225 class as ordinary variables and follow the same scope rules.
3226 The
3227 <literal>typedef</literal>
3228 names are in the same class as ordinary identifiers.
3229 They may be redeclared in inner blocks, but an explicit
3230 type must be given in the inner declaration:
3231 <programlisting>
3232 typedef float distance;
3233 ...
3234 {
3235 auto int distance;
3236 ...
3237 }
3238 </programlisting>
3239 </para><para>
3240 The
3241 <literal>int</literal>
3242 must be present in the second declaration,
3243 or it would be taken to be
3244 a declaration with no declarators and type
3245 <literal>
3246 distance</literal>.
3247 </para></sect2>
3248 <sect2><title>Scope of Externals</title>
3249 <para>
3250 If a function refers to an identifier declared to be
3251 <literal>extern</literal>,
3252 then somewhere among the files or libraries
3253 constituting the complete program
3254 there must be at least one external definition
3255 for the identifier.
3256 All functions in a given program which refer to the same
3257 external identifier refer to the same object,
3258 so care must be taken that the type and size
3259 specified in the definition
3260 are compatible with those specified
3261 by each function which references the data.
3262 </para><para>
3263 It is illegal to explicitly initialize any external
3264 identifier more than once in the set of files and libraries
3265 comprising a multi-file program.
3266 It is legal to have more than one data definition
3267 for any external non-function identifier;
3268 explicit use of <literal>extern</literal> does not
3269 change the meaning of an external declaration.
3270 </para><para>
3271 In restricted environments, the use of the <literal>extern</literal>
3272 storage class takes on an additional meaning.
3273 In these environments, the explicit appearance of the
3274 <literal>extern</literal> keyword in external data declarations of
3275 identities without initialization indicates that
3276 the storage for the identifiers is allocated elsewhere,
3277 either in this file or another file.
3278 It is required that there be exactly one definition of
3279 each external identifier (without <literal>extern</literal>)
3280 in the set of files and libraries
3281 comprising a mult-file program.
3282 </para><para>
3283 Identifiers declared
3284 <literal>static</literal>
3285 at the top level in external definitions
3286 are not visible in other files.
3287 Functions may be declared
3288 <literal>static</literal>.
3289 </para></sect2></sect1>
3290 <sect1><title>
3291 Compiler Control Lines
3292 </title><para>
3293 The C compiler contains a preprocessor capable
3294 of macro substitution, conditional compilation,
3295 and inclusion of named files.
3296 Lines beginning with
3297 <literal>
3298 #
3299 </literal>
3300 communicate
3301 with this preprocessor.
3302 There may be any number of blanks and horizontal tabs
3303 between the <literal>#</literal> and the directive.
3304 These lines have syntax independent of the rest of the language;
3305 they may appear anywhere and have effect which lasts (independent of
3306 scope) until the end of the source program file.
3307 </para>
3308 <sect2><title>Token Replacement</title>
3309 <para>
3310 A compiler-control line of the form
3311 <literallayout>
3312 <literal>#define</literal> <emphasis>identifier token-string<subscript>opt</subscript></emphasis>
3313 </literallayout>
3314 causes the preprocessor to replace subsequent instances
3315 of the identifier with the given string of tokens.
3316 Semicolons in or at the end of the token-string are part of that string.
3317 A line of the form
3318 <literallayout>
3319 <literal>#define</literal> <emphasis>identifier(identifier, ... )token-string<subscript>opt</subscript></emphasis>
3320 </literallayout>
3321 where there is no space between the first identifier
3322 and the
3323 <literal>(</literal>,
3324 is a macro definition with arguments.
3325 There may be zero or more formal parameters.
3326 Subsequent instances of the first identifier followed
3327 by a
3328 <literal>(</literal>,
3329 a sequence of tokens delimited by commas, and a
3330 <literal>)</literal>
3331 are replaced
3332 by the token string in the definition.
3333 Each occurrence of an identifier mentioned in the formal parameter list
3334 of the definition is replaced by the corresponding token string from the call.
3335 The actual arguments in the call are token strings separated by commas;
3336 however, commas in quoted strings or protected by
3337 parentheses do not separate arguments.
3338 The number of formal and actual parameters must be the same.
3339 Strings and character constants in the token-string are scanned
3340 for formal parameters, but
3341 strings and character constants in the rest of the program are
3342 not scanned for defined identifiers
3343 to replacement.
3344 </para><para>
3345 In both forms the replacement string is rescanned for more
3346 defined identifiers.
3347 In both forms
3348 a long definition may be continued on another line
3349 by writing
3350 <literal>
3351 \
3352 </literal>
3353 at the end of the line to be continued.
3354 </para><para>
3355 This facility is most valuable for definition of <quote>manifest constants,</quote>
3356 as in
3357 <screen>
3358 #define TABSIZE 100
3359
3360 int table[TABSIZE];
3361 </screen>
3362 </para><para>
3363 A control line of the form
3364 <literallayout>
3365 <literal>#undef</literal> <emphasis>identifier</emphasis>
3366 </literallayout>
3367 causes the
3368 identifier's preprocessor definition (if any) to be forgotten.
3369 </para><para>
3370 If a <literal>#define</literal>d identifier is the subject of a subsequent
3371 <literal>#define</literal> with no intervening <literal>#undef</literal>, then
3372 the two token-strings are compared textually.
3373 If the two token-strings are not identical
3374 (all white space is considered as equivalent), then
3375 the identifier is considered to be redefined.
3376 </para></sect2>
3377 <sect2><title>File Inclusion</title>
3378 <para>
3379 A compiler control line of
3380 the form
3381 <literallayout>
3382 <literal>#include</literal><emphasis> &quot;filename</emphasis>&quot;
3383 </literallayout>
3384 causes the replacement of that
3385 line by the entire contents of the file
3386 <emphasis>
3387 filename</emphasis>.
3388 The named file is searched for first in the directory
3389 of the file containing the <literal>#include</literal>,
3390 and then in a sequence of specified or standard places.
3391 Alternatively, a control line of the form
3392 <literallayout>
3393 <literal>#include</literal><emphasis> &lt;filename</emphasis>>
3394 </literallayout>
3395 searches only the specified or standard places
3396 and not the directory of the <literal>#include</literal>.
3397 (How the places are specified is not part of the language.)
3398 </para><para>
3399 <literal>#include</literal>s
3400 may be nested.
3401 </para></sect2>
3402 <sect2><title>Conditional Compilation</title>
3403 <para>
3404 A compiler control line of the form
3405 <literallayout>
3406 <literal>#if</literal> <emphasis>constant-expression</emphasis>
3407 </literallayout>
3408 checks whether the constant expression evaluates to nonzero.
3409 (Constant expressions are discussed in <quote>CONSTANT EXPRESSIONS</quote>.
3410 A control line of the form
3411 <literallayout>
3412 <literal>#ifdef </literal><emphasis>identifier</emphasis>
3413 </literallayout>
3414 checks whether the identifier is currently defined
3415 in the preprocessor; i.e., whether it has been the
3416 subject of a
3417 <literal>
3418 #define
3419 </literal>
3420 control line.
3421 It is equivalent to <literal>#ifdef(</literal><emphasis>identifier</emphasis><literal>)</literal>.
3422 A control line of the form
3423 <literallayout>
3424 <literal>#ifndef </literal><emphasis>identifier</emphasis>
3425 </literallayout>
3426 checks whether the identifier is currently undefined
3427 in the preprocessor.
3428 It is equivalent to
3429 <literallayout>
3430 <literal>#if !defined(</literal><emphasis>identifier</emphasis><literal>)</literal>.
3431 </literallayout>
3432 </para><para>
3433 All three forms are followed by an arbitrary number of lines,
3434 possibly containing a control line
3435 <literallayout>
3436 <literal>#else</literal>
3437 </literallayout>
3438 and then by a control line
3439 <literallayout>
3440 <literal>#endif</literal>
3441 </literallayout>
3442 </para><para>
3443 If the checked condition is true,
3444 then any lines
3445 between
3446 <literal>
3447 #else
3448 </literal>
3449 and
3450 <literal>
3451 #endif
3452 </literal>
3453 are ignored.
3454 If the checked condition is false, then any lines between
3455 the test and a
3456 <literal>
3457 #else
3458 </literal>
3459 or, lacking a
3460 <literal>#else</literal>,
3461 the
3462 <literal>
3463 #endif
3464 </literal>
3465 are ignored.
3466 </para><para>
3467 These constructions may be nested.
3468 </para></sect2>
3469 <sect2><title>Line Control</title>
3470 <para>
3471 For the benefit of other preprocessors which generate C programs,
3472 a line of the form
3473 <literallayout>
3474 <literal>#line </literal><emphasis>constant identifier</emphasis>
3475 </literallayout>
3476 causes the compiler to believe, for purposes of error
3477 diagnostics,
3478 that the line number of the next source line is given by the constant and the current input
3479 file is named by the identifier.
3480 If the identifier is absent, the remembered file name does not change.
3481 </para></sect2></sect1>
3482 <sect1><title>
3483 Implicit Declarations
3484 </title><para>
3485 It is not always necessary to specify
3486 both the storage class and the type
3487 of identifiers in a declaration.
3488 The storage class is supplied by
3489 the context in external definitions
3490 and in declarations of formal parameters
3491 and structure members.
3492 In a declaration inside a function,
3493 if a storage class but no type
3494 is given, the identifier is assumed
3495 to be
3496 <literal>int</literal>;
3497 if a type but no storage class is indicated,
3498 the identifier is assumed to
3499 be
3500 <literal>auto</literal>.
3501 An exception to the latter rule is made for
3502 functions because
3503 <literal>auto</literal>
3504 functions do not exist.
3505 If the type of an identifier is <quote>function returning ...,</quote>
3506 it is implicitly declared to be
3507 <literal>extern</literal>.
3508 </para><para>
3509 In an expression, an identifier
3510 followed by
3511 <literal>
3512 (
3513 </literal>
3514 and not already declared
3515 is contextually
3516 declared to be <quote>function returning
3517 <literal>int</literal>.</quote>
3518 </para></sect1>
3519 <sect1><title>
3520 Types Revisited
3521 </title><para>
3522 This part summarizes the operations
3523 which can be performed on objects of certain types.
3524 </para>
3525 <sect2><title>Structures and Unions</title>
3526 <para>
3527 Structures and unions may be assigned, passed as arguments to functions,
3528 and returned by functions.
3529 Other plausible operators, such as equality comparison
3530 and structure casts,
3531 are not implemented.
3532 </para><para>
3533 In a reference
3534 to a structure or union member, the
3535 name on the right
3536 of the <literal>-></literal> or the <literal>.</literal>
3537 must specify a member of the aggregate
3538 named or pointed to by the expression
3539 on the left.
3540 In general, a member of a union may not be inspected
3541 unless the value of the union has been assigned using that same member.
3542 However, one special guarantee is made by the language in order
3543 to simplify the use of unions:
3544 if a union contains several structures that share a common initial sequence
3545 and if the union currently contains one of these structures,
3546 it is permitted to inspect the common initial part of any of
3547 the contained structures.
3548 </para></sect2>
3549 <sect2><title>Functions</title>
3550 <para>
3551 There are only two things that
3552 can be done with a function <literal>m</literal>,
3553 call it or take its address.
3554 If the name of a function appears in an
3555 expression not in the function-name position of a call,
3556 a pointer to the function is generated.
3557 Thus, to pass one function to another, one
3558 might say
3559 <programlisting>
3560 int f();
3561 ...
3562 g(f);
3563 </programlisting>
3564 </para><para>
3565 Then the definition of
3566 <literal>
3567 g
3568 </literal>
3569 might read
3570 <programlisting>
3571 g(funcp)
3572 int (*funcp)();
3573 {
3574 ...
3575 (*funcp)();
3576 ...
3577 }
3578 </programlisting>
3579 </para><para>
3580 Notice that
3581 <literal>
3582 f
3583 </literal>
3584 must be declared
3585 explicitly in the calling routine since its appearance
3586 in
3587 <literal>
3588 g(f)
3589 </literal>
3590 was not followed by
3591 <literal>
3592 (.
3593 </literal>
3594 </para></sect2>
3595 <sect2><title>Arrays, Pointers, and Subscripting</title>
3596 <para>
3597 Every time an identifier of array type appears
3598 in an expression, it is converted into a pointer
3599 to the first member of the array.
3600 Because of this conversion, arrays are not
3601 lvalues.
3602 By definition, the subscript operator
3603 <literal>[]</literal>
3604 is interpreted
3605 in such a way that
3606 <literal>E1[E2]</literal>
3607 is identical to
3608 <literal>*((E1)+E2))</literal>.
3609 Because of the conversion rules
3610 which apply to
3611 <literal>+</literal>,
3612 if
3613 <literal>E1</literal>
3614 is an array and
3615 <literal>E2</literal>
3616 an integer, then
3617 <literal>E1[E2]</literal>
3618 refers to the
3619 <literal>E2-th</literal>
3620 member of
3621 <literal>E1</literal>.
3622 Therefore,
3623 despite its asymmetric
3624 appearance, subscripting is a commutative operation.
3625 </para><para>
3626 A consistent rule is followed in the case of
3627 multidimensional arrays.
3628 If
3629 <literal>E</literal>
3630 is an
3631 <emphasis>n</emphasis>-dimensional
3632 array
3633 of rank
3634 i&times;j&times;...&times;k,
3635 then
3636 <literal>
3637 E
3638 </literal>
3639 appearing in an expression is converted to
3640 a pointer to an (n-1)-dimensional
3641 array with rank
3642 j&times;...&times;k.
3643 If the
3644 <literal>
3645 *
3646 </literal>
3647 operator, either explicitly
3648 or implicitly as a result of subscripting,
3649 is applied to this pointer,
3650 the result is the pointed-to (n-1)-dimensional array,
3651 which itself is immediately converted into a pointer.
3652 </para><para>
3653 For example, consider
3654 <literallayout>
3655 <literal>int x[3][5];</literal>
3656 </literallayout>
3657 </para><para>
3658 Here
3659 <literal>
3660 x
3661 </literal>
3662 is a 3&times;5 array of integers.
3663 When
3664 <literal>
3665 x
3666 </literal>
3667 appears in an expression, it is converted
3668 to a pointer to (the first of three) 5-membered arrays of integers.
3669 In the expression
3670 <literal>x[i]</literal>,
3671 which is equivalent to
3672 <literal>*(x+i)</literal>,
3673 <literal>
3674 x
3675 </literal>
3676 is first converted to a pointer as described;
3677 then
3678 <literal>
3679 i
3680 </literal>
3681 is converted to the type of
3682 <literal>x</literal>,
3683 which involves multiplying
3684 <literal>
3685 i
3686 </literal>
3687 by the
3688 length the object to which the pointer points,
3689 namely 5-integer objects.
3690 The results are added and indirection applied to
3691 yield an array (of five integers) which in turn is converted to
3692 a pointer to the first of the integers.
3693 If there is another subscript, the same argument applies
3694 again; this time the result is an integer.
3695 </para><para>
3696 Arrays in C are stored
3697 row-wise (last subscript varies fastest)
3698 and the first subscript in the declaration helps determine
3699 the amount of storage consumed by an array.
3700 Arrays play no other part in subscript calculations.
3701 </para></sect2>
3702 <sect2><title>Explicit Pointer Conversions</title>
3703 <para>
3704 Certain conversions involving pointers are permitted
3705 but have implementation-dependent aspects.
3706 They are all specified by means of an explicit type-conversion
3707 operator, see <quote>Unary Operators</quote> under<quote>EXPRESSIONS</quote> and
3708 <quote>Type Names</quote>under <quote>DECLARATIONS.</quote>
3709 </para><para>
3710 A pointer may be converted to any of the integral types large
3711 enough to hold it.
3712 Whether an
3713 <literal>int</literal>
3714 or
3715 <literal>long</literal>
3716 is required is machine dependent.
3717 The mapping function is also machine dependent but is intended
3718 to be unsurprising to those who know the addressing structure
3719 of the machine.
3720 Details for some particular machines are given below.
3721 </para><para>
3722 An object of integral type may be explicitly converted to a pointer.
3723 The mapping always carries an integer converted from a pointer back to the same pointer
3724 but is otherwise machine dependent.
3725 </para><para>
3726 A pointer to one type may be converted to a pointer to another type.
3727 The resulting pointer may cause addressing exceptions
3728 upon use if
3729 the subject pointer does not refer to an object suitably aligned in storage.
3730 It is guaranteed that
3731 a pointer to an object of a given size may be converted to a pointer to an object
3732 of a smaller size
3733 and back again without change.
3734 </para><para>
3735 For example,
3736 a storage-allocation routine
3737 might accept a size (in bytes)
3738 of an object to allocate, and return a
3739 <literal>char</literal>
3740 pointer;
3741 it might be used in this way.
3742 <programlisting>
3743 extern char *alloc();
3744 double *dp;
3745
3746 dp = (double *) alloc(sizeof(double));
3747 *dp = 22.0 / 7.0;
3748 </programlisting>
3749 </para><para>
3750 The
3751 <function>alloc</function>
3752 must ensure (in a machine-dependent way)
3753 that its return value is suitable for conversion to a pointer to
3754 <literal>double</literal>;
3755 then the
3756 <emphasis>
3757 use
3758 </emphasis>
3759 of the function is portable.
3760 </para><para>
3761 The pointer
3762 representation on the
3763 PDP-11
3764 corresponds to a 16-bit integer and
3765 measures bytes.
3766 The
3767 <literal>char</literal>'s
3768 have no alignment requirements; everything else must have an even address.
3769 </para><para>
3770 On the
3771 VAX-11,
3772 pointers are 32 bits long and measure bytes.
3773 Elementary objects are aligned on a boundary equal to their
3774 length, except that
3775 <literal>double</literal>
3776 quantities need be aligned only on even 4-byte boundaries.
3777 Aggregates are aligned on the strictest boundary required by
3778 any of their constituents.
3779 </para><para>
3780 The 3B 20 computer has 24-bit pointers placed into 32-bit quantities.
3781 Most objects are
3782 aligned on 4-byte boundaries. <literal>short</literal>s are aligned in all cases on
3783 2-byte boundaries. Arrays of characters, all structures,
3784 <literal>int</literal>s, <literal>long</literal>s, <literal>float</literal>s, and <literal>double</literal>s are aligned on 4-byte
3785 boundries; but structure members may be packed tighter.
3786 </para></sect2>
3787 <sect2><title>CONSTANT EXPRESSIONS</title>
3788 <para>
3789 In several places C requires expressions that evaluate to
3790 a constant:
3791 after
3792 <literal>case</literal>,
3793 as array bounds, and in initializers.
3794 In the first two cases, the expression can
3795 involve only integer constants, character constants,
3796 casts to integral types,
3797 enumeration constants,
3798 and
3799 <literal>
3800 sizeof
3801 </literal>
3802 expressions, possibly
3803 connected by the binary operators
3804 <literallayout>
3805 + - * / % &amp; | ^ &lt;&lt; >> == != &lt; > &lt;= >= &amp;&amp; ||
3806 </literallayout>
3807 or by the unary operators
3808 <literallayout>
3809 - ~
3810 </literallayout>
3811 or by the ternary operator
3812 <literallayout>
3813 ?:
3814 </literallayout>
3815 </para><para>
3816 Parentheses can be used for grouping
3817 but not for function calls.
3818 </para><para>
3819 More latitude is permitted for initializers;
3820 besides constant expressions as discussed above,
3821 one can also use floating constants
3822 and arbitrary casts and
3823 can also apply the unary
3824 <literal>
3825 &amp;
3826 </literal>
3827 operator to external or static objects
3828 and to external or static arrays subscripted
3829 with a constant expression.
3830 The unary
3831 <literal>
3832 &amp;
3833 </literal>
3834 can also
3835 be applied implicitly
3836 by appearance of unsubscripted arrays and functions.
3837 The basic rule is that initializers must
3838 evaluate either to a constant or to the address
3839 of a previously declared external or static object plus or minus a constant.
3840 </para></sect2></sect1>
3841 <sect1><title>
3842 Portability Considerations
3843 </title><para>
3844 Certain parts of C are inherently machine dependent.
3845 The following list of potential trouble spots
3846 is not meant to be all-inclusive
3847 but to point out the main ones.
3848 </para><para>
3849 Purely hardware issues like
3850 word size and the properties of floating point arithmetic and integer division
3851 have proven in practice to be not much of a problem.
3852 Other facets of the hardware are reflected
3853 in differing implementations.
3854 Some of these,
3855 particularly sign extension
3856 (converting a negative character into a negative integer)
3857 and the order in which bytes are placed in a word,
3858 are nuisances that must be carefully watched.
3859 Most of the others are only minor problems.
3860 </para><para>
3861 The number of
3862 <literal>register</literal>
3863 variables that can actually be placed in registers
3864 varies from machine to machine
3865 as does the set of valid types.
3866 Nonetheless, the compilers all do things properly for their own machine;
3867 excess or invalid
3868 <literal>register</literal>
3869 declarations are ignored.
3870 </para><para>
3871 Some difficulties arise only when
3872 dubious coding practices are used.
3873 It is exceedingly unwise to write programs
3874 that depend
3875 on any of these properties.
3876 </para><para>
3877 The order of evaluation of function arguments
3878 is not specified by the language.
3879 The order in which side effects take place
3880 is also unspecified.
3881 </para><para>
3882 Since character constants are really objects of type
3883 <literal>int</literal>,
3884 multicharacter character constants may be permitted.
3885 The specific implementation
3886 is very machine dependent
3887 because the order in which characters
3888 are assigned to a word
3889 varies from one machine to another.
3890 </para><para>
3891 Fields are assigned to words and characters to integers right to left
3892 on some machines
3893 and left to right on other machines.
3894 These differences are invisible to isolated programs
3895 that do not indulge in type punning (e.g.,
3896 by converting an
3897 <literal>int</literal>
3898 pointer to a
3899 <literal>char</literal>
3900 pointer and inspecting the pointed-to storage)
3901 but must be accounted for when conforming to externally-imposed
3902 storage layouts.
3903 </para><para>
3904 The language accepted by the various compilers differs in minor details. Most
3905 notably, the current PDP-11 compiler will not initialize structures containing
3906 bitfields, and does not accept a few assignment operators in certain contexts where the
3907 value of the assignment is used.
3908 </para></sect1>
3909 <sect1><title>Anachronisms</title>
3910 <para>
3911 Since C is an evolving language, certain obsolete constructions may be
3912 found in older programs. Although most versions of the compiler support
3913 such anachronisms, ultimately they will disappear, leaving only a portability
3914 problem behind.
3915 </para>
3916 <para>
3917 Earlier versions of C used the form =op instead of op= for assignment
3918 operators. This leads to ambiguities, typified by:
3919 <screen>
3920 x=-1
3921 </screen>
3922 which actually decrements x since the = and the - are adjacent, but which might
3923 easily be intended to assign -1 to x.
3924 </para>
3925 <para>
3926 The syntax of initializers has changed: previously, the equals sign that introduces
3927 and initializer was not present, so instead of
3928 <screen>
3929 int x = 1;
3930 </screen>
3931 one used
3932 <screen>
3933 int x 1;
3934 </screen>
3935 The change was made because the initialization
3936 <screen>
3937 int f (1+2)
3938 </screen>
3939 resembles a function declaration closely enough to confuse the compilers.
3940 </para></sect1>
3941 <sect1><title>Syntax Summary</title>
3942 <para>
3943 This summary of C syntax is intended more for aiding comprehension
3944 than as an exact statement of the language.
3945 </para>
3946 <sect2><title>Expressions</title>
3947 <para>
3948 The basic expressions are:
3949 <literallayout>
3950 <emphasis>expression:
3951 primary
3952 * expression
3953 &amp;lvalue
3954 - expression
3955 ! expression
3956 ~ expression
3957 ++ lvalue
3958 --lvalue
3959 lvalue ++
3960 lvalue --</emphasis>
3961 <literal>sizeof</literal><emphasis> expression</emphasis>
3962 <literal>sizeof (</literal><emphasis>type-name</emphasis><literal>)</literal><emphasis>
3963 ( type-name ) expression
3964 expression binop expression
3965 expression ? expression : expression
3966 lvalue asgnop expression
3967 expression , expression</emphasis>
3968 </literallayout>
3969 <literallayout>
3970 <emphasis>primary:
3971 identifier
3972 constant
3973 string
3974 ( expression )
3975 primary ( expression-list<subscript>opt</subscript> )
3976 primary [ expression ]
3977 primary . identifier
3978 primary - identifier</emphasis>
3979 </literallayout>
3980 <literallayout>
3981 <emphasis>lvalue:
3982 identifier
3983 primary [ expression ]
3984 lvalue . identifier
3985 primary - identifier
3986 * expression
3987 ( lvalue )</emphasis>
3988 </literallayout>
3989 </para><para>
3990 The primary-expression operators
3991 <literallayout>
3992 () [] . -&lt;
3993 </literallayout>
3994 have highest priority and group left to right.
3995 The unary operators
3996 <literallayout>
3997 * &amp; - ! ~ ++ -- <literal>sizeof</literal><emphasis> ( type-name </emphasis>)
3998 </literallayout>
3999 have priority below the primary operators
4000 but higher than any binary operator
4001 and group right to left.
4002 Binary operators
4003 group left to right; they have priority
4004 decreasing
4005 as indicated below.
4006 <literallayout>
4007 <emphasis>binop:</emphasis>
4008 * / %
4009 + -
4010 >> &lt;&lt;
4011 &lt; > &lt;= >=
4012 == !=
4013 &amp;
4014 ^
4015 |
4016 &amp;&amp;
4017 ||
4018 </literallayout>
4019 The conditional operator groups right to left.
4020 </para><para>
4021 Assignment operators all have the same
4022 priority and all group right to left.
4023 <literallayout>
4024 <emphasis>asgnop:</emphasis>
4025 = += -= *= /= %= >>= &lt;&lt;= &amp;= ^= |=
4026 </literallayout>
4027 </para><para>
4028 The comma operator has the lowest priority and groups left to right.
4029 </para></sect2>
4030 <sect2><title>Declarations</title>
4031 <para>
4032 <literallayout>
4033 <emphasis>declaration:
4034 decl-specifiers init-declarator-list<subscript>opt</subscript> ;</emphasis>
4035 </literallayout>
4036 <literallayout>
4037 <emphasis>decl-specifiers:
4038 type-specifier decl-specifiers<subscript>opt</subscript>
4039 sc-specifier decl-specifiers<subscript>opt</subscript></emphasis>
4040 </literallayout>
4041 <literallayout>
4042 <emphasis>sc-specifier:</emphasis><literal>
4043 auto
4044 static
4045 extern
4046 register
4047 typedef</literal>
4048 </literallayout>
4049 <literallayout>
4050 <emphasis>type-specifier:</emphasis>
4051 <literal>char
4052 short
4053 int
4054 long
4055 unsigned
4056 float
4057 double</literal>
4058 <emphasis>struct-or-union-specifier
4059 typedef-name</emphasis>
4060 </literallayout>
4061 <literallayout>
4062 <emphasis>init-declarator-list:
4063 init-declarator
4064 init-declarator , init-declarator-list</emphasis>
4065 </literallayout>
4066 <literallayout>
4067 <emphasis>init-declarator:
4068 declarator initializer<subscript>opt</subscript></emphasis>
4069 </literallayout>
4070 <literallayout>
4071 <emphasis>declarator:
4072 identifier
4073 ( declarator )
4074 * declarator
4075 declarator ()
4076 declarator [ constant-expression<subscript>opt</subscript> ]</emphasis>
4077 </literallayout>
4078 <literallayout>
4079 <emphasis>struct-or-union-specifier:</emphasis><literal>
4080 struct</literal><emphasis> { struct-decl-list }</emphasis><literal>
4081 struct</literal> <emphasis>identifier { struct-decl-list }</emphasis><literal>
4082 struct</literal> <emphasis>identifier</emphasis><literal>
4083 union {</literal> <emphasis>struct-decl-list }</emphasis><literal>
4084 union </literal><emphasis>identifier { struct-decl-list }</emphasis><literal>
4085 union </literal><emphasis>identifier</emphasis>
4086 </literallayout>
4087 <literallayout>
4088 <emphasis>struct-decl-list:
4089 struct-declaration
4090 struct-declaration struct-decl-list</emphasis>
4091 </literallayout>
4092 <literallayout>
4093 <emphasis>struct-declaration:
4094 type-specifier struct-declarator-list ;</emphasis>
4095 </literallayout>
4096 <literallayout>
4097 <emphasis>struct-declarator-list:
4098 struct-declarator
4099 struct-declarator , struct-declarator-list</emphasis>
4100 </literallayout>
4101 <literallayout>
4102 <emphasis>struct-declarator:
4103 declarator
4104 declarator : constant-expression
4105 : constant-expression</emphasis>
4106 </literallayout>
4107 <literallayout>
4108 <emphasis>initializer:
4109 = expression
4110 = { initializer-list }
4111 = { initializer-list , }</emphasis>
4112 </literallayout>
4113 <literallayout>
4114 <emphasis>initializer-list:
4115 expression
4116 initializer-list , initializer-list
4117 { initializer-list }
4118 { initializer-list , }</emphasis>
4119 </literallayout>
4120 <literallayout>
4121 <emphasis>type-name:
4122 type-specifier abstract-declarator</emphasis>
4123 </literallayout>
4124 <literallayout>
4125 <emphasis>abstract-declarator:
4126 empty
4127 ( abstract-declarator )
4128 * abstract-declarator
4129 abstract-declarator ()
4130 abstract-declarator [ constant-expression<subscript>opt</subscript> ]</emphasis>
4131 </literallayout>
4132 <literallayout>
4133 <emphasis>typedef-name:
4134 identifier</emphasis>
4135 </literallayout>
4136 </para></sect2>
4137 <sect2><title>Statements</title>
4138 <para>
4139 <literallayout>
4140 <emphasis>compound-statement:
4141 { declaration-list<subscript>opt</subscript> statement-list<subscript>opt</subscript> }</emphasis>
4142 </literallayout>
4143 <literallayout>
4144 <emphasis>declaration-list:
4145 declaration
4146 declaration declaration-list</emphasis>
4147 </literallayout>
4148 <literallayout>
4149 <emphasis>statement-list:
4150 statement
4151 statement statement-list</emphasis>
4152 </literallayout>
4153 <literallayout>
4154 <emphasis>statement:
4155 compound-statement
4156 expression ;</emphasis>
4157 <literal>if</literal><emphasis> ( expression ) statement</emphasis>
4158 <literal>if</literal><emphasis> ( expression ) statement</emphasis> <literal>else</literal><emphasis> statement</emphasis>
4159 <literal>while</literal><emphasis> ( expression ) statement</emphasis>
4160 <literal>do</literal><emphasis> statement</emphasis> <literal>while</literal><emphasis> ( expression ) ;</emphasis>
4161 <literal>for</literal><emphasis> (exp<subscript>opt</subscript>'</emphasis><literal>;</literal><emphasis>exp<subscript>opt</subscript>'</emphasis><literal>;</literal><emphasis>exp<subscript>opt</subscript>'</emphasis><emphasis>) statement</emphasis>
4162 <literal>switch</literal><emphasis> ( expression ) statement</emphasis>
4163 <literal>case</literal><emphasis> constant-expression : statement</emphasis>
4164 <literal>default</literal><emphasis> : statement</emphasis>
4165 <literal>break ;
4166 continue ;
4167 return ;
4168 return</literal><emphasis> expression ;</emphasis>
4169 <literal>goto</literal><emphasis> identifier ;
4170 identifier : statement
4171 ;</emphasis>
4172 </literallayout>
4173 </para></sect2>
4174 <sect2><title>External definitions</title>
4175 <para>
4176 <literallayout>
4177 <emphasis>program:
4178 external-definition
4179 external-definition program</emphasis>
4180 </literallayout>
4181 <literallayout>
4182 <emphasis>external-definition:
4183 function-definition
4184 data-definition</emphasis>
4185 </literallayout>
4186 <literallayout>
4187 <emphasis>function-definition:
4188 decl-specifier<subscript>opt</subscript> function-declarator function-body</emphasis>
4189 </literallayout>
4190 <literallayout>
4191 <emphasis>function-declarator:
4192 declarator ( parameter-list<subscript>opt</subscript> )</emphasis>
4193 </literallayout>
4194 <literallayout>
4195 <emphasis>parameter-list:
4196 identifier
4197 identifier , parameter-list</emphasis>
4198 </literallayout>
4199 <literallayout>
4200 <emphasis>function-body:
4201 declaration-list<subscript>opt</subscript> compound-statement</emphasis>
4202 </literallayout>
4203 <literallayout>
4204 <emphasis>data-definition:</emphasis>
4205 <literal>extern</literal><emphasis> declaration</emphasis><literal> ;</literal>
4206 <literal>static</literal><emphasis> declaration</emphasis><literal> ;</literal>
4207 </literallayout>
4208 </para></sect2>
4209 <sect2><title>Preprocessor</title>
4210 <literallayout>
4211 <literal>#define</literal><replaceable> identifier token-string<subscript>opt</subscript></replaceable>
4212 <literal>#define</literal><replaceable> identifier</replaceable><literal>(</literal><replaceable>identifier</replaceable><literal>,...)</literal><replaceable>token-string<subscript>opt</subscript></replaceable>
4213 <literal>#undef</literal><replaceable> identifier</replaceable>
4214 <literal>#include &quot;</literal><replaceable>filename</replaceable><literal>&quot;</literal>
4215 #include &lt;<replaceable>filename</replaceable>&gt;
4216 <literal>#if</literal><replaceable> constant-expression</replaceable>
4217 <literal>#ifdef</literal><replaceable> identifier</replaceable>
4218 <literal>#ifndef</literal><replaceable> identifier</replaceable>
4219 <literal>#else</literal>
4220 <literal>#endif</literal>
4221 <literal>#line</literal> <replaceable>constant</replaceable> <replaceable>identifier</replaceable>
4222 </literallayout>
4223 </sect2>
4224 </sect1>
4225 </appendix>