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