· 6 years ago · Apr 20, 2019, 02:36 AM
1 (This foreword is not a part of American National Standard for
2Information Systems --- Programming Language C, X3.???-1988.)
3
4 American National Standard Programming Language C specifies the
5syntax and semantics of programs written in the C programming
6language. It specifies the C program's interactions with the
7execution environment via input and output data. It also specifies
8restrictions and limits imposed upon conforming implementations of C
9language translators.
10
11 The standard was developed by the X3J11 Technical Committee on the
12C Programming Language under project 381-D by American National
13Standards Committee on Computers and Information Processing (X3).
14SPARC document number 83-079 describes the purpose of this project to
15``provide an unambiguous and machine-independent definition of the
16language C.''
17
18 The need for a single clearly defined standard had arisen in the C
19community due to a rapidly expanding use of the C programming language
20and the variety of differing translator implementations that had been
21and were being developed. The existence of similar but incompatible
22implementations was a serious problem for program developers who
23wished to develop code that would compile and execute as expected in
24several different environments.
25
26 Part of this problem could be traced to the fact that implementors
27did not have an adequate definition of the C language upon which to
28base their implementations. The de facto C programming language
29standard, The C Programming Language by Brian W. Kernighan and Dennis
30M. Ritchie, is an excellent book; however, it is not precise or
31complete enough to specify the C language fully. In addition, the
32language has grown over years of use to incorporate new ideas in
33programming and to address some of the weaknesses of the original
34language.
35
36 American National Standard Programming Language C addresses the
37problems of both the program developer and the translator implementor
38by specifying the C language precisely.
39
40 The work of X3J11 began in the summer of 1983, based on the several
41documents that were made available to the Committee (see $1.5, Base
42Documents). The Committee divided the effort into three pieces: the
43environment, the language, and the library. A complete specification
44in each of these areas is necessary if truly portable programs are to
45be developed. Each of these areas is addressed in the Standard. The
46Committee evaluated many proposals for additions, deletions, and
47changes to the base documents during its deliberations. A concerted
48effort was made to codify existing practice wherever unambiguous and
49consistent practice could be identified. However, where no consistent
50practice could be identified, the Committee worked to establish clear
51rules that were consistent with the overall flavor of the language.
52
53 This document was approved as an American National Standard by the
54American National Standards Institute (ANSI) on DD MM, 1988.
55Suggestions for improvement of this Standard are welcome. They should
56be sent to the American National Standards Institute, 1430 Broadway,
57New York, NY 10018.
58
59 The Standard was processed and approved for submittal to ANSI by
60the American National Standards Committee on Computers and Information
61Processing, X3. Committee approval of the Standard does not
62necessarily imply that all members voted for its approval. At the
63time that it approved this Standard, the X3 Committee had the
64following members:
65
66 Organization Name of Representative
67(To be completed on approval of the Standard.)
68
69 Technical Committee X3J11 on the C Programming Language had the
70following members at the time they forwarded this document to X3 for
71processing as an American National Standard:
72
73Chair
74Jim Brodie
75
76Vice-Chair
77Thomas Plum Plum Hall Secretary
78P. J. Plauger Whitesmiths, Ltd.
79
80International Representative
81P. J. Plauger Whitesmiths, Ltd.
82Steve Hersee Lattice, Inc.
83
84Vocabulary Representative
85Andrew Johnson Prime Computer
86
87Environment Subcommittee Chairs
88Ralph Ryan Microsoft
89Ralph Phraner Phraner Associates
90
91Language Subcommittee Chair
92Lawrence Rosler AT&T
93
94Library Subcommittee Chair
95P. J. Plauger Whitesmiths, Ltd.
96
97Draft Redactor
98David F. Prosser AT&T
99Lawrence Rosler AT&T
100
101Rationale Redactor
102Randy Hudson Intermetrics, Inc.
103
104In the following list, unmarked names denote principal members and *
105denotes alternate members.
106
107David F. Prosser, AT&T
108Steven J. Adamski, AT&T* (X3H2 SQL liaison)
109Bob Gottlieb, Alliant Computer Systems
110Kevin Brosnan, Alliant Computer Systems
111Neal Weidenhofer, Amdahl
112Philip C. Steel, American Cimflex
113Eric McGlohon, American Cimflex*
114Stephen Kafka, Analog Devices
115Kevin Leary, Analog Devices*
116Gordon Sterling, Analog Devices*
117John Peyton, Apollo Computer
118Elizabeth Crockett, Apple Computers
119Ed Wells, Arinc
120Tom Ketterhagen, Arinc*
121Vaughn Vernon, Aspen Scientific
122Craig Bordelon, Bell Communications Research
123Steve Carter, Bell Communications Research*
124William Puig, Bell Communications Research*
125Bob Jervis, Borland International
126Yom-Tov Meged, Boston Systems Office
127Rose Thomson, Boston Systems Office*
128Maurice Fathi, COSMIC
129John Wu, Charles River Data Systems
130Daniel Mickey, Chemical Abstracts Service
131Thomas Mimlitch, Chemical Abstracts Service*
132Alan Losoff, Chicago Research & Trading Group
133Edward Briggs, Citibank
134Firmo Freire, Cobra S/A
135Jim Patterson, Cognos
136Bruce Tetelman, Columbia U. Center for Computing
137Terry Moore, CompuDas
138Mark Barrenechea, Computer Associates
139George Eberhardt, Computer Innovations
140Dave Neathery, Computer Innovations*
141Joseph Bibbo, Computrition
142Steve Davies, Concurrent Computer Corporation
143Don Fosbury, Control Data
144George VandeBunte, Control Data*
145Lloyd Irons, Cormorant Communications
146Tom MacDonald, Cray Research
147Lynne Johnson, Cray Research*
148Dave Becker, Cray Research*
149Jean Risley, Custom Development Environments
150Rex Jaeschke, DEC Professional
151Mike Terrazas, DECUS Representative
152Michael Meissner, Data General
153Mark Harris, Data General*
154Leonard Ohmes, Datapoint
155James Stanley, Data Systems Analysts
156Samuel J. Kendall, Delft Consulting
157Randy Meyers, Digital Equipment Corporation
158Art Bjork, Digital Equipment Corporation*
159Lu Anne Van de Pas, Digital Equipment Corporation*
160Ben Patel, EDS
161Richard Relph, EPI
162Graham Andrews, Edinburgh Portable Compilers
163Colin McPhail, Edinburgh Portable Compilers*
164J. Stephen Adamczyk, Edison Design Group
165Eric Schwarz, Edison Design Group*
166Dmitry Lenkov, Everest Solutions
167Frank Farance, Farance Inc.
168Peter Hayes, Farance Inc.*
169Florin Jordan, Floradin
170Philip Provin, General Electric Information Services
171Liz Sanville, Gould CSD
172Tina Aleksa, Gould CSD*
173Thomas Kelly, HCR Corporation
174Paul Jackson, HCR Corporation*
175Gary Jeter, Harris Computer Systems
176Sue Meloy, Hewlett Packard
177Larry Rosler, Hewlett Packard*
178Michelle Ruscetta, Hewlett Packard*
179Thomas E. Osten, Honeywell Information Systems
180David Kayden, Honeywell Information Systems*
181Shawn Elliott, IBM
182Larry Breed, IBM*
183Mel Goldberg, IBM*
184Mike Banahan, Instruction Set
185Clark Nelson, Intel
186Dan Lau, Intel*
187John Wolfe, InterACT
188Lillian Toll, InterACT*
189Randy Hudson, Intermetrics
190Keith Winter, International Computers Ltd.
191Honey M. Schrecker, International Computers Ltd.*
192Jim Brodie, J. Brodie & Associates
193Jacklin Kotikian, Kendall Square Research
194W. Peter Hesse, LSI Logic Europe Ltd.
195John Kaminski, Language Processors Inc.
196David Yost, Laurel Arts
197Mike Branstetter, Lawrence Livermore National Laboratory
198Bob Weaver, Los Alamos National Laboratory
199Lidia Eberhart, Modcomp
200Robert Sherry, Manx Software
201Courtney Meissen, Mark Williams Co.
202Patricia Jenkins, Masscomp
203Dave Hinman, Masscomp*
204Michael Kearns, MetaLink
205Tom Pennello, MetaWare Incorporated
206David F. Weil, Microsoft
207Mitch Harder, Microsoft*
208Kim Kempf, Microware Systems
209Shane McCarron, Minnesota Educational Computing
210Bruce Olsen, Mosaic Technologies
211Michael Paton, Motorola
212Rick Schubert, NCR
213Brian Johnson, NCR*
214Joseph Mueller, National Semiconductor
215Derek Godfrey, National Semiconductor*
216Jim Upperman, National Bureau of Standards
217James W. Williams, Naval Research Laboratory
218Lisa Simon, OCLC
219Paul Amaranth, Oakland University
220August R. Hansen, Omniware
221Michael Rolle, Oracle
222Carl Ellis, Oregon Software
223Barry Hedquist, Perennial
224Sassan Hazeghi, Peritus International
225James Holmlund, Peritus International*
226Thomas Plum, Plum Hall
227Christopher Skelly, Plum Hall*
228Andrew Johnson, Prime Computer
229Fran Litterio, Prime Computer*
230Daniel J. Conrad, Prismatics
231David Fritz, Production Languages
232Kenneth Pugh, Pugh
233Killeen Ed Ramsey, Purdue University
234Stephen Roberts, Purdue University*
235Kevin Nolan, Quantitative Technology Corp.
236Robert Mueller, Quantitative Technology Corp.*
237Chris DeVoney, Que Corporation
238Jon Tulk, Rabbit Software
239Terry Colligan, Rational Systems
240Daniel Saks, Saks & Associates
241Nancy Saks, Saks & Associates*
242Oliver Bradley, SAS Institute
243Alan Beale, SAS Institute*
244Larry Jones, SDRC
245Donald Kossman, SEI Information Technology
246Kenneth Harrenstien, SRI International
247Larry Rosenthal, Sierra Systems
248Phil Hempfner, Southern Bell Telephone
249Purshotam Rajani, Spruce Technology
250Savu Savulescu, Stagg Systems
251Peter Darnell, Stellar Computer
252Lee W. Cooprider, Stellar Computer*
253Paul Gilmartin, Storage Technology Corp.
254Steve Muchnick, Sun Microsystems
255Chuck Rasbold, Supercomputer Systems, Inc.
256Kelly O'Hair, Supercomputer Systems, Inc.*
257Henry Richardson, Tandem
258John M. Hausman, Tandem*
259Samuel Harbison, Tartan Laboratories
260Michael S. Ball, TauMetric
261Carl Sutton, Tektronix
262Jim Besemer, Tektronix*
263Reid Tatge, Texas Instruments
264Ed Brower, Tokheim
265Robert Mansfield, Tokheim*
266Monika Khushf, Tymlabs
267Morgan Jones, Tymlabs*
268Don Bixler, Unisys
269Steve Bartels, Unisys*
270Glenda Berkheimer, Unisys*
271Annice Jackson, Unisys*
272Fred Blonder, University of Maryland
273Fred Schwarz, University of Michigan
274R. Jordan Kreindler, University of Southern California CTC
275Mike Carmody, University of Waterloo
276Douglas Gwyn, US Army BRL (IEEE P1003 liaison)
277C. Dale Pierce, US Army Management Engineering*
278John C. Black, VideoFinancial
279Joseph Musacchia, Wang Labs
280Fred Rozakis, Wang Labs*
281P. J. Plauger, Whitesmiths, Ltd.
282Kim Leeper, Wick Hill
283Mark Wittenberg, Zehntel
284Jim Balter
285Robert Bradbury
286Edward Chin
287Neil Daniels
288Stephen Desofi
289Michael Duffy
290Phillip Escue
291Ralph Phraner
292D. Hugh Redelmeier
293Arnold Davi
294Robbins Roger
295Wilks Michael
296J. Young
297
298
299purpose: 1.1
300scope: 1.2
301references: 1.3
302organization of the document: 1.4
303base documents: 1.5
304definitions of terms: 1.6
305compliance: 1.7
306translation environment: 2.
307execution environment: 2.
308separate compilation: 2.1.1.1
309separate translation: 2.1.1.1
310source file: 2.1.1.1
311translation unit: 2.1.1.1
312program execution: 2.1.2.3
313side effects: 2.1.2.3
314sequence point: 2.1.2.3
315character set: 2.2.1
316signals: 2.2.3
317interrupts: 2.2.3
318syntax notation: 3.
319lexical elements: 3.1
320comment: 3.1
321white space: 3.1
322list of keywords: 3.1.1
323reserved words: 3.1.1
324underscore character: 3.1.2
325enumeration constant: 3.1.2
326length of names: 3.1.2
327internal name, length of: 3.1.2
328external name, length of: 3.1.2
329function name, length of: 3.1.2
330scopes: 3.1.2.1
331prototype, function: 3.1.2.1
332function scope: 3.1.2.1
333file scope: 3.1.2.1
334block scope: 3.1.2.1
335block structure: 3.1.2.1
336function prototype scope: 3.1.2.1
337linkage: 3.1.2.2
338external linkage: 3.1.2.2
339internal linkage: 3.1.2.2
340no linkage: 3.1.2.2
341name spaces: 3.1.2.3
342named label: 3.1.2.3
343structure tag: 3.1.2.3
344union tag: 3.1.2.3
345enumeration tag: 3.1.2.3
346structure member name: 3.1.2.3
347union member name: 3.1.2.3
348storage duration: 3.1.2.4
349static storage duration: 3.1.2.4
350automatic storage duration: 3.1.2.4
351types: 3.1.2.5
352object types: 3.1.2.5
353function types: 3.1.2.5
354incomplete types: 3.1.2.5
355char type: 3.1.2.5
356signed character: 3.1.2.5
357signed char type: 3.1.2.5
358short type: 3.1.2.5
359long type: 3.1.2.5
360unsigned type: 3.1.2.5
361float type: 3.1.2.5
362double type: 3.1.2.5
363long double type: 3.1.2.5
364basic types: 3.1.2.5
365character types: 3.1.2.5
366enumerated type: 3.1.2.5
367void type: 3.1.2.5
368derived types: 3.1.2.5
369integral types: 3.1.2.5
370arithmetic types: 3.1.2.5
371scalar types: 3.1.2.5
372aggregate types: 3.1.2.5
373constants: 3.1.3
374floating constant: 3.1.3.1
375double constant: 3.1.3.1
376integer constant: 3.1.3.2
377decimal constant: 3.1.3.2
378octal constant: 3.1.3.2
379hexadecimal constant: 3.1.3.2
380unsigned constant: 3.1.3.2
381long constant: 3.1.3.2
382enumeration constant: 3.1.3.3
383character constant: 3.1.3.4
384backslash character: 3.1.3.4
385escape character: 3.1.3.4
386escape sequence: 3.1.3.4
387string literal: 3.1.4
388character string: 3.1.4
389operator: 3.1.5
390evaluation: 3.1.5
391operand: 3.1.5
392punctuator: 3.1.6
393character-integer conversion: 3.2.1.1
394integer-character conversion: 3.2.1.1
395integral promotions: 3.2.1.1
396integer-long conversion: 3.2.1.1
397signed character: 3.2.1.1
398unsigned-integer conversion: 3.2.1.2
399integer-unsigned conversion: 3.2.1.2
400long-unsigned conversion: 3.2.1.2
401long-integer conversion: 3.2.1.2
402floating-integer conversion: 3.2.1.3
403integer-floating conversion: 3.2.1.3
404float-double conversion: 3.2.1.4
405double-float conversion: 3.2.1.4
406arithmetic conversions: 3.2.1.5
407type conversion rules: 3.2.1.5
408lvalue: 3.2.2.1
409function designator: 3.2.2.1
410conversion of array: 3.2.2.1
411conversion of function name: 3.2.2.1
412void type: 3.2.2.2
413pointer-pointer conversion: 3.2.2.3
414integer-pointer conversion: 3.2.2.3
415null pointer: 3.2.2.3
416expression: 3.3
417precedence of operators: 3.3
418associativity of operators: 3.3
419order of evaluation of expressions: 3.3
420order of evaluation: 3.3
421bitwise operators: 3.3
422exceptions: 3.3
423primary expression: 3.3.1
424type of string: 3.3.1
425parenthesized expression: 3.3.1
426subscript operator: 3.3.2
427function call: 3.3.2
428structure member operator: 3.3.2
429structure pointer operator: 3.3.2
430++ increment operator: 3.3.2
431-- decrement operator: 3.3.2
432array, explanation of subscripting: 3.3.2.1
433subscripting, explanation of: 3.3.2.1
434multi-dimensional array: 3.3.2.1
435storage order of array: 3.3.2.1
436function call: 3.3.2.2
437implicit declaration of function: 3.3.2.2
438function argument: 3.3.2.2
439call by value: 3.3.2.2
440recursion: 3.3.2.2
441structure reference: 3.3.2.3
442union reference: 3.3.2.3
443common initial sequence: 3.3.2.3
444postfix ++ and --: 3.3.2.4
445-- decrement operator: 3.3.2.4
446unary expression: 3.3.3
447++ increment operator: 3.3.3
448-- decrement operator: 3.3.3
449sizeof operator: 3.3.3
450& address operator: 3.3.3
451* indirection operator: 3.3.3
452+ unary plus operator: 3.3.3
453- unary minus operator: 3.3.3
454~ bitwise complement operator: 3.3.3
455! logical negation operator: 3.3.3
456++ increment operator: 3.3.3.1
457prefix ++ and --: 3.3.3.1
458-- decrement operator: 3.3.3.1
459+ unary plus operator: 3.3.3.3
460- unary minus operator: 3.3.3.3
461~ bitwise complement operator: 3.3.3.3
462! logical negation operator: 3.3.3.3
463byte: 3.3.3.4
464storage allocator: 3.3.3.4
465cast expression: 3.3.4
466cast operator: 3.3.4
467explicit conversion operator: 3.3.4
468cast operator: 3.3.4
469pointer conversion: 3.3.4
470explicit conversion operator: 3.3.4
471pointer-integer conversion: 3.3.4
472integer-pointer conversion: 3.3.4
473alignment restriction: 3.3.4
474arithmetic operators: 3.3.5
475multiplicative operators: 3.3.5
476* multiplication operator: 3.3.5
477/ division operator: 3.3.5
478% modulus operator: 3.3.5
479additive operators: 3.3.6
480+ addition operator: 3.3.6
481- subtraction operator: 3.3.6
482pointer arithmetic: 3.3.6
483pointer arithmetic: 3.3.6
484shift operators: 3.3.7
485<< left shift operator: 3.3.7
486>> right shift operator: 3.3.7
487relational operators: 3.3.8
488< less than operator: 3.3.8
489> greater than operator: 3.3.8
490<= less than or equal to operator: 3.3.8
491>= greater than or equal to operator: 3.3.8
492pointer comparison: 3.3.8
493equality operators: 3.3.9
494== equality operator: 3.3.9
495!= inequality operator: 3.3.9
496& bitwise AND operator: 3.3.10
497^ bitwise exclusive OR operator: 3.3.11
498| bitwise inclusive OR operator: 3.3.12
499&& logical AND operator: 3.3.13
500|| logical OR operator: 3.3.14
501?: conditional expression: 3.3.15
502assignment operators: 3.3.16
503assignment expression: 3.3.16
504simple assignment: 3.3.16.1
505conversion by assignment: 3.3.16.1
506compound assignment: 3.3.16.2
507comma operator: 3.3.17
508constant expression: 3.4
509permitted form of initializer: 3.4
510declarations: 3.5
511storage-class specifier: 3.5.1
512storage-class declaration: 3.5.1
513typedef declaration: 3.5.1
514extern storage class: 3.5.1
515static storage class: 3.5.1
516auto storage class: 3.5.1
517register storage class: 3.5.1
518type specifier: 3.5.2
519void type: 3.5.2
520char type: 3.5.2
521short type: 3.5.2
522int type: 3.5.2
523long type: 3.5.2
524float type: 3.5.2
525double type: 3.5.2
526signed type: 3.5.2
527unsigned type: 3.5.2
528structure declaration: 3.5.2.1
529union declaration: 3.5.2.1
530bit-field declaration: 3.5.2.1
531bit-field: 3.5.2.1
532member alignment: 3.5.2.1
533enumeration: 3.5.2.2
534enum-specifier: 3.5.2.2
535enumerator: 3.5.2.2
536structure tag: 3.5.2.3
537union tag: 3.5.2.3
538structure content: 3.5.2.3
539union content: 3.5.2.3
540enumeration content: 3.5.2.3
541self-referential structure: 3.5.2.3
542type qualifier: 3.5.3
543const type qualifier: 3.5.3
544volatile type qualifier: 3.5.3
545declarator: 3.5.4
546type declaration: 3.5.4
547declaration of pointer: 3.5.4.1
548array declaration: 3.5.4.2
549declaration of function: 3.5.4.3
550type names: 3.5.5
551abstract declarator: 3.5.5
552typedef declaration: 3.5.6
553initialization: 3.5.7
554initialization of statics: 3.5.7
555implicit initialization: 3.5.7
556default initialization: 3.5.7
557initialization of automatics: 3.5.7
558aggregate initialization: 3.5.7
559array initialization: 3.5.7
560structure initialization: 3.5.7
561character array initialization: 3.5.7
562wchar_t array initialization: 3.5.7
563statements: 3.6
564sequencing of statements: 3.6
565full expression: 3.6
566labeled statement: 3.6.1
567named label: 3.6.1
568case label: 3.6.1
569default label: 3.6.1
570compound statement: 3.6.2
571block: 3.6.2
572block structure: 3.6.2
573initialization in blocks: 3.6.2
574expression statement: 3.6.3
575null statement: 3.6.3
576empty statement: 3.6.3
577if-else statement: 3.6.4.1
578switch statement: 3.6.4.2
579switch body: 3.6.4.2
580loop body: 3.6.5
581while statement: 3.6.5.1
582do statement: 3.6.5.2
583for statement: 3.6.5.3
584goto statement: 3.6.6.1
585continue statement: 3.6.6.2
586break statement: 3.6.6.3
587return statement: 3.6.6.4
588type conversion by return: 3.6.6.4
589conversion by return: 3.6.6.4
590external definition: 3.7
591function definition: 3.7.1
592parameter: 3.7.1
593array argument: 3.7.1
594function name argument: 3.7.1
595pointer to function: 3.7.1
596object definitions: 3.7.2
597scope of externals: 3.7.2
598tentative definition: 3.7.2
599preprocessing directives: 3.8
600macro preprocessor: 3.8
601preprocessing directive lines: 3.8
602conditional inclusion: 3.8.1
603#if: 3.8.1
604#elif 3.8.1
605#ifdef: 3.8.1
606#ifndef: 3.8.1
607#else: 3.8.1
608#endif: 3.8.1
609#include: 3.8.2
610source file inclusion: 3.8.2
611macro replacement: 3.8.3
612object-like macro: 3.8.3
613function-like macro: 3.8.3
614macro name: 3.8.3
615#define: 3.8.3
616macro parameters: 3.8.3
617macro invocation: 3.8.3
618argument substitution: 3.8.3.1
619# operator: 3.8.3.2
620## operator: 3.8.3.3
621rescanning and replacement: 3.8.3.4
622macro definition scope: 3.8.3.5
623#undef: 3.8.3.5
624#line: 3.8.4
625error directive: 3.8.5
626pragma directive: 3.8.6
627null directive: 3.8.7
628introduction: 4.1
629string definition: 4.1.1
630letter definition: 4.1.1
631decimal-point definition: 4.1.1
632reserved identifier: 4.1.2
633printing character: 4.3
634control character: 4.3
635variable arguments: 4.8
636unbuffered stream: 4.9.3
637fully buffered stream: 4.9.3
638line buffered stream: 4.9.3
639appendices: A.
640language syntax summary: A.1
641sequence points: A.2
642library summary: A.3
643implementation limits: A.4
644warnings: A.5
645portability: A.6
646order of evaluation: A.6.1
647machine dependency: A.6.3
648restrictions on registers: A.6.3.7
649function pointer casts: A.6.5.7
650bit-field types: A.6.5.8
651fortran keyword: A.6.5.9
652asm keyword: A.6.5.10
653multiple external definitions: A.6.5.11
654empty macro arguments: A.6.5.12
655predefined macro names: A.6.5.13
656signal handler arguments: A.6.5.14
657stream types: A.6.5.15
658file-opening modes: A.6.5.15
659file position indicator: A.6.5.16
660foreword: A.7
661
662
6631. INTRODUCTION
664
6651.1 PURPOSE
666
667 This Standard specifies the form and establishes the interpretation
668 of programs written in the C programming language./1/
669
6701.2 SCOPE
671
672 This Standard specifies:
673
674 * the representation of C programs;
675
676 * the syntax and constraints of the C language;
677
678 * the semantic rules for interpreting C programs;
679
680 * the representation of input data to be processed by C programs;
681
682 * the representation of output data produced by C programs;
683
684 * the restrictions and limits imposed by a conforming implementation of C.
685
686
687 This Standard does not specify:
688
689 * the mechanism by which C programs are transformed for use by a
690 data-processing system;
691
692 * the mechanism by which C programs are invoked for use by a
693 data-processing system;
694
695 * the mechanism by which input data are transformed for use by a C program;
696
697 * the mechanism by which output data are transformed after being
698 produced by a C program;
699
700 * the size or complexity of a program and its data that will exceed
701 the capacity of any specific data-processing system or the capacity of
702 a particular processor;
703
704 * all minimal requirements of a data-processing system that is
705 capable of supporting a conforming implementation.
706
707
7081.3 REFERENCES
709
710 1. ``The C Reference Manual'' by Dennis M. Ritchie, a version of
711 which was published in The C Programming Language by Brian
712 W. Kernighan and Dennis M. Ritchie, Prentice-Hall, Inc., (1978).
713 Copyright owned by AT&T.
714
715 2. 1984 /usr/group Standard by the /usr/group Standards Committee,
716 Santa Clara, California, USA (November, 1984).
717
718 3. American National Dictionary for Information Processing Systems,
719 Information Processing Systems Technical Report ANSI X3/TR-1-82 (1982).
720
721 4. ISO 646-1983 Invariant Code Set.
722
723 5. IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754-1985).
724
725 6. ISO 4217 Codes for the Representation of Currency and Funds.
726
727
7281.4 ORGANIZATION OF THE DOCUMENT
729
730 This document is divided into four major sections:
731
732 1. this introduction;
733
734 2. the characteristics of environments that translate and execute C programs;
735
736 3. the language syntax, constraints, and semantics;
737
738 4. the library facilities.
739
740Examples are provided to illustrate possible forms of the
741constructions described. Footnotes are provided to emphasize
742consequences of the rules described in the section or elsewhere in the
743Standard. References are used to refer to other related sections. A
744set of appendices summarizes information contained in the Standard.
745The abstract, the foreword, the examples, the footnotes, the
746references, and the appendices are not part of the Standard.
747
7481.5 BASE DOCUMENTS
749
750The language section ($3) is derived from ``The C Reference
751Manual'' by Dennis M. Ritchie, a version of which was published as
752Appendix A of The C Programming Language by Brian W. Kernighan and
753Dennis M. Ritchie, Prentice-Hall, Inc., 1978; copyright owned by AT&T.
754
755The library section ($4) is based on the 1984 /usr/group Standard by
756the /usr/group Standards Committee, Santa Clara, California, USA
757(November 14, 1984).
758
7591.6 DEFINITIONS OF TERMS
760
761 In this Standard, ``shall'' is to be interpreted as a requirement
762on an implementation or on a program; conversely, ``shall not'' is to
763be interpreted as a prohibition.
764
765The following terms are used in this document:
766
767 * Implementation --- a particular set of software, running in a
768 particular translation environment under particular control options,
769 that performs translation of programs for, and supports execution of
770 functions in, a particular execution environment.
771
772 * Bit --- the unit of data storage in the execution environment large
773 enough to hold an object that may have one of two values. It need not
774 be possible to express the address of each individual bit of an
775 object.
776
777 * Byte --- the unit of data storage in the execution environment
778 large enough to hold any member of the basic character set of the
779 execution environment. It shall be possible to express the address of
780 each individual byte of an object uniquely. A byte is composed of a
781 contiguous sequence of bits, the number of which is
782 implementation-defined. The least significant bit is called the
783 low-order bit; the most significant bit is called the high-order bit.
784
785 * Object --- a region of data storage in the execution environment,
786 the contents of which can represent values. Except for bit-fields,
787 objects are composed of contiguous sequences of one or more bytes, the
788 number, order, and encoding of which are either explicitly specified
789 or implementation-defined.
790
791 * Character --- a single byte representing a member of the basic
792 character set of either the source or the execution environment.
793
794 * Multibyte character --- a sequence of one or more bytes
795 representing a member of the extended character set of either the
796 source or the execution environment. The extended character set is a
797 superset of the basic character set.
798
799 * Alignment --- a requirement that objects of a particular type be
800 located on storage boundaries with addresses that are particular
801 multiples of a byte address.
802
803 * Argument --- an expression in the comma-separated list bounded by
804 the parentheses in a function call expression, or a sequence of
805 preprocessing tokens in the comma-separated list bounded by the
806 parentheses in a function-like macro invocation. Also known as
807 ``actual argument'' or ``actual parameter.''
808
809 * Parameter --- an object declared as part of a function declaration
810 or definition that acquires a value on entry to the function, or an
811 identifier from the comma-separated list bounded by the parentheses
812 immediately following the macro name in a function-like macro
813 definition. Also known as ``formal argument'' or ``formal
814 parameter.''
815
816 * Unspecified behavior --- behavior, for a correct program construct
817 and correct data, for which the Standard imposes no requirements.
818
819 * Undefined behavior --- behavior, upon use of a nonportable or
820 erroneous program construct, of erroneous data, or of
821 indeterminately-valued objects, for which the Standard imposes no
822 requirements. Permissible undefined behavior ranges from ignoring the
823 situation completely with unpredictable results, to behaving during
824 translation or program execution in a documented manner characteristic
825 of the environment (with or without the issuance of a diagnostic
826 message), to terminating a translation or execution (with the issuance
827 of a diagnostic message).
828
829 If a ``shall'' or ``shall not'' requirement that appears outside of
830 a constraint is violated, the behavior is undefined. Undefined
831 behavior is otherwise indicated in this Standard by the words
832 ``undefined behavior'' or by the omission of any explicit definition
833 of behavior. There is no difference in emphasis among these three;
834 they all describe ``behavior that is undefined.''
835
836 * Implementation-defined behavior --- behavior, for a correct program
837 construct and correct data, that depends on the characteristics of the
838 implementation and that each implementation shall document.
839
840 * Locale-specific behavior --- behavior that depends on local
841 conventions of nationality, culture, and language that each
842 implementation shall document.
843
844 * Diagnostic message --- a message belonging to an
845 implementation-defined subset of the implementation's message output.
846
847 * Constraints --- syntactic and semantic restrictions by which the
848 exposition of language elements is to be interpreted.
849
850 * Implementation limits --- restrictions imposed upon programs by the
851 implementation.
852
853 * Forward references --- references to later sections of the Standard
854 that contain additional information relevant to this section.
855
856 Other terms are defined at their first appearance, indicated by italic
857 type. Terms explicitly defined in this Standard are not to be
858 presumed to refer implicitly to similar terms defined elsewhere.
859
860 Terms not defined in this Standard are to be interpreted according to
861 the American National Dictionary for Information Processing Systems,
862 Information Processing Systems Technical Report ANSI X3/TR-1-82 (1982).
863
864Forward references: localization ($4.4).
865
866"Examples"
867
868 An example of unspecified behavior is the order in which the
869 arguments to a function are evaluated.
870
871 An example of undefined behavior is the behavior on integer overflow.
872
873 An example of implementation-defined behavior is the propagation of
874 the high-order bit when a signed integer is shifted right.
875
876 An example of locale-specific behavior is whether the islower
877 function returns true for characters other than the 26 lower-case
878 English letters.
879
880Forward references: bitwise shift operators ($3.3.7), expressions
881($3.3), function calls ($3.3.2.2), the islower function ($4.3.1.6).
882
883
8841.7 COMPLIANCE
885
886 A strictly conforming program shall use only those features of the
887language and library specified in this Standard. It shall not produce
888output dependent on any unspecified, undefined, or
889implementation-defined behavior, and shall not exceed any minimum
890implementation limit.
891
892 The two forms of conforming implementation are hosted and
893freestanding. A conforming hosted implementation shall accept any
894strictly conforming program. A conforming freestanding implementation
895shall accept any strictly conforming program in which the use of the
896features specified in the library section ($4) is confined to the
897contents of the standard headers <float.h> , <limits.h> , <stdarg.h> ,
898and <stddef.h> . A conforming implementation may have extensions
899(including additional library functions), provided they do not alter
900the behavior of any strictly conforming program.
901
902 A conforming program is one that is acceptable to a conforming
903implementation./2/
904
905 An implementation shall be accompanied by a document that defines
906all implementation-defined characteristics and all extensions.
907
908Forward references: limits <float.h> and <limits.h> ($4.1.4), variable
909arguments <stdarg.h> ($4.8), common definitions <stddef.h> ($4.1.5).
910
911
9121.8 FUTURE DIRECTIONS
913
914 With the introduction of new devices and extended character sets,
915new features may be added to the Standard. Subsections in the
916language and library sections warn implementors and programmers of
917usages which, though valid in themselves, may conflict with future
918additions.
919
920 Certain features are obsolescent , which means that they may be
921considered for withdrawal in future revisions of the Standard. They
922are retained in the Standard because of their widespread use, but
923their use in new implementations (for implementation features) or new
924programs (for language or library features) is discouraged.
925
926Forward references: future language directions ($3.9.9), future
927library directions ($4.13).
928
9291.9 ABOUT THIS DRAFT
930
931 Symbols in the right margin mark substantive differences between
932this draft and its predecessor (ANSI X3J11/88-001, January 11, 1988).
933A plus sign indicates an addition, a minus sign a deletion, and a
934vertical bar a replacement.
935
936 This section and the difference marks themselves will not appear in
937the published document.
938
939
9402. ENVIRONMENT
941
942 An implementation translates C source files and executes C programs
943in two data-processing-system environments, which will be called the
944translation environment and the execution environment in this
945Standard. Their characteristics define and constrain the results of
946executing conforming C programs constructed according to the syntactic
947and semantic rules for conforming implementations.
948
949Forward references: In the environment section ($2), only a few of
950many possible forward references have been noted.
951
952
9532.1 CONCEPTUAL MODELS
954
9552.1.1 Translation environment
956
9572.1.1.1 Program structure
958
959 A C program need not all be translated at the same time. The text
960of the program is kept in units called source files in this Standard.
961A source file together with all the headers and source files included
962via the preprocessing directive #include , less any source lines
963skipped by any of the conditional inclusion preprocessing directives,
964is called a translation unit. Previously translated translation units
965may be preserved individually or in libraries. The separate
966translation units of a program communicate by (for example) calls to
967functions whose identifiers have external linkage, by manipulation of
968objects whose identifiers have external linkage, and by manipulation
969of data files. Translation units may be separately translated and
970then later linked to produce an executable program.
971
972Forward references: conditional inclusion ($3.8.1), linkages of
973identifiers ($3.1.2.2), source file inclusion ($3.8.2).
974
9752.1.1.2 Translation phases
976
977 The precedence among the syntax rules of translation is specified
978by the following phases./3/
979
980 1. Physical source file characters are mapped to the source character
981 set (introducing new-line characters for end-of-line indicators) if
982 necessary. Trigraph sequences are replaced by corresponding
983 single-character internal representations.
984
985 2. Each instance of a new-line character and an immediately preceding
986 backslash character is deleted, splicing physical source lines to form
987 logical source lines. A source file that is not empty shall end in a
988 new-line character, which shall not be immediately preceded by a
989 backslash character.
990
991 3. The source file is decomposed into preprocessing tokens/4/ and
992 sequences of white-space characters (including comments). A source
993 file shall not end in a partial preprocessing token or comment. Each
994 comment is replaced by one space character. New-line characters are
995 retained. Whether each nonempty sequence of other white-space
996 characters is retained or replaced by one space character is
997 implementation-defined.
998
999 4. Preprocessing directives are executed and macro invocations are
1000 expanded. A #include preprocessing directive causes the named header
1001 or source file to be processed from phase 1 through phase 4,
1002 recursively.
1003
1004 5. Each escape sequence in character constants and string literals is
1005 converted to a member of the execution character set.
1006
1007 6. Adjacent character string literal tokens are concatenated and
1008 adjacent wide string literal tokens are concatenated.
1009
1010 7. White-space characters separating tokens are no longer
1011 significant. Preprocessing tokens are converted into tokens. The
1012 resulting tokens are syntactically and semantically analyzed and
1013 translated.
1014
1015 8. All external object and function references are resolved. Library
1016 components are linked to satisfy external references to functions and
1017 objects not defined in the current translation. All such translator
1018 output is collected into a program image which contains information
1019 needed for execution in its execution environment.
1020
1021Forward references: lexical elements ($3.1), preprocessing directives
1022($3.8), trigraph sequences ($2.2.1.1).
1023
10242.1.1.3 Diagnostics
1025
1026 A conforming implementation shall produce at least one diagnostic
1027message (identified in an implementation-defined manner) for every
1028translation unit that contains a violation of any syntax rule or
1029constraint. Diagnostic messages need not be produced in other
1030circumstances.
1031
10322.1.2 Execution environments
1033
1034 Two execution environments are defined: freestanding and hosted.
1035In both cases, program startup occurs when a designated C function
1036is called by the execution environment. All objects in static storage
1037shall be initialized (set to their initial values) before program
1038startup. The manner and timing of such initialization are otherwise
1039unspecified. Program termination returns control to the execution
1040environment.
1041
1042Forward references: initialization ($3.5.7).
1043
10442.1.2.1 Freestanding environment
1045
1046 In a freestanding environment (in which C program execution may
1047take place without any benefit of an operating system), the name and
1048type of the function called at program startup are
1049implementation-defined. There are otherwise no reserved external
1050identifiers. Any library facilities available to a freestanding
1051program are implementation-defined.
1052
1053 The effect of program termination in a freestanding environment is
1054implementation-defined.
1055
10562.1.2.2 Hosted environment
1057
1058 A hosted environment need not be provided, but shall conform to the
1059following specifications if present.
1060
1061"Program startup"
1062
1063 The function called at program startup is named main . The
1064implementation declares no prototype for this function. It can be
1065defined with no parameters:
1066
1067 int main(void) { /*...*/ }
1068
1069or with two parameters (referred to here as argc and argv , though any
1070names may be used, as they are local to the function in which they are
1071declared):
1072
1073 int main(int argc, char *argv[]) { /*...*/ }
1074
1075
1076 If they are defined, the parameters to the main function shall obey
1077the following constraints:
1078
1079 * The value of argc shall be nonnegative.
1080
1081 * argv[argc] shall be a null pointer.
1082
1083 * If the value of argc is greater than zero, the array members
1084 argv[0] through argv[argc-1] inclusive shall contain pointers to
1085 strings, which are given implementation-defined values by the host
1086 environment prior to program startup. The intent is to supply to the
1087 program information determined prior to program startup from elsewhere
1088 in the hosted environment. If the host environment is not capable of
1089 supplying strings with letters in both upper-case and lower-case, the
1090 implementation shall ensure that the strings are received in
1091 lower-case.
1092
1093 * If the value of argc is greater than zero, the string pointed to by
1094 argv[0] represents the program name ;argv[0][0] shall be the null
1095 character if the program name is not available from the host
1096 environment. If the value of argc is greater than one, the strings
1097 pointed to by argv[1] through argv[argc-1] represent the program
1098 parameters .
1099
1100 * The parameters argc and argv and the strings pointed to by the argv
1101 array shall be modifiable by the program, and retain their last-stored
1102 values between program startup and program termination.
1103
1104"Program execution"
1105
1106 In a hosted environment, a program may use all the functions,
1107macros, type definitions, and objects described in the library section ($4).
1108
1109"Program termination"
1110
1111 A return from the initial call to the main function is equivalent
1112to calling the exit function with the value returned by the main
1113function as its argument. If the main function executes a return that
1114specifies no value, the termination status returned to the host
1115environment is undefined.
1116
1117Forward references: definition of terms ($4.1.1), the exit function
1118($4.10.4.3).
1119
1120
11212.1.2.3 Program execution
1122
1123 The semantic descriptions in this Standard describe the behavior of
1124an abstract machine in which issues of optimization are irrelevant.
1125
1126 Accessing a volatile object, modifying an object, modifying a file,
1127or calling a function that does any of those operations are all side
1128effects ,which are changes in the state of the execution environment.
1129Evaluation of an expression may produce side effects. At certain
1130specified points in the execution sequence called sequence points, all
1131side effects of previous evaluations shall be complete and no side
1132effects of subsequent evaluations shall have taken place.
1133
1134 In the abstract machine, all expressions are evaluated as specified
1135by the semantics. An actual implementation need not evaluate part of
1136an expression if it can deduce that its value is not used and that no
1137needed side effects are produced (including any caused by calling a
1138function or accessing a volatile object).
1139
1140 When the processing of the abstract machine is interrupted by
1141receipt of a signal, only the values of objects as of the previous
1142sequence point may be relied on. Objects that may be modified between
1143the previous sequence point and the next sequence point need not have
1144received their correct values yet.
1145
1146 An instance of each object with automatic storage duration is
1147associated with each entry into a block. Such an object exists and
1148retains its last-stored value during the execution of the block and
1149while the block is suspended (by a call of a function or receipt of a
1150signal).
1151
1152 The least requirements on a conforming implementation are:
1153
1154 * At sequence points, volatile objects are stable in the sense that
1155 previous evaluations are complete and subsequent evaluations have not
1156 yet occurred.
1157
1158 * At program termination, all data written into files shall be
1159 identical to the result that execution of the program according to the
1160 abstract semantics would have produced.
1161
1162 * The input and output dynamics of interactive devices shall take
1163 place as specified in $4.9.3. The intent of these requirements is
1164 that unbuffered or line-buffered output appear as soon as possible, to
1165 ensure that prompting messages actually appear prior to a program
1166 waiting for input.
1167
1168 What constitutes an interactive device is implementation-defined.
1169
1170 More stringent correspondences between abstract and actual
1171 semantics may be defined by each implementation.
1172
1173"Examples"
1174
1175 An implementation might define a one-to-one correspondence between
1176abstract and actual semantics: at every sequence point, the values of
1177the actual objects would agree with those specified by the abstract
1178semantics. The keyword volatile would then be redundant.
1179
1180 Alternatively, an implementation might perform various
1181optimizations within each translation unit, such that the actual
1182semantics would agree with the abstract semantics only when making
1183function calls across translation unit boundaries. In such an
1184implementation, at the time of each function entry and function return
1185where the calling function and the called function are in different
1186translation units, the values of all externally linked objects and of
1187all objects accessible via pointers therein would agree with the
1188abstract semantics. Furthermore, at the time of each such function
1189entry the values of the parameters of the called function and of all
1190objects accessible via pointers therein would agree with the abstract
1191semantics. In this type of implementation, objects referred to by
1192interrupt service routines activated by the signal function would
1193require explicit specification of volatile storage, as well as other
1194implementation-defined restrictions.
1195
1196 In executing the fragment
1197
1198 char c1, c2;
1199 /*...*/
1200 c1 = c1 + c2;
1201
1202the ``integral promotions'' require that the abstract machine promote
1203the value of each variable to int size and then add the two int s and
1204truncate the sum. Provided the addition of two char s can be done
1205without creating an overflow exception, the actual execution need only
1206produce the same result, possibly omitting the promotions.
1207
1208 Similarly, in the fragment
1209
1210 float f1, f2;
1211 double d;
1212 /*...*/
1213 f1 = f2 * d;
1214
1215the multiplication may be executed using single-precision arithmetic
1216if the implementation can ascertain that the result would be the same
1217as if it were executed using double-precision arithmetic (for example,
1218if d were replaced by the constant 2.0, which has type double ).
1219Alternatively, an operation involving only int s or float s may be
1220executed using double-precision operations if neither range nor
1221precision is lost thereby.
1222
1223Forward references: compound statement, or block ($3.6.2), files
1224($4.9.3), sequence points ($3.3, $3.6), the signal function ($4.7),
1225type qualifiers ($3.5.3).
1226
1227
12282.2 ENVIRONMENTAL CONSIDERATIONS
1229
12302.2.1 Character sets
1231
1232 Two sets of characters and their associated collating sequences
1233shall be defined: the set in which source files are written, and the
1234set interpreted in the execution environment. The values of the
1235members of the execution character set are implementation-defined; any
1236additional members beyond those required by this section are
1237locale-specific.
1238
1239 In a character constant or string literal, members of the execution
1240character set shall be represented by corresponding members of the
1241source character set or by escape sequences consisting of the
1242backslash \ followed by one or more characters. A byte with all bits
1243set to 0, called the null character, shall exist in the basic
1244execution character set; it is used to terminate a character string
1245literal.
1246
1247 Both the basic source and basic execution character sets shall have
1248at least the following members: the 26 upper-case letters of the
1249English alphabet
1250
1251 A B C D E F G H I J K L M
1252 N O P Q R S T U V W X Y Z
1253
1254the 26 lower-case letters of the English alphabet
1255
1256 a b c d e f g h i j k l m
1257 n o p q r s t u v w x y z
1258
1259the 10 decimal digits
1260
1261 0 1 2 3 4 5 6 7 8 9
1262
1263the following 29 graphic characters
1264
1265 ! " # % & ' ( ) * + , - . / :
1266 ; < = > ? [ \ ] ^ _ { | } ~
1267
1268the space character, and control characters representing horizontal
1269tab, vertical tab, and form feed. In both the source and execution
1270basic character sets, the value of each character after 0 in the above
1271list of decimal digits shall be one greater than the value of the
1272previous. In source files, there shall be some way of indicating the
1273end of each line of text; this Standard treats such an end-of-line
1274indicator as if it were a single new-line character. In the execution
1275character set, there shall be control characters representing alert,
1276backspace, carriage return, and new line. If any other characters are
1277encountered in a source file (except in a preprocessing token that is
1278never converted to a token, a character constant, a string literal, or
1279a comment), the behavior is undefined.
1280
1281Forward references: character constants ($3.1.3.4), preprocessing
1282directives ($3.8), string literals ($3.1.4), comments ($3.1.9).
1283
1284
12852.2.1.1 Trigraph sequences
1286
1287 All occurrences in a source file of the following sequences of
1288three characters (called trigraph sequences /5/)are replaced with the
1289corresponding single character.
1290
1291 ??= #
1292 ??( [
1293 ??/ \
1294 ??) ]
1295 ??' ^
1296 ??< {
1297 ??! |
1298 ??> }
1299 ??- ~
1300
1301No other trigraph sequences exist. Each ? that does not begin one of
1302the trigraphs listed above is not changed.
1303
1304Example
1305
1306 The following source line
1307
1308 printf("Eh???/n");
1309
1310becomes (after replacement of the trigraph sequence ??/ )
1311
1312 printf("Eh?\n");
1313
1314
13152.2.1.2 Multibyte characters
1316
1317 The source character set may contain multibyte characters, used to
1318represent members of the extended character set. The execution
1319character set may also contain multibyte characters, which need not
1320have the same encoding as for the source character set. For both
1321character sets, the following shall hold:
1322
1323 * The single-byte characters defined in $2.2.1 shall be present.
1324
1325 * The presence, meaning, and representation of any additional members
1326 is locale-specific.
1327
1328 * A multibyte character may have a state-dependent encoding ,wherein
1329 each sequence of multibyte characters begins in an initial shift state
1330 and enters other implementation-defined shift states when specific
1331 multibyte characters are encountered in the sequence. While in the
1332 initial shift state, all single-byte characters retain their usual
1333 interpretation and do not alter the shift state. The interpretation
1334 for subsequent bytes in the sequence is a function of the current
1335 shift state.
1336
1337 * A byte with all bits zero shall be interpreted as a null character
1338 independent of shift state.
1339
1340 * A byte with all bits zero shall not occur in the second or
1341 subsequent bytes of a multibyte character.
1342
1343 For the source character set, the following shall hold:
1344
1345 * A comment, string literal, character constant, or header name shall
1346 begin and end in the initial shift state.
1347
1348 * A comment, string literal, character constant, or header name shall
1349 consist of a sequence of valid multibyte characters.
1350
1351
13522.2.2 Character display semantics
1353
1354 The active position is that location on a display device where the
1355next character output by the fputc function would appear. The intent
1356of writing a printable character (as defined by the isprint function)
1357to a display device is to display a graphic representation of that
1358character at the active position and then advance the active position
1359to the next position on the current line. The direction of printing
1360is locale-specific. If the active position is at the final position
1361of a line (if there is one), the behavior is unspecified.
1362
1363 Alphabetic escape sequences representing nongraphic characters in
1364the execution character set are intended to produce actions on display
1365devices as follows: ( alert ) Produces an audible or visible alert.
1366The active position shall not be changed. ( backspace ) Moves the
1367active position to the previous position on the current line. If the
1368active position is at the initial position of a line, the behavior is
1369unspecified. ( "form feed" ) Moves the active position to the initial
1370position at the start of the next logical page. ( "new line" ) Moves
1371the active position to the initial position of the next line.
1372( "carriage return" ) Moves the active position to the initial position
1373of the current line. ( "horizontal tab" ) Moves the active position
1374to the next horizontal tabulation position on the current line. If
1375the active position is at or past the last defined horizontal
1376tabulation position, the behavior is unspecified. ( "vertical tab" )
1377Moves the active position to the initial position of the next vertical
1378tabulation position. If the active position is at or past the last
1379defined vertical tabulation position, the behavior is unspecified.
1380
1381 Each of these escape sequences shall produce a unique
1382implementation-defined value which can be stored in a single char
1383object. The external representations in a text file need not be
1384identical to the internal representations, and are outside the scope
1385of this Standard.
1386
1387Forward references: the fputc function ($4.9.7.3), the isprint
1388function ($4.3.1.7).
1389
1390
13912.2.3 Signals and interrupts
1392
1393 Functions shall be implemented such that they may be interrupted at
1394any time by a signal, or may be called by a signal handler, or both,
1395with no alteration to earlier, but still active, invocations' control
1396flow (after the interruption), function return values, or objects with
1397automatic storage duration. All such objects shall be maintained
1398outside the function image (the instructions that comprise the
1399executable representation of a function) on a per-invocation basis.
1400
1401 The functions in the standard library are not guaranteed to be
1402reentrant and may modify objects with static storage duration.
1403
1404
14052.2.4 Environmental limits
1406
1407 Both the translation and execution environments constrain the
1408implementation of language translators and libraries. The following
1409summarizes the environmental limits on a conforming implementation.
1410
1411
14122.2.4.1 Translation limits
1413
1414 The implementation shall be able to translate and execute at least
1415one program that contains at least one instance of every one of the
1416following limits:/6/
1417
1418 * 15 nesting levels of compound statements, iteration control
1419 structures, and selection control structures
1420
1421 * 8 nesting levels of conditional inclusion
1422
1423 * 12 pointer, array, and function declarators (in any combinations)
1424 modifying an arithmetic, a structure, a union, or an incomplete type
1425 in a declaration
1426
1427 * 31 declarators nested by parentheses within a full declarator
1428
1429 * 32 expressions nested by parentheses within a full expression
1430
1431 * 31 significant initial characters in an internal identifier or a
1432 macro name
1433
1434 * 6 significant initial characters in an external identifier
1435
1436 * 511 external identifiers in one translation unit
1437
1438 * 127 identifiers with block scope declared in one block
1439
1440 * 1024 macro identifiers simultaneously defined in one translation unit
1441
1442 * 31 parameters in one function definition
1443
1444 * 31 arguments in one function call
1445
1446 * 31 parameters in one macro definition
1447
1448 * 31 arguments in one macro invocation
1449
1450 * 509 characters in a logical source line
1451
1452 * 509 characters in a character string literal or wide string literal
1453 (after concatenation)
1454
1455 * 32767 bytes in an object (in a hosted environment only)
1456
1457 * 8 nesting levels for #include'd files
1458
1459 * 257 case labels for a switch statement (excluding those for any
1460 nested switch statements)
1461
1462 * 127 members in a single structure or union
1463
1464 * 127 enumeration constants in a single enumeration
1465
1466 * 15 levels of nested structure or union definitions in a single
1467 struct-declaration-list
1468
1469
14702.2.4.2 Numerical limits
1471
1472 A conforming implementation shall document all the limits specified
1473in this section, which shall be specified in the headers <limits.h>
1474and <float.h> .
1475
1476"Sizes of integral types <limits.h>"
1477
1478 The values given below shall be replaced by constant expressions
1479suitable for use in #if preprocessing directives. Their
1480implementation-defined values shall be equal or greater in magnitude
1481(absolute value) to those shown, with the same sign.
1482
1483 * maximum number of bits for smallest object that is not a bit-field (byte)
1484CHAR_BIT 8
1485
1486 * minimum value for an object of type signed char
1487SCHAR_MIN -127
1488
1489 * maximum value for an object of type signed char
1490SCHAR_MAX +127
1491
1492 * maximum value for an object of type unsigned char
1493UCHAR_MAX 255
1494
1495 * minimum value for an object of type char
1496CHAR_MIN see below
1497
1498 * maximum value for an object of type char
1499CHAR_MAX see below
1500
1501 * maximum number of bytes in a multibyte character, for any supported locale
1502MB_LEN_MAX 1
1503
1504 * minimum value for an object of type short int
1505SHRT_MIN -32767
1506
1507 * maximum value for an object of type short int
1508SHRT_MAX +32767
1509
1510 * maximum value for an object of type unsigned short int
1511USHRT_MAX 65535
1512
1513 * minimum value for an object of type int
1514INT_MIN -32767
1515
1516 * maximum value for an object of type int
1517INT_MAX +32767
1518
1519 * maximum value for an object of type unsigned int
1520UINT_MAX 65535
1521
1522 * minimum value for an object of type long int
1523LONG_MIN -2147483647
1524
1525 * maximum value for an object of type long int
1526LONG_MAX +2147483647
1527
1528 * maximum value for an object of type unsigned long int
1529ULONG_MAX 4294967295
1530
1531 If the value of an object of type char sign-extends when used in an
1532expression, the value of CHAR_MIN shall be the same as that of
1533SCHAR_MIN and the value of CHAR_MAX shall be the same as that of
1534SCHAR_MAX . If the value of an object of type char does not
1535sign-extend when used in an expression, the value of CHAR_MIN shall be
15360 and the value of CHAR_MAX shall be the same as that of UCHAR_MAX
1537./7/
1538
1539"Characteristics of floating types <float.h>"
1540
1541 delim $$ The characteristics of floating types are defined in terms
1542of a model that describes a representation of floating-point numbers
1543and values that provide information about an implementation's
1544floating-point arithmetic. The following parameters are used to
1545define the model for each floating-point type:
1546
1547 A normalized floating-point number x ($f sub 1$ > 0 if x is defined
1548by the following model:/8/ $x~=~s~times~b sup e~times~sum from k=1 to
1549p~f sub k~times~b sup -k~,~~~e sub min~<=~e~<=~e sub max$
1550
1551 Of the values in the <float.h> header, FLT_RADIX shall be a
1552constant expression suitable for use in #if preprocessing directives;
1553all other values need not be constant expressions. All except
1554FLT_RADIX and FLT_ROUNDS have separate names for all three
1555floating-point types. The floating-point model representation is
1556provided for all values except FLT_ROUNDS .
1557
1558 The rounding mode for floating-point addition is characterized by
1559the value of FLT_ROUNDS : -1 indeterminable, 0 toward zero, 1 to nearest,
15602 toward positive infinity, 3 toward negative infinity. All other values
1561for FLT_ROUNDS characterize implementation-defined rounding behavior.
1562
1563 The values given in the following list shall be replaced by
1564implementation-defined expressions that shall be equal or greater in
1565magnitude (absolute value) to those shown, with the same sign.
1566
1567 * radix of exponent representation, b
1568FLT_RADIX 2
1569
1570 * number of base- FLT_RADIX digits in the floating-point mantissa, p
1571
1572FLT_MANT_DIG
1573DBL_MANT_DIG
1574LDBL_MANT_DIG
1575
1576
1577
1578 * number of decimal digits of precision, $left floor~(p~-~1)~times~{
1579 log sub 10 } b~right floor ~+~ left { lpile { 1 above 0 } ~~ lpile {
1580 roman "if " b roman " is a power of 10" above roman otherwise }$
1581
1582FLT_DIG 6
1583DBL_DIG 10
1584LDBL_DIG 10
1585
1586
1587
1588 * minimum negative integer such that FLT_RADIX raised to that power
1589 minus 1 is a normalized floating-point number, $e sub min$
1590
1591FLT_MIN_EXP
1592DBL_MIN_EXP
1593LDBL_MIN_EXP
1594
1595
1596
1597 * minimum negative integer such that 10 raised to that power is in
1598 the range of normalized floating-point numbers,
1599
1600FLT_MIN_10_EXP -37
1601DBL_MIN_10_EXP -37
1602LDBL_MIN_10_EXP -37
1603
1604
1605
1606 * maximum integer such that FLT_RADIX raised to that power minus 1 is
1607 a representable finite floating-point number, $e sub max$
1608
1609FLT_MAX_EXP
1610DBL_MAX_EXP
1611LDBL_MAX_EXP
1612
1613
1614
1615 * maximum integer such that 10 raised to that power is in the range
1616 of representable finite floating-point numbers,
1617
1618FLT_MAX_10_EXP +37
1619DBL_MAX_10_EXP +37
1620LDBL_MAX_10_EXP +37
1621
1622
1623 The values given in the following list shall be replaced by
1624implementation-defined expressions with values that shall be equal to
1625or greater than those shown.
1626
1627 * maximum representable finite floating-point number,
1628
1629FLT_MAX 1E+37
1630DBL_MAX 1E+37
1631LDBL_MAX 1E+37
1632
1633
1634 The values given in the following list shall be replaced by
1635implementation-defined expressions with values that shall be equal to
1636or smaller than those shown.
1637
1638 * minimum positive floating-point number x such that 1.0 + x
1639
1640FLT_EPSILON 1E-5
1641DBL_EPSILON 1E-9
1642LDBL_EPSILON 1E-9
1643
1644
1645
1646 * minimum normalized positive floating-point number, $b sup { e sub
1647 min - 1 }$
1648
1649FLT_MIN 1E-37
1650DBL_MIN 1E-37
1651LDBL_MIN 1E-37
1652
1653
1654
1655Examples
1656
1657 The following describes an artificial floating-point representation
1658that meets the minimum requirements of the Standard, and the
1659appropriate values in a <float.h> header for type float :
1660$x~=~s~times~16 sup e~times~sum from k=1 to 6~f sub k~times~16 sup
1661-k~,~~~-31~<=~e~<=~+32$
1662
1663
1664 FLT_RADIX 16
1665 FLT_MANT_DIG 6
1666 FLT_EPSILON 9.53674316E-07F
1667 FLT_DIG 6
1668 FLT_MIN_EXP -31
1669 FLT_MIN 2.93873588E-39F
1670 FLT_MIN_10_EXP -38
1671 FLT_MAX_EXP +32
1672 FLT_MAX 3.40282347E+38F
1673 FLT_MAX_10_EXP +38
1674
1675
1676 The following describes floating-point representations that also
1677meet the requirements for single-precision and double-precision
1678normalized numbers in the IEEE Standard for Binary Floating-Point
1679Arithmetic (ANSI/IEEE Std 754-1985),/9/ b and the appropriate values
1680in a <float.h> header for types float and double : $x sub
1681f~=~s~times~2 sup e~times~{ sum from k=1 to 24~f sub k~times~2 sup -k
1682},~~~-125~<=~e~<=~+128$ $x sub d~=~s~times~2 sup e~times~{ sum from
1683k=1 to 53~f sub k~times~2 sup -k },~~~-1021~<=~e~<=~+1024$
1684
1685
1686 FLT_RADIX 2
1687 FLT_MANT_DIG 24
1688 FLT_EPSILON 1.19209290E-07F
1689 FLT_DIG 6
1690 FLT_MIN_EXP -125
1691 FLT_MIN 1.17549435E-38F
1692 FLT_MIN_10_EXP -37
1693 FLT_MAX_EXP +128
1694 FLT_MAX 3.40282347E+38F
1695 FLT_MAX_10_EXP +38
1696 DBL_MANT_DIG 53
1697 DBL_EPSILON 2.2204460492503131E-16
1698 DBL_DIG 15
1699 DBL_MIN_EXP -1021
1700 DBL_MIN 2.2250738585072016E-308
1701 DBL_MIN_10_EXP -307
1702 DBL_MAX_EXP +1024
1703 DBL_MAX 1.7976931348623157E+308
1704 DBL_MAX_10_EXP +308
1705
1706
1707 The values shown above for FLT_EPSILON and DBL_EPSILON are
1708appropriate for the ANSI/IEEE Std 754-1985 default rounding mode (to
1709nearest). Their values may differ for other rounding modes.
1710
1711Forward references: conditional inclusion ($3.8.1). conditional
1712inclusion ($3.8.1).
1713
1714
17153. LANGUAGE
1716
1717 In the syntax notation used in the language section ($3), syntactic
1718categories (nonterminals) are indicated by italic type, and literal
1719words and character set members (terminals) by bold type. A colon (:)
1720following a nonterminal introduces its definition. Alternative
1721definitions are listed on separate lines, except when prefaced by the
1722words ``one of.'' An optional symbol is indicated by the so that
1723
1724 { expression<opt> }
1725
1726indicates an optional expression enclosed in braces.
1727
17283.1 LEXICAL ELEMENTS
1729
1730
1731Syntax
1732
1733 token:
1734 keyword
1735 identifier
1736 constant
1737 string-literal
1738 operator
1739 punctuator
1740
1741 preprocessing-token:
1742 header-name
1743 identifier
1744 pp-number
1745 character-constant
1746 string-literal
1747 operator
1748 punctuator
1749 each non-white-space character that cannot be one of
1750 the above
1751
1752
1753
1754Constraints
1755
1756 Each preprocessing token that is converted to a token shall have
1757the lexical form of a keyword, an identifier, a constant, a string
1758literal, an operator, or a punctuator.
1759
1760Semantics
1761
1762 A token is the minimal lexical element of the language in
1763translation phases 7 and 8. The categories of tokens are: keywords,
1764identifiers, constants, string literals, operators, and punctuators.
1765A preprocessing token is the minimal lexical element of the language
1766in translation phases 3 through 6. The categories of preprocessing
1767token are: header names, identifiers, preprocessing numbers,
1768character constants, string literals, operators, punctuators, and
1769single non-white-space characters that do not lexically match the
1770other preprocessing token categories. If a ' or a character matches
1771the last category, the behavior is undefined. Comments (described
1772later) and the characters space, horizontal tab, new-line, vertical
1773tab, and form-feed---collectively called white space ---canseparate
1774preprocessing tokens. As described in $3.8, in certain circumstances
1775during translation phase 4, white space (or the absence thereof)
1776serves as more than preprocessing token separation. White space may
1777appear within a preprocessing token only as part of a header name or
1778between the quotation characters in a character constant or string
1779literal.
1780
1781 If the input stream has been parsed into preprocessing tokens up to
1782a given character, the next preprocessing token is the longest
1783sequence of characters that could constitute a preprocessing token.
1784
1785Examples
1786
1787 The program fragment 1Ex is parsed as a preprocessing number token
1788(one that is not a valid floating or integer constant token), even
1789though a parse as the pair of preprocessing tokens 1 and Ex might
1790produce a valid expression (for example, if Ex were a macro defined as
1791+1 ). Similarly, the program fragment 1E1 is parsed as a
1792preprocessing number (one that is a valid floating constant token),
1793whether or not E is a macro name.
1794
1795 The program fragment x+++++y is parsed as x ++ ++ + y, which
1796violates a constraint on increment operators, even though the parse x
1797++ + ++ y might yield a correct expression.
1798
1799Forward references: character constants ($3.1.3.4), comments ($3.1.9),
1800expressions ($3.3), floating constants ($3.1.3.1), header names
1801($3.1.7), macro replacement ($3.8.3), postfix increment and decrement
1802operators ($3.3.2.4), prefix increment and decrement operators
1803($3.3.3.1), preprocessing directives ($3.8), preprocessing numbers
1804($3.1.8), string literals ($3.1.4).
1805
1806
18073.1.1 Keywords
1808
1809Syntax
1810
1811 keyword: one of
1812
1813 auto double int struct
1814 break else long switch
1815 case enum register typedef
1816 char extern return union
1817 const float short unsigned
1818 continue for signed void
1819 default goto sizeof volatile
1820 do if static while
1821
1822
1823
1824Semantics
1825
1826 The above tokens (entirely in lower-case) are reserved (in
1827translation phases 7 and 8) for use as keywords, and shall not be used
1828otherwise.
1829
1830
18313.1.2 Identifiers
1832
1833Syntax
1834
1835 identifier:
1836 nondigit
1837 identifier nondigit
1838 identifier digit
1839
1840
1841
1842 nondigit: one of
1843 _ a b c d e f g h i j k l m
1844 n o p q r s t u v w x y z
1845 A B C D E F G H I J K L M
1846 N O P Q R S T U V W X Y Z
1847
1848
1849
1850 digit: one of
1851 0 1 2 3 4 5 6 7 8 9
1852
1853
1854
1855Description
1856
1857 An identifier is a sequence of nondigit characters (including the
1858underscore _ and the lower-case and upper-case letters) and digits.
1859The first character shall be a nondigit character.
1860
1861Constraints
1862
1863 In translation phases 7 and 8, an identifier shall not consist of
1864the same sequence of characters as a keyword.
1865
1866Semantics
1867
1868 An identifier denotes an object, a function, or one of the
1869following entities that will be described later: a tag or a member of
1870a structure, union, or enumeration; a typedef name; a label name; a
1871macro name; or a macro parameter. A member of an enumeration is
1872called an enumeration constant. Macro names and macro parameters are
1873not considered further here, because prior to the semantic phase of
1874program translation any occurrences of macro names in the source file
1875are replaced by the preprocessing token sequences that constitute
1876their macro definitions.
1877
1878 There is no specific limit on the maximum length of an identifier.
1879
1880"Implementation limits"
1881
1882 The implementation shall treat at least the first 31 characters of
1883an internal name (a macro name or an identifier that does not have
1884external linkage) as significant. Corresponding lower-case and
1885upper-case letters are different. The implementation may further
1886restrict the significance of an external name (an identifier that has
1887external linkage) to six characters and may ignore distinctions of
1888alphabetical case for such names./10/ These limitations on identifiers
1889are all implementation-defined.
1890
1891 Any identifiers that differ in a significant character are
1892different identifiers. If two identifiers differ in a non-significant
1893character, the behavior is undefined.
1894
1895Forward references: linkages of identifiers ($3.1.2.2), macro
1896replacement ($3.8.3).
1897
1898
18993.1.2.1 Scopes of identifiers
1900
1901 An identifier is visible (i.e., can be used) only within a region
1902of program text called its scope . There are four kinds of scopes:
1903function, file, block, and function prototype. (A function prototype
1904is a declaration of a function that declares the types of its
1905parameters.)
1906
1907 A label name is the only kind of identifier that has function scope.
1908It can be used (in a goto statement) anywhere in the function in
1909which it appears, and is declared implicitly by its syntactic
1910appearance (followed by a : and a statement). Label names shall be
1911unique within a function.
1912
1913 Every other identifier has scope determined by the placement of its
1914declaration (in a declarator or type specifier). If the declarator or
1915type specifier that declares the identifier appears outside of any
1916block or list of parameters, the identifier has file scope, which
1917terminates at the end of the translation unit. If the declarator or
1918type specifier that declares the identifier appears inside a block or
1919within the list of parameter declarations in a function definition,
1920the identifier has block scope, which terminates at the } that closes
1921the associated block. If the declarator or type specifier that
1922declares the identifier appears within the list of parameter
1923declarations in a function prototype (not part of a function
1924definition), the identifier has function prototype scope ,which
1925terminates at the end of the function declarator. If an outer
1926declaration of a lexically identical identifier exists in the same
1927name space, it is hidden until the current scope terminates, after
1928which it again becomes visible.
1929
1930 Structure, union, and enumeration tags have scope that begins just
1931after the appearance of the tag in a type specifier that declares the
1932tag. Each enumeration constant has scope that begins just after the
1933appearance of its defining enumerator in an enumerator list. Any
1934other identifier has scope that begins just after the completion of
1935its declarator.
1936
1937Forward references: compound statement, or block ($3.6.2),
1938declarations ($3.5), enumeration specifiers ($3.5.2.2), function calls
1939($3.3.2.2), function declarators (including prototypes) ($3.5.4.3),
1940function definitions ($3.7.1), the goto statement ($3.6.6.1), labeled
1941statements ($3.6.1), name spaces of identifiers ($3.1.2.3), scope of
1942macro definitions ($3.8.3.5), source file inclusion ($3.8.2), tags
1943($3.5.2.3), type specifiers ($3.5.2).
1944
19453.1.2.2 Linkages of identifiers
1946
1947 An identifier declared in different scopes or in the same scope
1948more than once can be made to refer to the same object or function by
1949a process called linkage . There are three kinds of linkage: external,
1950internal, and none.
1951
1952 In the set of translation units and libraries that constitutes an
1953entire program, each instance of a particular identifier with external
1954linkage denotes the same object or function. Within one translation
1955unit, each instance of an identifier with internal linkage denotes the
1956same object or function. Identifiers with no linkage denote unique
1957entities.
1958
1959 If the declaration of an identifier for an object or a function has
1960file scope and contains the storage-class specifier static, the
1961identifier has internal linkage.
1962
1963 If the declaration of an identifier for an object or a function
1964contains the storage-class specifier extern , the identifier has the
1965same linkage as any visible declaration of the identifier with file
1966scope. If there is no visible declaration with file scope, the
1967identifier has external linkage.
1968
1969 If the declaration of an identifier for a function has no
1970storage-class specifier, its linkage is determined exactly as if it
1971were declared with the storage-class specifier extern . If the
1972declaration of an identifier for an object has file scope and no
1973storage-class specifier, its linkage is external.
1974
1975 The following identifiers have no linkage: an identifier declared
1976to be anything other than an object or a function; an identifier
1977declared to be a function parameter; an identifier declared to be an
1978object inside a block without the storage-class specifier extern.
1979
1980 If, within a translation unit, the same identifier appears with
1981both internal and external linkage, the behavior is undefined.
1982
1983Forward references: compound statement, or block ($3.6.2),
1984declarations ($3.5), expressions ($3.3), external definitions ($3.7).
1985
1986
19873.1.2.3 Name spaces of identifiers
1988
1989 If more than one declaration of a particular identifier is visible
1990at any point in a translation unit, the syntactic context
1991disambiguates uses that refer to different entities. Thus, there are
1992separate name spaces for various categories of identifiers, as
1993follows:
1994
1995 * label names (disambiguated by the syntax of the label declaration
1996 and use);
1997
1998 * the tags of structures, unions, and enumerations (disambiguated by
1999 following any/11/ of the keywords struct , union , or enum );
2000
2001 * the members of structures or unions; each structure or union has a
2002 separate name space for its members (disambiguated by the type of the
2003 expression used to access the member via the . or -> operator);
2004
2005 * all other identifiers, called ordinary identifiers (declared in
2006 ordinary declarators or as enumeration constants).
2007
2008Forward references: declarators ($3.5.4), enumeration specifiers
2009($3.5.2.2), labeled statements ($3.6.1), structure and union
2010specifiers ($3.5.2.1), structure and union members ($3.3.2.3), tags
2011($3.5.2.3).
2012
2013
20143.1.2.4 Storage durations of objects
2015
2016 An object has a storage duration that determines its lifetime.
2017There are two storage durations: static and automatic.
2018
2019 An object declared with external or internal linkage, or with the
2020storage-class specifier static has static storage duration. For such
2021an object, storage is reserved and its stored value is initialized
2022only once, prior to program startup. The object exists and retains
2023its last-stored value throughout the execution of the entire
2024program./12/
2025
2026 An object declared with no linkage and without the storage-class
2027specifier static has automatic storage duration. Storage is guaranteed
2028to be reserved for a new instance of such an object on each normal
2029entry into the block in which it is declared, or on a jump from
2030outside the block to a label in the block or in an enclosed block. If
2031an initialization is specified for the value stored in the object, it
2032is performed on each normal entry, but not if the block is entered by
2033a jump to a label. Storage for the object is no longer guaranteed to
2034be reserved when execution of the block ends in any way. (Entering an
2035enclosed block suspends but does not end execution of the enclosing
2036block. Calling a function that returns suspends but does not end
2037execution of the block containing the call.) The value of a pointer
2038that referred to an object with automatic storage duration that is no
2039longer guaranteed to be reserved is indeterminate.
2040
2041Forward references: compound statement, or block ($3.6.2), function
2042calls ($3.3.2.2), initialization ($3.5.7).
2043
2044
20453.1.2.5 Types
2046
2047 The meaning of a value stored in an object or returned by a
2048function is determined by the type of the expression used to access
2049it. (An identifier declared to be an object is the simplest such
2050expression; the type is specified in the declaration of the
2051identifier.) Types are partitioned into object types (types that
2052describe objects), function types (types that describe functions), and
2053incomplete types (types that describe objects but lack information
2054needed to determine their sizes).
2055
2056 An object declared as type char is large enough to store any member
2057of the basic execution character set. If a member of the required
2058source character set enumerated in $2.2.1 is stored in a char object,
2059its value is guaranteed to be positive. If other quantities are
2060stored in a char object, the behavior is implementation-defined: the
2061values are treated as either signed or nonnegative integers.
2062
2063 There are four signed integer types, designated as signed char,
2064short int, int, and long int. (The signed integer and other types
2065may be designated in several additional ways, as described in $3.5.2.)
2066
2067 An object declared as type signed char occupies the same amount of
2068storage as a ``plain'' char object. A ``plain'' int object has the
2069natural size suggested by the architecture of the execution
2070environment (large enough to contain any value in the range INT_MIN to
2071INT_MAX as defined in the header <limits.h> ). In the list of signed
2072integer types above, the range of values of each type is a subrange of
2073the values of the next type in the list.
2074
2075 For each of the signed integer types, there is a corresponding (but
2076different) unsigned integer type (designated with the keyword unsigned)
2077that uses the same amount of storage (including sign information)
2078and has the same alignment requirements. The range of nonnegative
2079values of a signed integer type is a subrange of the corresponding
2080unsigned integer type, and the representation of the same value in
2081each type is the same. A computation involving unsigned operands can
2082never overflow, because a result that cannot be represented by the
2083resulting unsigned integer type is reduced modulo the number that is
2084one greater than the largest value that can be represented by the
2085resulting unsigned integer type.
2086
2087 There are three floating types, designated as float , double , and
2088long double . The set of values of the type float is a subset of the
2089set of values of the type double ; the set of values of the type
2090double is a subset of the set of values of the type long double.
2091
2092 The type char, the signed and unsigned integer types, and the
2093floating types are collectively called the basic types. Even if the
2094implementation defines two or more basic types to have the same
2095representation, they are nevertheless different types.
2096
2097 There are three character types, designated as char , signed char ,
2098and unsigned char.
2099
2100 An enumeration comprises a set of named integer constant values.
2101Each distinct enumeration constitutes a different enumerated type.
2102
2103 The void type comprises an empty set of values; it is an incomplete
2104type that cannot be completed.
2105
2106 Any number of derived types can be constructed from the basic,
2107enumerated, and incomplete types, as follows:
2108
2109 * An array type describes a contiguously allocated set of objects
2110 with a particular member object type, called the element type .Array
2111 types are characterized by their element type and by the number of
2112 members of the array. An array type is said to be derived from its
2113 element type, and if its element type is T , the array type is
2114 sometimes called ``array of T .'' The construction of an array type
2115 from an element type is called ``array type derivation.''
2116
2117 * A structure type describes a sequentially allocated set of member
2118 objects, each of which has an optionally specified name and possibly
2119 distinct type.
2120
2121 * A union type describes an overlapping set of member objects, each
2122 of which has an optionally specified name and possibly distinct type.
2123
2124 * A function type describes a function with specified return type. A
2125 function type is characterized by its return type and the number and
2126 types of its parameters. A function type is said to be derived from
2127 its return type, and if its return type is T , the function type is
2128 sometimes called ``function returning T.'' The construction of a
2129 function type from a return type is called ``function type
2130 derivation.''
2131
2132 * A pointer type may be derived from a function type, an object type,
2133 or an incomplete type, called the referenced type. A pointer type
2134 describes an object whose value provides a reference to an entity of
2135 the referenced type. A pointer type derived from the referenced type
2136 T is sometimes called ``pointer to T .'' The construction of a pointer
2137 type from a referenced type is called ``pointer type derivation.''
2138
2139 These methods of constructing derived types can be applied
2140recursively.
2141
2142 The type char, the signed and unsigned integer types, and the
2143enumerated types are collectively called integral types. The
2144representations of integral types shall define values by use of a pure
2145binary numeration system./13/ American National Dictionary for
2146Information Processing Systems.) The representations of floating types
2147are unspecified.
2148
2149 Integral and floating types are collectively called arithmetic
2150types. Arithmetic types and pointer types are collectively called
2151scalar types. Array and structure types are collectively called
2152aggregate types. /14/
2153
2154 A pointer to void shall have the same representation and alignment
2155requirements as a pointer to a character type. Other pointer types
2156need not have the same representation or alignment requirements.
2157
2158 An array type of unknown size is an incomplete type. It is
2159completed, for an identifier of that type, by specifying the size in a
2160later declaration (with internal or external linkage). A structure or
2161union type of unknown content (as described in $3.5.2.3) is an
2162incomplete type. It is completed, for all declarations of that type,
2163by declaring the same structure or union tag with its defining content
2164later in the same scope.
2165
2166 Array, function, and pointer types are collectively called derived
2167declarator types. A declarator type derivation from a type T is the
2168construction of a derived declarator type from T by the application of
2169an array, a function, or a pointer type derivation to T.
2170
2171 A type is characterized by its top type, which is either the first
2172type named in describing a derived type (as noted above in the
2173construction of derived types), or the type itself if the type
2174consists of no derived types.
2175
2176 A type has qualified type if its top type is specified with a type
2177qualifier; otherwise it has unqualified type .The type qualifiers
2178const and volatile respectively designate const-qualified type and
2179volatile-qualified type. /15/ For each qualified type there is an
2180unqualified type that is specified the same way as the qualified type,
2181but without any type qualifiers in its top type. This type is known
2182as the unqualified version of the qualified type. Similarly, there
2183are appropriately qualified versions of types (such as a
2184const-qualified version of a type), just as there are appropriately
2185non-qualified versions of types (such as a non-const-qualified version
2186of a type).
2187
2188Examples
2189
2190 The type designated as ``float *'' is called ``pointer to float''
2191and its top type is a pointer type, not a floating type. The
2192const-qualified version of this type is designated as ``float * const''
2193whereas the type designated as `` const float * '' is not a
2194qualified type --- it is called ``pointer to const float '' and is a
2195pointer to a qualified type.
2196
2197 Finally, the type designated as `` struct tag (*[5])(float) '' is
2198called ``array of pointer to function returning struct tag.'' Its top
2199type is array type. The array has length five and the function has a
2200single parameter of type float.
2201
2202Forward references: character constants ($3.1.3.4), declarations
2203($3.5), tags ($3.5.2.3), type qualifiers ($3.5.3).
2204
2205
22063.1.2.6 Compatible type and composite type
2207
2208 Two types have compatible type if their types are the same.
2209Additional rules for determining whether two types are compatible are
2210described in $3.5.2 for type specifiers, in $3.5.3 for type
2211qualifiers, and in $3.5.4 for declarators. /16/ Moreover, two
2212structure, union, or enumeration types declared in separate
2213translation units are compatible if they have the same number of
2214members, the same member names, and compatible member types; for two
2215structures, the members shall be in the same order; for two
2216enumerations, the members shall have the same values.
2217
2218 All declarations that refer to the same object or function shall
2219have compatible type; otherwise the behavior is undefined.
2220
2221 A composite type can be constructed from two types that are
2222compatible; it is a type that is compatible with both of the two types
2223and has the following additions:
2224
2225 * If one type is an array of known size, the composite type is an
2226 array of that size.
2227
2228 * If only one type is a function type with a parameter type list (a
2229 function prototype), the composite type is a function prototype with
2230 the parameter type list.
2231
2232 * If both types have parameter type lists, the type of each parameter
2233 in the composite parameter type list is the composite type of the
2234 corresponding parameters.
2235
2236 These rules apply recursively to the types from which the two types
2237are derived.
2238
2239 For an identifier with external or internal linkage declared in the
2240same scope as another declaration for that identifier, the type of the
2241identifier becomes the composite type.
2242
2243Example
2244
2245 Given the following two file scope declarations:
2246
2247 int f(int (*)(), double (*)[3]);
2248 int f(int (*)(char *), double (*)[]);
2249
2250The resulting composite type for the function is:
2251
2252 int f(int (*)(char *), double (*)[3]);
2253
2254Forward references: declarators ($3.5.4), enumeration specifiers
2255($3.5.2.2), structure and union specifiers ($3.5.2.1), type
2256definitions ($3.5.6), type qualifiers ($3.5.3), type specifiers
2257($3.5.2).
2258
2259
22603.1.3 Constants
2261
2262Syntax
2263
2264 constant:
2265 floating-constant
2266 integer-constant
2267 enumeration-constant
2268 character-constant
2269
2270Constraints
2271
2272 The value of a constant shall be in the range of representable
2273values for its type.
2274
2275Semantics
2276
2277 Each constant has a type, determined by its form and value, as
2278detailed later.
2279
2280
22813.1.3.1 Floating constants
2282
2283Syntax
2284
2285 floating-constant:
2286 fractional-constant exponent-part<opt> floating-suffix<opt>
2287 digit-sequence exponent-part floating-suffix<opt>
2288
2289 fractional-constant:
2290 digit-sequence<opt>.digit-sequence
2291 digit-sequence.
2292
2293 exponent-part:
2294 e sign<opt> digit-sequence
2295 E sign<opt> digit-sequence
2296
2297 sign: one of
2298 + -
2299
2300 digit-sequence:
2301 digit
2302 digit-sequence digit
2303
2304 floating-suffix: one of
2305 f l F L
2306
2307Description
2308
2309 A floating constant has a value part that may be followed by an
2310exponent part and a suffix that specifies its type. The components of
2311the value part may include a digit sequence representing the
2312whole-number part, followed by a period (.), followed by a digit
2313sequence representing the fraction part. The components of the
2314exponent part are an e or E followed by an exponent consisting of an
2315optionally signed digit sequence. Either the whole-number part or the
2316fraction part shall be present; either the period or the exponent part
2317shall be present.
2318
2319Semantics
2320
2321 The value part is interpreted as a decimal rational number; the
2322digit sequence in the exponent part is interpreted as a decimal
2323integer. The exponent indicates the power of 10 by which the value
2324part is to be scaled. If the scaled value is in the range of
2325representable values (for its type) but cannot be represented exactly,
2326the result is either the nearest higher or nearest lower value, chosen
2327in an implementation-defined manner.
2328
2329 An unsuffixed floating constant has type double. If suffixed by
2330the letter f or F, it has type float. If suffixed by the letter l
2331or L, it has type long double.
2332
2333
23343.1.3.2 Integer constants
2335
2336Syntax
2337
2338 integer-constant:
2339 decimal-constant integer-suffix<opt>
2340 octal-constant integer-suffix<opt>
2341 hexadecimal-constant integer-suffix<opt>
2342
2343 decimal-constant:
2344 nonzero-digit
2345 decimal-constant digit
2346
2347 octal-constant:
2348 0
2349 octal-constant octal-digit
2350
2351 hexadecimal-constant:
2352 0x hexadecimal-digit
2353 0X hexadecimal-digit
2354 hexadecimal-constant hexadecimal-digit
2355
2356 nonzero-digit: one of
2357 1 2 3 4 5 6 7 8 9
2358
2359 octal-digit: one of
2360 0 1 2 3 4 5 6 7
2361
2362 hexadecimal-digit: one of
2363 0 1 2 3 4 5 6 7 8 9
2364 a b c d e f
2365 A B C D E F
2366
2367 integer-suffix:
2368 unsigned-suffix long-suffix<opt>
2369 long-suffix unsigned-suffix<opt>
2370
2371 unsigned-suffix: one of
2372 u U
2373
2374 long-suffix: one of
2375 l L
2376
2377Description
2378
2379 An integer constant begins with a digit, but has no period or
2380exponent part. It may have a prefix that specifies its base and a
2381suffix that specifies its type.
2382
2383 A decimal constant begins with a nonzero digit and consists of a
2384sequence of decimal digits. An octal constant consists of the prefix
23850 optionally followed by a sequence of the digits 0 through 7 only. A
2386hexadecimal constant consists of the prefix 0x or 0X followed by a
2387sequence of the decimal digits and the letters a (or A ) through f (or
2388F) with values 10 through 15 respectively.
2389
2390Semantics
2391
2392 The value of a decimal constant is computed base 10; that of an
2393octal constant, base 8; that of a hexadecimal constant, base 16. The
2394lexically first digit is the most significant.
2395
2396 The type of an integer constant is the first of the corresponding
2397list in which its value can be represented. Unsuffixed decimal: int,
2398long int, unsigned long int; unsuffixed octal or hexadecimal: int,
2399unsigned int, long int, unsigned long int; suffixed by the letter u
2400or U: unsigned int, unsigned long int; suffixed by the letter l or
2401L: long int, unsigned long int; suffixed by both the letters u or U
2402and l or L: unsigned long int .
2403
2404
24053.1.3.3 Enumeration constants
2406
2407Syntax
2408
2409 enumeration-constant:
2410 identifier
2411
2412Semantics
2413
2414 An identifier declared as an enumeration constant has type int.
2415
2416Forward references: enumeration specifiers ($3.5.2.2).
2417
2418
24193.1.3.4 Character constants
2420
2421Syntax
2422
2423 character-constant:
2424 ' c-char-sequence'
2425 L' c-char-sequence'
2426
2427 c-char-sequence:
2428 c-char
2429 c-char-sequence c-char
2430
2431 c-char:
2432 any member of the source character set except
2433 the single-quote ', backslash \, or new-line character
2434 escape-sequence
2435
2436 escape-sequence:
2437 simple-escape-sequence
2438 octal-escape-sequence
2439 hexadecimal-escape-sequence
2440
2441 simple-escape-sequence: one of
2442 \' \" \? \\
2443 \a \b \f \n \r \t \v
2444
2445 octal-escape-sequence:
2446 \ octal-digit
2447 \ octal-digit octal-digit
2448 \ octal-digit octal-digit octal-digit
2449
2450 hexadecimal-escape-sequence:
2451 \x hexadecimal-digit
2452 hexadecimal-escape-sequence hexadecimal-digit
2453
2454
2455
2456Description
2457
2458 An integer character constant is a sequence of one or more
2459multibyte characters enclosed in single-quotes, as in 'x' or 'ab'. A
2460wide character constant is the same, except prefixed by the letter L .
2461With a few exceptions detailed later, the elements of the sequence are
2462any members of the source character set; they are mapped in an
2463implementation-defined manner to members of the execution character
2464set.
2465
2466 The single-quote ', the double-quote , the question-mark ?, the
2467backslash \ , and arbitrary integral values, are representable
2468according to the following table of escape sequences:
2469
2470 single-quote ' \'
2471 double-quote " \"
2472 question-mark ? \?
2473 backslash \ \\
2474 octal integer \ octal digits
2475 hexadecimal integer \x hexadecimal digits
2476
2477 The double-quote and question-mark ? are representable either by
2478themselves or by the escape sequences \" and \? respectively, but the
2479single-quote ' and the backslash \ shall be represented, respectively,
2480by the escape sequences \' and \\ .
2481
2482 The octal digits that follow the backslash in an octal escape
2483sequence are taken to be part of the construction of a single
2484character for an integer character constant or of a single wide
2485character for a wide character constant. The numerical value of the
2486octal integer so formed specifies the value of the desired character.
2487
2488 The hexadecimal digits that follow the backslash and the letter x
2489in a hexadecimal escape sequence are taken to be part of the
2490construction of a single character for an integer character constant
2491or of a single wide character for a wide character constant. The
2492numerical value of the hexadecimal integer so formed specifies the
2493value of the desired character.
2494
2495 Each octal or hexadecimal escape sequence is the longest sequence
2496of characters that can constitute the escape sequence.
2497
2498 In addition, certain nongraphic characters are representable by
2499escape sequences consisting of the backslash \ followed by a
2500lower-case letter: \a , \b , \f , \n , \r , \t , and \v ./17/ If any
2501other escape sequence is encountered, the behavior is undefined./18/
2502
2503Constraints
2504
2505 The value of an octal or hexadecimal escape sequence shall be in
2506the range of representable values for the unsigned type corresponding
2507to its type.
2508
2509Semantics
2510
2511 An integer character constant has type int. The value of an
2512integer character constant containing a single character that maps
2513into a member of the basic execution character set is the numerical
2514value of the representation of the mapped character interpreted as an
2515integer. The value of an integer character constant containing more
2516than one character, or containing a character or escape sequence not
2517represented in the basic execution character set, is
2518implementation-defined. In particular, in an implementation in which
2519type char has the same range of values as signed char, the high-order
2520bit position of a single-character integer character constant is
2521treated as a sign bit.
2522
2523 A wide character constant has type wchar_t , an integral type
2524defined in the <stddef.h> header. The value of a wide character
2525constant containing a single multibyte character that maps into a
2526member of the extended execution character set is the wide character
2527(code) corresponding to that multibyte character, as defined by the
2528mbtowc function, with an implementation-defined current locale. The
2529value of a wide character constant containing more than one multibyte
2530character, or containing a multibyte character or escape sequence not
2531represented in the extended execution character set, is
2532implementation-defined.
2533
2534Examples
2535
2536 The construction '\0' is commonly used to represent the null character.
2537
2538 Consider implementations that use two's-complement representation
2539for integers and eight bits for objects that have type char. In an
2540implementation in which type char has the same range of values as
2541signed char, the integer character constant '\xFF' has the value if
2542type char has the same range of values as unsigned char, the
2543character constant '\xFF' has the value
2544
2545 Even if eight bits are used for objects that have type char , the
2546construction '\x123' specifies an integer character constant
2547containing only one character. (The value of this single-character
2548integer character constant is implementation-defined and violates the
2549above constraint.) To specify an integer character constant containing
2550the two characters whose values are 0x12 and '3', the construction
2551'\0223' may be used, since a hexadecimal escape sequence is terminated
2552only by a non-hexadecimal character. (The value of this two-character
2553integer character constant is implementation-defined also.)
2554
2555 Even if 12 or more bits are used for objects that have type wchar_t,
2556the construction L'\1234' specifies the implementation-defined value
2557that results from the combination of the values 0123 and '4'.
2558
2559Forward references: characters and integers ($3.2.1.1) common
2560definitions <stddef.h> ($4.1.5), the mbtowc function ($4.10.7.2).
2561
2562
25633.1.4 String literals
2564
2565Syntax
2566
2567 string-literal:
2568 " s-char-sequence<opt>"
2569 L" s-char-sequence<opt>"
2570
2571 s-char-sequence:
2572 s-char
2573 s-char-sequence s-char
2574
2575 s-char:
2576 any member of the source character set except
2577 the double-quote ", backslash \, or new-line character
2578 escape-sequence
2579
2580Description
2581
2582 A character string literal is a sequence of zero or more multibyte
2583characters enclosed in double-quotes, as in xyz. A wide string
2584literal is the same, except prefixed by the letter L.
2585
2586 The same considerations apply to each element of the sequence in a
2587character string literal or a wide string literal as if it were in an
2588integer character constant or a wide character constant, except that
2589the single-quote ' is representable either by itself or by the escape
2590sequence \', but the double-quote shall be represented by the escape
2591sequence \.
2592
2593Semantics
2594
2595 A character string literal has static storage duration and type
2596``array of char ,'' and is initialized with the given characters. A
2597wide string literal has static storage duration and type ``array of
2598wchar_t,'' and is initialized with the wide characters corresponding
2599to the given multibyte characters. Character string literals that are
2600adjacent tokens are concatenated into a single character string
2601literal. A null character is then appended. /19/ Likewise, adjacent
2602wide string literal tokens are concatenated into a single wide string
2603literal to which a code with value zero is then appended. If a
2604character string literal token is adjacent to a wide string literal
2605token, the behavior is undefined.
2606
2607 Identical string literals of either form need not be distinct. If
2608the program attempts to modify a string literal of either form, the
2609behavior is undefined.
2610
2611Example
2612
2613 This pair of adjacent character string literals
2614
2615 "\x12" "3"
2616
2617produces a single character string literal containing the two
2618characters whose values are \x12 and '3', because escape sequences are
2619converted into single members of the execution character set just
2620prior to adjacent string literal concatenation.
2621
2622Forward references: common definitions <stddef.h> ($4.1.5).
2623
2624
26253.1.5 Operators
2626
2627Syntax
2628
2629 operator: one of
2630 [ ] ( ) . ->
2631 ++ -- & * + - ~ ! sizeof
2632 / % << >> < > <= >= == != ^ | && ||
2633 ? :
2634 = *= /= %= += -= <<= >>= &= ^= |=
2635 , # ##
2636
2637Constraints
2638
2639 The operators [ ] , ( ) , and ? : shall occur in pairs, possibly
2640separated by expressions. The operators # and ## shall occur in
2641macro-defining preprocessing directives only.
2642
2643Semantics
2644
2645 An operator specifies an operation to be performed (an evaluation )
2646that yields a value, or yields a designator, or produces a side
2647effect, or a combination thereof. An operand is an entity on which an
2648operator acts.
2649
2650Forward references: expressions ($3.3), macro replacement ($3.8.3).
2651
26523.1.6 Punctuators
2653
2654
2655Syntax
2656
2657 punctuator: one of
2658 [ ] ( ) { } * , : = ; ... #
2659
2660Constraints
2661
2662 The punctuators [ ] , ( ) , and { } shall occur in pairs, possibly
2663separated by expressions, declarations, or statements. The punctuator
2664# shall occur in preprocessing directives only.
2665
2666Semantics
2667
2668 A punctuator is a symbol that has independent syntactic and
2669semantic significance but does not specify an operation to be
2670performed that yields a value. Depending on context, the same symbol
2671may also represent an operator or part of an operator.
2672
2673Forward references: expressions ($3.3), declarations ($3.5),
2674preprocessing directives ($3.8), statements ($3.6).
2675
26763.1.7 Header names
2677
2678Syntax
2679
2680 header-name:
2681 < h-char-sequence>
2682 " q-char-sequence"
2683
2684 h-char-sequence:
2685 h-char
2686 h-char-sequence h-char
2687
2688 h-char:
2689 any member of the source character set except
2690 the new-line character and >
2691
2692 q-char-sequence:
2693 q-char
2694 q-char-sequence q-char
2695
2696 q-char:
2697 any member of the source character set except
2698 the new-line character and "
2699
2700
2701Constraints
2702
2703 Header name preprocessing tokens shall only appear within a
2704#include preprocessing directive.
2705
2706Semantics
2707
2708 The sequences in both forms of header names are mapped in an
2709implementation-defined manner to headers or external source file names
2710as specified in $3.8.2.
2711
2712 If the characters ', \ , , or /* occur in the sequence between the
2713< and > delimiters, the behavior is undefined. Similarly, if the
2714characters ', \ , or /* occur in the sequence between the " delimiters,
2715the behavior is undefined. /20/
2716
2717Example
2718
2719 The following sequence of characters:
2720
2721 0x3<1/a.h>1e2
2722 #include <1/a.h>
2723 #define const.member@$
2724
2725forms the following sequence of preprocessing tokens (with each
2726individual preprocessing token delimited by a { on the left and a } on
2727the right).
2728
2729 {0x3}{<}{1}{/}{a}{.}{h}{>}{1e2}
2730 {#}{include} {<1/a.h>}
2731 {#}{define} {const}{.}{member}{@}{$}
2732
2733Forward references: source file inclusion ($3.8.2).
2734
2735
27363.1.8 Preprocessing numbers
2737
2738Syntax
2739
2740 pp-number:
2741 digit
2742 . digit
2743 pp-number digit
2744 pp-number nondigit
2745 pp-number e sign
2746 pp-number E sign
2747 pp-number .
2748
2749Description
2750
2751 A preprocessing number begins with a digit optionally preceded by a
2752period (.) and may be followed by letters, underscores, digits,
2753periods, and e+, e-, E+, or E- character sequences.
2754
2755 Preprocessing number tokens lexically include all floating and
2756integer constant tokens.
2757
2758Semantics
2759
2760 A preprocessing number does not have type or a value; it acquires
2761both after a successful conversion (as part of translation phase 7) to
2762a floating constant token or an integer constant token.
2763
2764
27653.1.9 Comments
2766
2767 Except within a character constant, a string literal, or a comment,
2768the characters /* introduce a comment. The contents of a comment are
2769examined only to identify multibyte characters and to find the
2770characters */ that terminate it. /21/
2771
2772
27733.2 CONVERSIONS
2774
2775 Several operators convert operand values from one type to another
2776automatically. This section specifies the result required from such
2777an implicit conversion, as well as those that result from a cast
2778operation (an explicit conversion). The list in $3.2.1.5 summarizes
2779the conversions performed by most ordinary operators; it is
2780supplemented as required by the discussion of each operator in $3.3.
2781
2782 Conversion of an operand value to a compatible type causes no change.
2783
2784Forward references: cast operators ($3.3.4).
2785
2786
27873.2.1 Arithmetic operands
2788
27893.2.1.1 Characters and integers
2790
2791 A char, a short int, or an int bit-field, or their signed or
2792unsigned varieties, or an object that has enumeration type, may be
2793used in an expression wherever an int or unsigned int may be used. If
2794an int can represent all values of the original type, the value is
2795converted to an int; otherwise it is converted to an unsigned int.
2796These are called the integral promotions.
2797
2798 The integral promotions preserve value including sign. As
2799discussed earlier, whether a ``plain'' char is treated as signed is
2800implementation-defined.
2801
2802Forward references: enumeration specifiers ($3.5.2.2), structure and
2803union specifiers ($3.5.2.1).
2804
2805
28063.2.1.2 Signed and unsigned integers
2807
2808 When an unsigned integer is converted to another integral type, if
2809the value can be represented by the new type, its value is unchanged.
2810
2811 When a signed integer is converted to an unsigned integer with
2812equal or greater size, if the value of the signed integer is
2813nonnegative, its value is unchanged. Otherwise: if the unsigned
2814integer has greater size, the signed integer is first promoted to the
2815signed integer corresponding to the unsigned integer; the value is
2816converted to unsigned by adding to it one greater than the largest
2817number that can be represented in the unsigned integer type. /22/
2818
2819 When an integer is demoted to an unsigned integer with smaller
2820size, the result is the nonnegative remainder on division by the
2821number one greater than the largest unsigned number that can be
2822represented in the type with smaller size. When an integer is demoted
2823to a signed integer with smaller size, or an unsigned integer is
2824converted to its corresponding signed integer, if the value cannot be
2825represented the result is implementation-defined.
2826
2827
28283.2.1.3 Floating and integral
2829
2830 When a value of floating type is converted to integral type, the
2831fractional part is discarded. If the value of the integral part
2832cannot be represented by the integral type, the behavior is
2833undefined. /23/
2834
2835 When a value of integral type is converted to floating type, if the
2836value being converted is in the range of values that can be
2837represented but cannot be represented exactly, the result is either
2838the nearest higher or nearest lower value, chosen in an
2839implementation-defined manner.
2840
2841
28423.2.1.4 Floating types
2843
2844 When a float is promoted to double or long double , or a double is
2845promoted to long double , its value is unchanged.
2846
2847 When a double is demoted to float or a long double to double or
2848float, if the value being converted is outside the range of values
2849that can be represented, the behavior is undefined. If the value
2850being converted is in the range of values that can be represented but
2851cannot be represented exactly, the result is either the nearest higher
2852or nearest lower value, chosen in an implementation-defined manner.
2853
2854
28553.2.1.5 Usual arithmetic conversions
2856
2857 Many binary operators that expect operands of arithmetic type cause
2858conversions and yield result types in a similar way. The purpose is
2859to yield a common type, which is also the type of the result. This
2860pattern is called the usual arithmetic conversions: First, if either
2861operand has type long double, the other operand is converted to long
2862double . Otherwise, if either operand has type double, the other
2863operand is converted to double. Otherwise, if either operand has
2864type float, the other operand is converted to float. Otherwise, the
2865integral promotions are performed on both operands. Then the
2866following rules are applied: If either operand has type unsigned long
2867int, the other operand is converted to unsigned long int.
2868Otherwise, if one operand has type long int and the other has type
2869unsigned int, if a long int can represent all values of an unsigned
2870int, the operand of type unsigned int is converted to long int ; if a
2871long int cannot represent all the values of an unsigned int, both
2872operands are converted to unsigned long int. Otherwise, if either
2873operand has type long int, the other operand is converted to long int.
2874Otherwise, if either operand has type unsigned int, the other
2875operand is converted to unsigned int. Otherwise, both operands have
2876type int.
2877
2878 The values of operands and of the results of expressions may be
2879represented in greater precision and range than that required by the
2880type; the types are not changed thereby.
2881
2882
28833.2.2 Other operands
2884
28853.2.2.1 Lvalues and function designators
2886
2887 An lvalue is an expression (with an object type or an incomplete
2888type other than void) that designates an object. /24/ When an object
2889is said to have a particular type, the type is specified by the lvalue
2890used to designate the object. A modifiable lvalue is an lvalue that
2891does not have array type, does not have an incomplete type, does not
2892have a const-qualified type, and if it is a structure or union, does
2893not have any member (including, recursively, any member of all
2894contained structures or unions) with a const-qualified type.
2895
2896 Except when it is the operand of the sizeof operator, the unary &
2897operator, the ++ operator, the -- operator, or the left operand of the .
2898operator or an assignment operator, an lvalue that does not have
2899array type is converted to the value stored in the designated object
2900(and is no longer an lvalue). If the lvalue has qualified type, the
2901value has the unqualified version of the type of the lvalue; otherwise
2902the value has the type of the lvalue. If the lvalue has an incomplete
2903type and does not have array type, the behavior is undefined.
2904
2905 Except when it is the operand of the sizeof operator or the unary &
2906operator, or is a character string literal used to initialize an array
2907of character type, or is a wide string literal used to initialize an
2908array with element type compatible with wchar_t, an lvalue that has
2909type ``array of type '' is converted to an expression that has type
2910``pointer to type '' that points to the initial member of the array
2911object and is not an lvalue.
2912
2913 A function designator is an expression that has function type.
2914Except when it is the operand of the sizeof operator /25/ or the unary
2915& operator, a function designator with type ``function returning type
2916'' is converted to an expression that has type ``pointer to function
2917returning type .''
2918
2919Forward references: address and indirection operators ($3.3.3.2),
2920assignment operators ($3.3.16), common definitions <stddef.h>
2921($4.1.5), initialization ($3.5.7), postfix increment and decrement
2922operators ($3.3.2.4), prefix increment and decrement operators
2923($3.3.3.1), the sizeof operator ($3.3.3.4), structure and union
2924members ($3.3.2.3).
2925
2926
29273.2.2.2 void
2928
2929 The (nonexistent) value of a void expression (an expression that
2930has type void) shall not be used in any way, and implicit or explicit
2931conversions (except to void ) shall not be applied to such an
2932expression. If an expression of any other type occurs in a context
2933where a void expression is required, its value or designator is
2934discarded. (A void expression is evaluated for its side effects.)
2935
2936
29373.2.2.3 Pointers
2938
2939 A pointer to void may be converted to or from a pointer to any
2940incomplete or object type. A pointer to any incomplete or object type
2941may be converted to a pointer to void and back again; the result shall
2942compare equal to the original pointer.
2943
2944 A pointer to a non-q-qualified type may be converted to a pointer
2945to the q-qualified version of the type; the values stored in the
2946original and converted pointers shall compare equal.
2947
2948 An integral constant expression with the value 0, or such an
2949expression cast to type void * , is called a null pointer constant. If
2950a null pointer constant is assigned to or compared for equality to a
2951pointer, the constant is converted to a pointer of that type. Such a
2952pointer, called a null pointer, is guaranteed to compare unequal to a
2953pointer to any object or function.
2954
2955 Two null pointers, converted through possibly different sequences
2956of casts to pointer types, shall compare equal.
2957
2958Forward references: cast operators ($3.3.4), equality operators
2959($3.3.9), simple assignment ($3.3.16.1).
2960
2961
29623.3 EXPRESSIONS
2963
2964 An expression is a sequence of operators and operands that
2965specifies computation of a value, or that designates an object or a
2966function, or that generates side effects, or that performs a
2967combination thereof.
2968
2969 Between the previous and next sequence point an object shall have
2970its stored value modified at most once by the evaluation of an
2971expression. Furthermore, the prior value shall be accessed only to
2972determine the value to be stored. /26/
2973
2974 Except as indicated by the syntax /27/ or otherwise specified later
2975(for the function-call operator () , && , || , ?: , and comma
2976operators), the order of evaluation of subexpressions and the order in
2977which side effects take place are both unspecified.
2978
2979 Some operators (the unary operator ~ , and the binary operators << ,
2980>> , & , ^ , and | , collectively described as bitwise operators
2981)shall have operands that have integral type. These operators return
2982values that depend on the internal representations of integers, and
2983thus have implementation-defined aspects for signed types.
2984
2985 If an exception occurs during the evaluation of an expression (that
2986is, if the result is not mathematically defined or not representable),
2987the behavior is undefined.
2988
2989 An object shall have its stored value accessed only by an lvalue
2990that has one of the following types: /28/
2991
2992 * the declared type of the object,
2993
2994 * a qualified version of the declared type of the object,
2995
2996 * a type that is the signed or unsigned type corresponding to the
2997 declared type of the object,
2998
2999 * a type that is the signed or unsigned type corresponding to a
3000 qualified version of the declared type of the object,
3001
3002 * an aggregate or union type that includes one of the aforementioned
3003 types among its members (including, recursively, a member of a
3004 subaggregate or contained union), or
3005
3006 * a character type.
3007
3008
30093.3.1 Primary expressions
3010
3011Syntax
3012
3013 primary-expression:
3014 identifier
3015 constant
3016 string-literal
3017 ( expression )
3018
3019Semantics
3020
3021 An identifier is a primary expression, provided it has been
3022declared as designating an object (in which case it is an lvalue) or a
3023function (in which case it is a function designator).
3024
3025 A constant is a primary expression. Its type depends on its form,
3026as detailed in $3.1.3.
3027
3028 A string literal is a primary expression. It is an lvalue with
3029type as detailed in $3.1.4.
3030
3031 A parenthesized expression is a primary expression. Its type and
3032value are identical to those of the unparenthesized expression. It is
3033an lvalue, a function designator, or a void expression if the
3034unparenthesized expression is, respectively, an lvalue, a function
3035designator, or a void expression.
3036
3037Forward references: declarations ($3.5).
3038
3039
30403.3.2 Postfix operators
3041
3042Syntax
3043
3044 postfix-expression:
3045 primary-expression
3046 postfix-expression [ expression ]
3047 postfix-expression ( argument-expression-list<opt> )
3048 postfix-expression . identifier
3049 postfix-expression -> identifier
3050 postfix-expression ++
3051 postfix-expression --
3052
3053 argument-expression-list:
3054 assignment-expression
3055 argument-expression-list , assignment-expression
3056
3057
30583.3.2.1 Array subscripting
3059
3060Constraints
3061
3062 One of the expressions shall have type ``pointer to object type ,''
3063the other expression shall have integral type, and the result has type
3064`` type .''
3065
3066Semantics
3067
3068 A postfix expression followed by an expression in square brackets
3069[] is a subscripted designation of a member of an array object. The
3070definition of the subscript operator [] is that E1[E2] is identical to
3071(*(E1+(E2))) . Because of the conversion rules that apply to the
3072binary + operator, if E1 is an array object (equivalently, a pointer
3073to the initial member of an array object) and E2 is an integer, E1[E2]
3074designates the E2 -th member of E1 (counting from zero).
3075
3076 Successive subscript operators designate a member of a
3077multi-dimensional array object. If E is an n -dimensional array ( n
3078>=2) with dimensions i x j "x ... x" k , then E (used as other than an
3079lvalue) is converted to a pointer to an ( n -1)-dimensional array with
3080dimensions j "x ... x" k . If the unary * operator is applied to this
3081pointer explicitly, or implicitly as a result of subscripting, the
3082result is the pointed-to ( n -1)-dimensional array, which itself is
3083converted into a pointer if used as other than an lvalue. It follows
3084from this that arrays are stored in row-major order (last subscript
3085varies fastest).
3086
3087Example
3088
3089 Consider the array object defined by the declaration
3090
3091 int x[3][5];
3092
3093Here x is a 3x5 array of int s; more precisely, x is an array of three
3094member objects, each of which is an array of five int s. In the
3095expression x[i] , which is equivalent to (*(x+(i))) , x is first
3096converted to a pointer to the initial array of five int s. Then i is
3097adjusted according to the type of x , which conceptually entails
3098multiplying i by the size of the object to which the pointer points,
3099namely an array of five int objects. The results are added and
3100indirection is applied to yield an array of five int s. When used in
3101the expression x[i][j] , that in turn is converted to a pointer to the
3102first of the int s, so x[i][j] yields an int.
3103
3104Forward references: additive operators ($3.3.6), address and
3105indirection operators ($3.3.3.2), array declarators ($3.5.4.2).
3106
3107
31083.3.2.2 Function calls
3109
3110Constraints
3111
3112 The expression that denotes the called function/29/ shall have type
3113pointer to function returning void or returning an object type other
3114than array.
3115
3116 If the expression that denotes the called function has a type that
3117includes a prototype, the number of arguments shall agree with the
3118number of parameters. Each argument shall have a type such that its
3119value may be assigned to an object with the unqualified version of the
3120type of its corresponding parameter.
3121
3122Semantics
3123
3124 A postfix expression followed by parentheses () containing a
3125possibly empty, comma-separated list of expressions is a function
3126call. The postfix expression denotes the called function. The list
3127of expressions specifies the arguments to the function.
3128
3129 If the expression that precedes the parenthesized argument list in
3130a function call consists solely of an identifier, and if no
3131declaration is visible for this identifier, the identifier is
3132implicitly declared exactly as if, in the innermost block containing
3133the function call, the declaration
3134
3135 extern int identifier();
3136
3137appeared. /30/
3138
3139 An argument may be an expression of any object type. In preparing
3140for the call to a function, the arguments are evaluated, and each
3141parameter is assigned the value of the corresponding argument./31/ The
3142value of the function call expression is specified in $3.6.6.4.
3143
3144 If the expression that denotes the called function has a type that
3145does not include a prototype, the integral promotions are performed on
3146each argument and arguments that have type float are promoted to
3147double. These are called the default argument promotions. If the
3148number of arguments does not agree with the number of parameters, the
3149behavior is undefined. If the function is defined with a type that
3150does not include a prototype, and the types of the arguments after
3151promotion are not compatible with those of the parameters after
3152promotion, the behavior is undefined. If the function is defined with
3153a type that includes a prototype, and the types of the arguments after
3154promotion are not compatible with the types of the parameters, or if
3155the prototype ends with an ellipsis ( ", ..." ), the behavior is
3156undefined.
3157
3158 If the expression that denotes the called function has a type that
3159includes a prototype, the arguments are implicitly converted, as if by
3160assignment, to the types of the corresponding parameters. The
3161ellipsis notation in a function prototype declarator causes argument
3162type conversion to stop after the last declared parameter. The
3163default argument promotions are performed on trailing arguments. If
3164the function is defined with a type that is not compatible with the
3165type (of the expression) pointed to by the expression that denotes the
3166called function, the behavior is undefined.
3167
3168 No other conversions are performed implicitly; in particular, the
3169number and types of arguments are not compared with those of the
3170parameters in a function definition that does not include a function
3171prototype declarator.
3172
3173 The order of evaluation of the function designator, the arguments,
3174and subexpressions within the arguments is unspecified, but there is a
3175sequence point before the actual call.
3176
3177 Recursive function calls shall be permitted, both directly and
3178indirectly through any chain of other functions.
3179
3180Example
3181
3182 In the function call
3183
3184 (*pf[f1()]) (f2(), f3() + f4())
3185
3186the functions f1 , f2 , f3 , and f4 may be called in any order. All
3187side effects shall be completed before the function pointed to by
3188pf[f1()] is entered.
3189
3190Forward references: function declarators (including prototypes)
3191($3.5.4.3), function definitions ($3.7.1), the return statement
3192($3.6.6.4), simple assignment ($3.3.16.1).
3193
3194
31953.3.2.3 Structure and union members
3196
3197Constraints
3198
3199 The first operand of the . operator shall have a qualified or
3200unqualified structure or union type, and the second operand shall name
3201a member of that type.
3202
3203 The first operand of the -> operator shall have type ``pointer to
3204qualified or unqualified structure'' or ``pointer to qualified or
3205unqualified union,'' and the second operand shall name a member of the
3206type pointed to.
3207
3208Semantics
3209
3210 A postfix expression followed by a dot . and an identifier
3211designates a member of a structure or union object. The value is that
3212of the named member, and is an lvalue if the first expression is an
3213lvalue. If the first expression has qualified type, the result has
3214the so-qualified version of the type of the designated member.
3215
3216 A postfix expression followed by an arrow -> and an identifier
3217designates a member of a structure or union object. The value is that
3218of the named member of the object to which the first expression
3219points, and is an lvalue./32/ If the first expression is a pointer to
3220a qualified type, the result has the so-qualified version of the type
3221of the designated member.
3222
3223 With one exception, if a member of a union object is accessed after
3224a value has been stored in a different member of the object, the
3225behavior is implementation-defined./33/ One special guarantee is made
3226in order to simplify the use of unions: If a union contains several
3227structures that share a common initial sequence, and if the union
3228object currently contains one of these structures, it is permitted to
3229inspect the common initial part of any of them. Two structures share
3230a common initial sequence if corresponding members have compatible
3231types for a sequence of one or more initial members.
3232
3233Example
3234
3235 If f is a function returning a structure or union, and x is a
3236member of that structure or union, f().x is a valid postfix expression
3237but is not an lvalue.
3238
3239 The following is a valid fragment:
3240
3241 union {
3242 struct {
3243 int alltypes;
3244 } n;
3245 struct {
3246 int type;
3247 int intnode;
3248 } ni;
3249 struct {
3250 int type;
3251 double doublenode;
3252 } nf;
3253 } u;
3254 /*...*/
3255 u.nf.type = 1;
3256 u.nf.doublenode = 3.14;
3257 /*...*/
3258 if (u.n.alltypes == 1)
3259 /*...*/ sin(u.nf.doublenode) /*...*/
3260
3261
3262
3263Forward references: address and indirection operators ($3.3.3.2),
3264structure and union specifiers ($3.5.2.1).
3265
3266
32673.3.2.4 Postfix increment and decrement operators
3268
3269Constraints
3270
3271 The operand of the postfix increment or decrement operator shall
3272have qualified or unqualified scalar type and shall be a modifiable
3273lvalue.
3274
3275Semantics
3276
3277 The result of the postfix ++ operator is the value of the operand.
3278After the result is obtained, the value of the operand is incremented.
3279(That is, the value 1 of the appropriate type is added to it.) See the
3280discussions of additive operators and compound assignment for
3281information on constraints, types and conversions and the effects of
3282operations on pointers. The side effect of updating the stored value
3283of the operand shall occur between the previous and the next sequence
3284point.
3285
3286 The postfix -- operator is analogous to the postfix ++ operator,
3287except that the value of the operand is decremented (that is, the
3288value 1 of the appropriate type is subtracted from it).
3289
3290Forward references: additive operators ($3.3.6), compound assignment
3291($3.3.16.2).
3292
3293
32943.3.3 Unary operators
3295
3296Syntax
3297
3298 unary-expression:
3299 postfix-expression
3300 ++ unary-expression
3301 -- unary-expression
3302 unary-operator cast-expression
3303 sizeof unary-expression
3304 sizeof ( type-name )
3305
3306 unary-operator: one of
3307 & * + - ~ !
3308
3309
33103.3.3.1 Prefix increment and decrement operators
3311
3312Constraints
3313
3314 The operand of the prefix increment or decrement operator shall
3315have qualified or unqualified scalar type and shall be a modifiable
3316lvalue.
3317
3318Semantics
3319
3320 The value of the operand of the prefix ++ operator is incremented.
3321The result is the new value of the operand after incrementation. The
3322expression ++E is equivalent to (E+=1) . See the discussions of
3323additive operators and compound assignment for information on
3324constraints, types, side effects, and conversions and the effects of
3325operations on pointers.
3326
3327 The prefix -- operator is analogous to the prefix ++ operator,
3328except that the value of the operand is decremented.
3329
3330Forward references: additive operators ($3.3.6), compound assignment
3331($3.3.16.2).
3332
3333
33343.3.3.2 Address and indirection operators
3335
3336Constraints
3337
3338 The operand of the unary & operator shall be either a function
3339designator or an lvalue that designates an object that is not a
3340bit-field and is not declared with the register storage-class
3341specifier.
3342
3343 The operand of the unary * operator shall have pointer type.
3344
3345Semantics
3346
3347 The result of the unary & (address-of) operator is a pointer to the
3348object or function designated by its operand. If the operand has type
3349`` type ,'' the result has type ``pointer to type .''
3350
3351 The unary * operator denotes indirection. If the operand points to
3352a function, the result is a function designator; if it points to an
3353object, the result is an lvalue designating the object. If the
3354operand has type ``pointer to type ,'' the result has type `` type .''
3355If an invalid value has been assigned to the pointer, the behavior of
3356the unary * operator is undefined./34/
3357
3358Forward references: storage-class specifiers ($3.5.1), structure and
3359union specifiers ($3.5.2.1).
3360
3361
33623.3.3.3 Unary arithmetic operators
3363
3364Constraints
3365
3366 The operand of the unary + or - operator shall have arithmetic
3367type; of the ~ operator, integral type; of the ! operator, scalar
3368type.
3369
3370Semantics
3371
3372 The result of the unary + operator is the value of its operand.
3373The integral promotion is performed on the operand, and the result has
3374the promoted type.
3375
3376 The result of the unary - operator is the negative of its operand.
3377The integral promotion is performed on the operand, and the result has
3378the promoted type.
3379
3380 The result of the ~ operator is the bitwise complement of its
3381operand (that is, each bit in the result is set if and only if the
3382corresponding bit in the converted operand is not set). The integral
3383promotion is performed on the operand, and the result has the promoted
3384type. The expression ~E is equivalent to (ULONG_MAX-E) if E is
3385promoted to type unsigned long , to (UINT_MAX-E) if E is promoted to
3386type unsigned int . (The constants ULONG_MAX and UINT_MAX are defined
3387in the header <limits.h> .)
3388
3389 The result of the logical negation operator ! is 0 if the value of
3390its operand compares unequal to 0, 1 if the value of its operand
3391compares equal to 0. The result has type int . The expression !E is
3392equivalent to (0==E) .
3393
3394Forward references: limits <float.h> and <limits.h> ($4.1.4).
3395
3396
33973.3.3.4 The sizeof operator
3398
3399Constraints
3400
3401 The sizeof operator shall not be applied to an expression that has
3402function type or an incomplete type, to the parenthesized name of such
3403a type, or to an lvalue that designates a bit-field object.
3404
3405Semantics
3406
3407 The sizeof operator yields the size (in bytes) of its operand,
3408which may be an expression or the parenthesized name of a type. The
3409size is determined from the type of the operand, which is not itself
3410evaluated. The result is an integer constant.
3411
3412 When applied to an operand that has type char , unsigned char , or
3413signed char , (or a qualified version thereof) the result is 1. When
3414applied to an operand that has array type, the result is the total
3415number of bytes in the array./35/ When applied to an operand that has
3416structure or union type, the result is the total number of bytes in
3417such an object, including internal and trailing padding.
3418
3419 The value of the result is implementation-defined, and its type (an
3420unsigned integral type) is size_t defined in the <stddef.h> header.
3421
3422Examples
3423
3424 A principal use of the sizeof operator is in communication with
3425routines such as storage allocators and I/O systems. A
3426storage-allocation function might accept a size (in bytes) of an
3427object to allocate and return a pointer to void. For example:
3428
3429 extern void *alloc();
3430 double *dp = alloc(sizeof *dp);
3431
3432The implementation of the alloc function should ensure that its return
3433value is aligned suitably for conversion to a pointer to double.
3434
3435 Another use of the sizeof operator is to compute the number of
3436members in an array:
3437
3438 sizeof array / sizeof array[0]
3439
3440Forward references: common definitions <stddef.h> ($4.1.5),
3441declarations ($3.5), structure and union specifiers ($3.5.2.1), type
3442names ($3.5.5).
3443
3444
34453.3.4 Cast operators
3446
3447Syntax
3448
3449 cast-expression:
3450 unary-expression
3451 ( type-name ) cast-expression
3452
3453Constraints
3454
3455 Unless the type name specifies void type, the type name shall
3456specify qualified or unqualified scalar type and the operand shall
3457have scalar type.
3458
3459Semantics
3460
3461 Preceding an expression by a parenthesized type name converts the
3462value of the expression to the named type. This construction is
3463called a cast. /36/ A cast that specifies an implicit conversion or no
3464conversion has no effect on the type or value of an expression.
3465
3466 Conversions that involve pointers (other than as permitted by the
3467constraints of $3.3.16.1) shall be specified by means of an explicit
3468cast; they have implementation-defined aspects: A pointer may be
3469converted to an integral type. The size of integer required and the
3470result are implementation-defined. If the space provided is not long
3471enough, the behavior is undefined. An arbitrary integer may be
3472converted to a pointer. The result is implementation-defined./37/ A
3473pointer to an object or incomplete type may be converted to a pointer
3474to a different object type or a different incomplete type. The
3475resulting pointer might not be valid if it is improperly aligned for
3476the type pointed to. It is guaranteed, however, that a pointer to an
3477object of a given alignment may be converted to a pointer to an object
3478of the same alignment or a less strict alignment and back again; the
3479result shall compare equal to the original pointer. (An object that
3480has character type has the least strict alignment.) A pointer to a
3481function of one type may be converted to a pointer to a function of
3482another type and back again; the result shall compare equal to the
3483original pointer. If a converted pointer is used to call a function
3484that has a type that is not compatible with the type of the called
3485function, the behavior is undefined.
3486
3487Forward references: equality operators ($3.3.9), function declarators
3488(including prototypes) ($3.5.4.3), simple assignment ($3.3.16.1), type
3489names ($3.5.5).
3490
3491
34923.3.5 Multiplicative operators
3493
3494Syntax
3495
3496 multiplicative-expression:
3497 cast-expression
3498 multiplicative-expression * cast-expression
3499 multiplicative-expression / cast-expression
3500 multiplicative-expression % cast-expression
3501
3502Constraints
3503
3504 Each of the operands shall have arithmetic type. The operands of
3505the % operator shall have integral type.
3506
3507Semantics
3508
3509 The usual arithmetic conversions are performed on the operands.
3510
3511 The result of the binary * operator is the product of the operands.
3512
3513 The result of the / operator is the quotient from the division of
3514the first operand by the second; the result of the % operator is the
3515remainder. In both operations, if the value of the second operand is
3516zero, the behavior is undefined.
3517
3518 When integers are divided and the division is inexact, if both
3519operands are positive the result of the / operator is the largest
3520integer less than the algebraic quotient and the result of the %
3521operator is positive. If either operand is negative, whether the
3522result of the / operator is the largest integer less than the
3523algebraic quotient or the smallest integer greater than the algebraic
3524quotient is implementation-defined, as is the sign of the result of
3525the % operator. If the quotient a/b is representable, the expression
3526(a/b)*b + a%b shall equal a .
3527
3528
35293.3.6 Additive operators
3530
3531Syntax
3532
3533 additive-expression:
3534 multiplicative-expression
3535 additive-expression + multiplicative-expression
3536 additive-expression - multiplicative-expression
3537
3538Constraints
3539
3540 For addition, either both operands shall have arithmetic type, or
3541one operand shall be a pointer to an object type and the other shall
3542have integral type. (Incrementing is equivalent to adding 1.)
3543
3544 For subtraction, one of the following shall hold:
3545
3546 * both operands have arithmetic type;
3547
3548 * both operands are pointers to qualified or unqualified versions of
3549 compatible object types; or
3550
3551 * the left operand is a pointer to an object type and the right
3552 operand has integral type. (Decrementing is equivalent to subtracting 1.)
3553
3554Semantics
3555
3556 If both operands have arithmetic type, the usual arithmetic
3557conversions are performed on them.
3558
3559 The result of the binary + operator is the sum of the operands.
3560
3561 The result of the binary - operator is the difference resulting
3562from the subtraction of the second operand from the first.
3563
3564 When an expression that has integral type is added to or subtracted
3565from a pointer, the integral value is first multiplied by the size of
3566the object pointed to. The result has the type of the pointer
3567operand. If the pointer operand points to a member of an array
3568object, and the array object is large enough, the result points to a
3569member of the same array object, appropriately offset from the
3570original member. Thus if P points to a member of an array object, the
3571expression P+1 points to the next member of the array object. Unless
3572both the pointer operand and the result point to a member of the same
3573array object, or one past the last member of the array object, the
3574behavior is undefined. Unless both the pointer operand and the result
3575point to a member of the same array object, or the pointer operand
3576points one past the last member of an array object and the result
3577points to a member of the same array object, the behavior is undefined
3578if the result is used as the operand of a unary * operator.
3579
3580 When two pointers to members of the same array object are
3581subtracted, the difference is divided by the size of a member. The
3582result represents the difference of the subscripts of the two array
3583members. The size of the result is implementation-defined, and its
3584type (a signed integral type) is ptrdiff_t defined in the <stddef.h>
3585header. As with any other arithmetic overflow, if the result does not
3586fit in the space provided, the behavior is undefined. If two pointers
3587that do not point to members of the same array object are subtracted,
3588the behavior is undefined. However, if P points either to a member of
3589an array object or one past the last member of an array object, and Q
3590points to the last member of the same array object, the expression
3591(Q+1) - P has the same value as (Q-P) + 1 , even though Q+1 does not
3592point to a member of the array object.
3593
3594Forward references: common definitions <stddef.h> ($4.1.5).
3595
3596
35973.3.7 Bitwise shift operators
3598
3599Syntax
3600
3601 shift-expression:
3602 additive-expression
3603 shift-expression << additive-expression
3604 shift-expression >> additive-expression
3605
3606Constraints
3607
3608 Each of the operands shall have integral type.
3609
3610Semantics
3611
3612 The integral promotions are performed on each of the operands. The
3613type of the result is that of the promoted left operand. If the value
3614of the right operand is negative or is greater than or equal to the
3615width in bits of the promoted left operand, the behavior is undefined.
3616
3617 The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated
3618bits are filled with zeros. If E1 has an unsigned type, the value of
3619the result is E1 multiplied by the quantity, 2 raised to the power E2,
3620reduced modulo ULONG_MAX+1 if E1 has type unsigned long, UINT_MAX+1
3621otherwise. (The constants ULONG_MAX and UINT_MAX are defined in the
3622header <limits.h> .)
3623
3624 The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1
3625has an unsigned type or if E1 has a signed type and a nonnegative
3626value, the value of the result is the integral part of the quotient of
3627E1 divided by the quantity, 2 raised to the power E2 . If E1 has a
3628signed type and a negative value, the resulting value is
3629implementation-defined.
3630
3631
36323.3.8 Relational operators
3633
3634Syntax
3635
3636 relational-expression:
3637 shift-expression
3638 relational-expression < shift-expression
3639 relational-expression > shift-expression
3640 relational-expression <= shift-expression
3641 relational-expression >= shift-expression
3642
3643Constraints
3644
3645 One of the following shall hold:
3646
3647 * both operands have arithmetic type;
3648
3649 * both operands are pointers to qualified or unqualified versions of
3650 compatible object types; or
3651
3652 * both operands are pointers to qualified or unqualified versions of
3653 compatible incomplete types.
3654
3655Semantics
3656
3657 If both of the operands have arithmetic type, the usual arithmetic
3658conversions are performed.
3659
3660 When two pointers are compared, the result depends on the relative
3661locations in the address space of the objects pointed to. If the
3662objects pointed to are members of the same aggregate object, pointers
3663to structure members declared later compare higher than pointers to
3664members declared earlier in the structure, and pointers to array
3665elements with larger subscript values compare higher than pointers to
3666elements of the same array with lower subscript values. All pointers
3667to members of the same union object compare equal. If the objects
3668pointed to are not members of the same aggregate or union object, the
3669result is undefined, with the following exception. If P points to the
3670last member of an array object and Q points to a member of the same
3671array object, the pointer expression P+1 compares higher than Q , even
3672though P+1 does not point to a member of the array object.
3673
3674 Each of the operators < (less than), > (greater than), <= (less
3675than or equal to), and >= (greater than or equal to) shall yield 1 if
3676the specified relation is true and 0 if it is false./38/ The result
3677has type int.
3678
3679
36803.3.9 Equality operators
3681
3682Syntax
3683
3684 equality-expression:
3685 relational-expression
3686 equality-expression == relational-expression
3687 equality-expression != relational-expression
3688
3689Constraints
3690
3691 One of the following shall hold:
3692
3693 * both operands have arithmetic type;
3694
3695 * both operands are pointers to qualified or unqualified versions of
3696 compatible types;
3697
3698 * one operand is a pointer to an object or incomplete type and the
3699 other is a qualified or unqualified version of void ; or
3700
3701 * one operand is a pointer and the other is a null pointer constant.
3702
3703Semantics
3704
3705 The == (equal to) and the != (not equal to) operators are analogous
3706to the relational operators except for their lower precedence./39/
3707
3708 If two pointers to object or incomplete types compare equal, they
3709point to the same object. If two pointers to functions compare equal,
3710they point to the same function. If two pointers point to the same
3711object or function, they compare equal./40/ If one of the operands is
3712a pointer to an object or incomplete type and the other has type
3713pointer to a qualified or unqualified version of void , the pointer to
3714an object or incomplete type is converted to the type of the other
3715operand.
3716
3717
37183.3.10 Bitwise AND operator
3719
3720Syntax
3721
3722 AND-expression:
3723 equality-expression
3724 AND-expression & equality-expression
3725
3726Constraints
3727
3728 Each of the operands shall have integral type.
3729
3730Semantics
3731
3732 The usual arithmetic conversions are performed on the operands.
3733
3734 The result of the binary & operator is the bitwise AND of the
3735operands (that is, each bit in the result is set if and only if each
3736of the corresponding bits in the converted operands is set).
3737
3738
37393.3.11 Bitwise exclusive OR operator
3740
3741Syntax
3742
3743 exclusive-OR-expression:
3744 AND-expression
3745 exclusive-OR-expression ^ AND-expression
3746
3747Constraints
3748
3749 Each of the operands shall have integral type.
3750
3751Semantics
3752
3753 The usual arithmetic conversions are performed on the operands.
3754
3755 The result of the ^ operator is the bitwise exclusive OR of the
3756operands (that is, each bit in the result is set if and only if
3757exactly one of the corresponding bits in the converted operands is
3758set).
3759
3760
37613.3.12 Bitwise inclusive OR operator
3762
3763Syntax
3764
3765 inclusive-OR-expression:
3766 exclusive-OR-expression
3767 inclusive-OR-expression | exclusive-OR-expression
3768
3769Constraints
3770
3771 Each of the operands shall have integral type.
3772
3773Semantics
3774
3775 The usual arithmetic conversions are performed on the operands.
3776
3777 The result of the | operator is the bitwise inclusive OR of the
3778operands (that is, each bit in the result is set if and only if at
3779least one of the corresponding bits in the converted operands is set).
3780
3781
37823.3.13 Logical AND operator
3783
3784Syntax
3785
3786 logical-AND-expression:
3787 inclusive-OR-expression
3788 logical-AND-expression && inclusive-OR-expression
3789
3790Constraints
3791
3792 Each of the operands shall have scalar type.
3793
3794Semantics
3795
3796 The && operator shall yield 1 if both of its operands compare
3797unequal to 0, otherwise it yields 0. The result has type int.
3798
3799 Unlike the bitwise binary & operator, the && operator guarantees
3800left-to-right evaluation; there is a sequence point after the
3801evaluation of the first operand. If the first operand compares equal
3802to 0, the second operand is not evaluated.
3803
3804
38053.3.14 Logical OR operator
3806
3807Syntax
3808
3809 logical-OR-expression:
3810 logical-AND-expression
3811 logical-OR-expression || logical-AND-expression
3812
3813Constraints
3814
3815 Each of the operands shall have scalar type.
3816
3817Semantics
3818
3819 The || operator shall yield 1 if either of its operands compare
3820unequal to 0, otherwise it yields 0. The result has type int.
3821
3822 Unlike the bitwise | operator, the || operator guarantees
3823left-to-right evaluation; there is a sequence point after the
3824evaluation of the first operand. If the first operand compares
3825unequal to 0, the second operand is not evaluated.
3826
3827
38283.3.15 Conditional operator
3829
3830Syntax
3831
3832 conditional-expression:
3833 logical-OR-expression
3834 logical-OR-expression ? expression : conditional-expression
3835
3836Constraints
3837
3838 The first operand shall have scalar type.
3839
3840 One of the following shall hold for the second and third operands:
3841
3842 * both operands have arithmetic type;
3843
3844 * both operands have compatible structure or union types;
3845
3846 * both operands have void type;
3847
3848 * both operands are pointers to qualified or unqualified versions of
3849 compatible types;
3850
3851 * one operand is a pointer and the other is a null pointer constant; or
3852
3853 * one operand is a pointer to an object or incomplete type and the
3854 other is a pointer to a qualified or unqualified version of void .
3855
3856Semantics
3857
3858 The first operand is evaluated; there is a sequence point after its
3859evaluation. The second operand is evaluated only if the first
3860compares unequal to 0; the third operand is evaluated only if the
3861first compares equal to 0; the value of the second or third operand
3862(whichever is evaluated) is the result./41/
3863
3864 If both the second and third operands have arithmetic type, the
3865usual arithmetic conversions are performed to bring them to a common
3866type and the result has that type. If both the operands have
3867structure or union type, the result has that type. If both operands
3868have void type, the result has void type.
3869
3870 If both the second and third operands are pointers or one is a null
3871pointer constant and the other is a pointer, the result type is a
3872pointer to a type qualified with all the type qualifiers of the types
3873pointed-to by both operands. Furthermore, if both operands are
3874pointers to compatible types or differently qualified versions of a
3875compatible type, the result has the composite type; if one operand is
3876a null pointer constant, the result has the type of the other operand;
3877otherwise, one operand is a pointer to void or a qualified version of
3878void, in which case the other operand is converted to type pointer to
3879void, and the result has that type.
3880
3881
38823.3.16 Assignment operators
3883
3884Syntax
3885
3886 assignment-expression:
3887 conditional-expression
3888 unary-expression assignment-operator assignment-expression
3889
3890 assignment-operator: one of
3891 = *= /= %= += -= <<= >>= &= ^= |=
3892
3893Constraints
3894
3895 An assignment operator shall have a modifiable lvalue as its left operand.
3896
3897Semantics
3898
3899 An assignment operator stores a value in the object designated by
3900the left operand. An assignment expression has the value of the left
3901operand after the assignment, but is not an lvalue. The type of an
3902assignment expression is the type of the left operand unless the left
3903operand has qualified type, in which case it is the unqualified
3904version of the type of the left operand. The side effect of updating
3905the stored value of the left operand shall occur between the previous
3906and the next sequence point.
3907
3908 The order of evaluation of the operands is unspecified.
3909
3910
39113.3.16.1 Simple assignment
3912
3913Constraints
3914
3915 One of the following shall hold:/42/
3916
3917 * the left operand has qualified or unqualified arithmetic type and
3918 the right has arithmetic type;
3919
3920 * the left operand has a qualified or unqualified version of a
3921 structure or union type compatible with the type of the right;
3922
3923 * both operands are pointers to qualified or unqualified versions of
3924 compatible types, and the type pointed to by the left has all the
3925 qualifiers of the type pointed to by the right;
3926
3927 * one operand is a pointer to an object or incomplete type and the
3928 other is a pointer to a qualified or unqualified version of void, and
3929 the type pointed to by the left has all the qualifiers of the type
3930 pointed to by the right; or
3931
3932 * the left operand is a pointer and the right is a null pointer constant.
3933
3934Semantics
3935
3936 In simple assignment ( = ), the value of the right operand is
3937 converted to the type of the assignment expression and replaces the
3938 value stored in the object designated by the left operand.
3939
3940 If the value being stored in an object is accessed from another
3941 object that overlaps in any way the storage of the first object, then
3942 the overlap shall be exact and the two objects shall have qualified or
3943 unqualified versions of a compatible type; otherwise the behavior is
3944 undefined.
3945
3946Example
3947
3948 In the program fragment
3949
3950 int f(void);
3951 char c;
3952 /*...*/
3953 /*...*/ ((c = f()) == -1) /*...*/
3954
3955the int value returned by the function may be truncated when stored in
3956the char, and then converted back to int width prior to the
3957comparison. In an implementation in which ``plain'' char has the same
3958range of values as unsigned char (and char is narrower than int ), the
3959result of the conversion cannot be negative, so the operands of the
3960comparison can never compare equal. Therefore, for full portability
3961the variable c should be declared as int.
3962
3963
39643.3.16.2 Compound assignment
3965
3966Constraints
3967
3968 For the operators += and -= only, either the left operand shall be
3969a pointer to an object type and the right shall have integral type, or
3970the left operand shall have qualified or unqualified arithmetic type
3971and the right shall have arithmetic type.
3972
3973 For the other operators, each operand shall have arithmetic type
3974consistent with those allowed by the corresponding binary operator.
3975
3976Semantics
3977
3978 A compound assignment of the form E1 op = E2 differs from the
3979simple assignment expression E1 = E1 op (E2) only in that the lvalue
3980E1 is evaluated only once.
3981
3982
39833.3.17 Comma operator
3984
3985Syntax
3986
3987 expression:
3988 assignment-expression
3989 expression , assignment-expression
3990
3991Semantics
3992
3993 The left operand of a comma operator is evaluated as a void
3994expression; there is a sequence point after its evaluation. Then the
3995right operand is evaluated; the result has its type and value./43/
3996
3997Example
3998
3999 As indicated by the syntax, in contexts where a comma is a
4000punctuator (in lists of arguments to functions and lists of
4001initializers) the comma operator as described in this section cannot
4002appear. On the other hand, it can be used within a parenthesized
4003expression or within the second expression of a conditional operator
4004in such contexts. In the function call
4005
4006 f(a, (t=3, t+2), c)
4007
4008the function has three arguments, the second of which has the value 5.
4009
4010Forward references: initialization ($3.5.7).
4011
4012
40133.4 CONSTANT EXPRESSIONS
4014
4015Syntax
4016
4017 constant-expression:
4018 conditional-expression
4019
4020Description
4021
4022 A constant expression can be evaluated during translation rather
4023than runtime, and accordingly may be used in any place that a constant
4024may be.
4025
4026Constraints
4027
4028 Constant expressions shall not contain assignment, increment,
4029decrement, function-call, or comma operators, except when they are
4030contained within the operand of a sizeof operator./44/
4031
4032 Each constant expression shall evaluate to a constant that is in
4033the range of representable values for its type.
4034
4035Semantics
4036
4037 An expression that evaluates to a constant is required in several
4038contexts./45/ If the expression is evaluated in the translation
4039environment, the arithmetic precision and range shall be at least as
4040great as if the expression were being evaluated in the execution
4041environment.
4042
4043 An integral constant expression shall have integral type and shall
4044only have operands that are integer constants, enumeration constants,
4045character constants, sizeof expressions, and floating constants that
4046are the immediate operands of casts. Cast operators in an integral
4047constant expression shall only convert arithmetic types to integral
4048types, except as part of an operand to the sizeof operator.
4049
4050 More latitude is permitted for constant expressions in
4051initializers. Such a constant expression shall evaluate to one of the
4052following:
4053
4054 * an arithmetic constant expression,
4055
4056 * an address constant, or
4057
4058 * an address constant for an object type plus or minus an integral
4059 constant expression.
4060
4061 An arithmetic constant expression shall have arithmetic type and
4062shall only have operands that are integer constants, floating
4063constants, enumeration constants, character constants, and sizeof
4064expressions. Cast operators in an arithmetic constant expression
4065shall only convert arithmetic types to arithmetic types, except as
4066part of an operand to the sizeof operator.
4067
4068 An address constant is a pointer to an lvalue designating an object
4069of static storage duration, or to a function designator; it shall be
4070created explicitly, using the unary & operator, or implicitly, by the
4071use of an expression of array or function type. The array-subscript
4072[] and member-access . and -> operators, the address & and
4073indirection * unary operators, and pointer casts may be used in the
4074creation an address constant, but the value of an object shall not be
4075accessed by use of these operators.
4076
4077 The semantic rules for the evaluation of a constant expression are
4078the same as for non-constant expressions./46/
4079
4080Forward references: initialization ($3.5.7).
4081
4082
40833.5 DECLARATIONS
4084
4085Syntax
4086
4087 declaration:
4088 declaration-specifiers init-declarator-list<opt> ;
4089
4090 declaration-specifiers:
4091 storage-class-specifier declaration-specifiers<opt>
4092 type-specifier declaration-specifiers<opt>
4093 type-qualifier declaration-specifiers<opt>
4094
4095 init-declarator-list:
4096 init-declarator
4097 init-declarator-list , init-declarator
4098
4099 init-declarator:
4100 declarator
4101 declarator = initializer
4102
4103Constraints
4104
4105 A declaration shall declare at least a declarator, a tag, or the
4106members of an enumeration.
4107
4108 If an identifier has no linkage, there shall be no more than one
4109declaration of the identifier (in a declarator or type specifier) with
4110the same scope and in the same name space, except for tags as
4111specified in $3.5.2.3.
4112
4113 All declarations in the same scope that refer to the same object or
4114function shall specify compatible types.
4115
4116Semantics
4117
4118 A declaration specifies the interpretation and attributes of a set
4119of identifiers. A declaration that also causes storage to be reserved
4120for an object or function named by an identifier is a definition ./47/
4121
4122 The declaration specifiers consist of a sequence of specifiers that
4123indicate the linkage, storage duration, and part of the type of the
4124entities that the declarators denote. The init-declarator-list is a
4125comma-separated sequence of declarators, each of which may have
4126additional type information, or an initializer, or both. The
4127declarators contain the identifiers (if any) being declared.
4128
4129 If an identifier for an object is declared with no linkage, the
4130type for the object shall be complete by the end of its declarator, or
4131by the end of its init-declarator if it has an initializer.
4132
4133Forward references: declarators ($3.5.4), enumeration specifiers
4134($3.5.2.2), initialization ($3.5.7), tags ($3.5.2.3).
4135
4136
41373.5.1 Storage-class specifiers
4138
4139Syntax
4140
4141 storage-class-specifier:
4142 typedef
4143 extern
4144 static
4145 auto
4146 register
4147
4148Constraints
4149
4150 At most one storage-class specifier may be given in the declaration
4151specifiers in a declaration./48/
4152
4153Semantics
4154
4155 The typedef specifier is called a ``storage-class specifier'' for
4156syntactic convenience only; it is discussed in $3.5.6. The meanings
4157of the various linkages and storage durations were discussed in
4158$3.1.2.2 and $3.1.2.4.
4159
4160 A declaration of an identifier for an object with storage-class
4161specifier register suggests that access to the object be as fast as
4162possible. The extent to which such suggestions are effective is
4163implementation-defined./49/
4164
4165 The declaration of an identifier for a function that has block
4166scope shall have no explicit storage-class specifier other than extern.
4167
4168Forward references: type definitions ($3.5.6).
4169
4170
41713.5.2 Type specifiers
4172
4173Syntax
4174
4175 type-specifier:
4176 void
4177 char
4178 short
4179 int
4180 long
4181 float
4182 double
4183 signed
4184 unsigned
4185 struct-or-union-specifier
4186 enum-specifier
4187 typedef-name
4188
4189Constraints
4190
4191Each list of type specifiers shall be one of the following sets; the
4192type specifiers may occur in any order, possibly intermixed with the
4193other declaration specifiers.
4194
4195 * void
4196
4197 * char
4198
4199 * signed char
4200
4201 * unsigned char
4202
4203 * short , signed short , short int , or signed short int
4204
4205 * unsigned short , or unsigned short int
4206
4207 * int , signed , signed int , or no type specifiers
4208
4209 * unsigned , or unsigned int
4210
4211 * long , signed long , long int , or signed long int
4212
4213 * unsigned long , or unsigned long int
4214
4215 * float
4216
4217 * double
4218
4219 * long double
4220
4221 * struct-or-union specifier
4222
4223 * enum-specifier
4224
4225 * typedef-name
4226
4227Semantics
4228
4229 Specifiers for structures, unions, and enumerations are discussed
4230in $3.5.2.1 through $3.5.2.3. Declarations of typedef names are
4231discussed in $3.5.6. The characteristics of the other types are
4232discussed in $3.1.2.5.
4233
4234 Each of the above comma-separated lists designates the same type,
4235except that for bit-field declarations, signed int (or signed ) may
4236differ from int (or no type specifiers).
4237
4238Forward references: enumeration specifiers ($3.5.2.2), structure and
4239union specifiers ($3.5.2.1), tags ($3.5.2.3), type definitions ($3.5.6).
4240
4241
42423.5.2.1 Structure and union specifiers
4243
4244Syntax
4245
4246 struct-or-union-specifier:
4247 struct-or-union identifier<opt> { struct-declaration-list }
4248 struct-or-union identifier
4249
4250 struct-or-union:
4251 struct
4252 union
4253
4254 struct-declaration-list:
4255 struct-declaration
4256 struct-declaration-list struct-declaration
4257
4258 struct-declaration:
4259 specifier-qualifier-list struct-declarator-list ;
4260
4261 specifier-qualifier-list:
4262 type-specifier specifier-qualifier-list<opt>
4263 type-qualifier specifier-qualifier-list<opt>
4264
4265 struct-declarator-list:
4266 struct-declarator
4267 struct-declarator-list , struct-declarator
4268
4269 struct-declarator:
4270 declarator
4271 declarator<opt> : constant-expression
4272
4273Constraints
4274
4275 A structure or union shall not contain a member with incomplete or
4276function type. Hence it shall not contain an instance of itself (but
4277may contain a pointer to an instance of itself).
4278
4279 The expression that specifies the width of a bit-field shall be an
4280integral constant expression that has nonnegative value that shall not
4281exceed the number of bits in an ordinary object of compatible type.
4282If the value is zero, the declaration shall have no declarator.
4283
4284Semantics
4285
4286 As discussed in $3.1.2.5, a structure is a type consisting of a
4287sequence of named members, whose storage is allocated in an ordered
4288sequence, and a union is a type consisting of a sequence of named
4289members, whose storage overlap.
4290
4291 Structure and union specifiers have the same form.
4292
4293 The presence of a struct-declaration-list in a
4294struct-or-union-specifier declares a new type, within a translation
4295unit. The struct-declaration-list is a sequence of declarations for
4296the members of the structure or union. The type is incomplete until
4297after the } that terminates the list.
4298
4299 A member of a structure or union may have any object type. In
4300addition, a member may be declared to consist of a specified number of
4301bits (including a sign bit, if any). Such a member is called a
4302bit-field ;/50/ its width is preceded by a colon.
4303
4304 A bit-field may have type int , unsigned int , or signed int .
4305Whether the high-order bit position of a ``plain'' int bit-field is
4306treated as a sign bit is implementation-defined. A bit-field is
4307interpreted as an integral type consisting of the specified number of
4308bits.
4309
4310 An implementation may allocate any addressable storage unit large
4311enough to hold a bit-field. If enough space remains, a bit-field that
4312immediately follows another bit-field in a structure shall be packed
4313into adjacent bits of the same unit. If insufficient space remains,
4314whether a bit-field that does not fit is put into the next unit or
4315overlaps adjacent units is implementation-defined. The order of
4316allocation of bit-fields within a unit (high-order to low-order or
4317low-order to high-order) is implementation-defined. The alignment of
4318the addressable storage unit is unspecified.
4319
4320 A bit-field declaration with no declarator, but only a colon and a
4321width, indicates an unnamed bit-field./51/ As a special case of this,
4322a bit-field with a width of 0 indicates that no further bit-field is
4323to be packed into the unit in which the previous bit-field, if any,
4324was placed.
4325
4326 Each non-bit-field member of a structure or union object is aligned
4327in an implementation-defined manner appropriate to its type.
4328
4329 Within a structure object, the non-bit-field members and the units
4330in which bit-fields reside have addresses that increase in the order
4331in which they are declared. A pointer to a structure object, suitably
4332cast, points to its initial member (or if that member is a bit-field,
4333then to the unit in which it resides), and vice versa. There may
4334therefore be unnamed holes within a structure object, but not at its
4335beginning, as necessary to achieve the appropriate alignment.
4336
4337 The size of a union is sufficient to contain the largest of its
4338members. The value of at most one of the members can be stored in a
4339union object at any time. A pointer to a union object, suitably cast,
4340points to each of its members (or if a member is a bit-field, then to
4341the unit in which it resides), and vice versa.
4342
4343 There may also be unnamed padding at the end of a structure or
4344union, as necessary to achieve the appropriate alignment were the
4345structure or union to be a member of an array.
4346
4347
43483.5.2.2 Enumeration specifiers
4349
4350Syntax
4351
4352 enum-specifier:
4353 enum identifier<opt> { enumerator-list }
4354 enum identifier
4355
4356 enumerator-list:
4357 enumerator
4358 enumerator-list , enumerator
4359
4360 enumerator:
4361 enumeration-constant
4362 enumeration-constant = constant-expression
4363
4364Constraints
4365
4366 The expression that defines the value of an enumeration constant
4367shall be an integral constant expression that has a value
4368representable as an int .
4369
4370Semantics
4371
4372 The identifiers in an enumerator list are declared as constants
4373that have type int and may appear wherever such are permitted./52/ An
4374enumerator with = defines its enumeration constant as the value of the
4375constant expression. If the first enumerator has no = , the value of
4376its enumeration constant is 0. Each subsequent enumerator with no =
4377defines its enumeration constant as the value of the constant
4378expression obtained by adding 1 to the value of the previous
4379enumeration constant. (A combination of both forms of enumerators may
4380produce enumeration constants with values that duplicate other values
4381in the same enumeration.) The enumerators of an enumeration are also
4382known as its members.
4383
4384 Each enumerated type shall be compatible with an integer type; the
4385choice of type is implementation-defined.
4386
4387Example
4388
4389 enum hue { chartreuse, burgundy, claret=20, winedark };
4390 /*...*/
4391 enum hue col, *cp;
4392 /*...*/
4393 col = claret;
4394 cp = &col;
4395 /*...*/
4396 /*...*/ (*cp != burgundy) /*...*/
4397
4398makes hue the tag of an enumeration, and then declares col as an
4399object that has that type and cp as a pointer to an object that has
4400that type. The enumerated values are in the set {0, 1, 20, 21}.
4401
4402
44033.5.2.3 Tags
4404
4405 A type specifier of the form
4406
4407 struct-or-union identifier { struct-declaration-list }
4408 enum identifier { enumerator-list }
4409
4410declares the identifier to be the tag of the structure, union, or
4411enumeration specified by the list. The list defines the structure
4412content ,union content ,or enumeration content .If this declaration of
4413the tag is visible, a subsequent declaration that uses the tag and
4414that omits the bracketed list specifies the declared structure, union,
4415or enumerated type. Subsequent declarations in the same scope shall
4416omit the bracketed list.
4417
4418 If a type specifier of the form
4419
4420 struct-or-union identifier
4421
4422occurs prior to the declaration that defines the content, the
4423structure or union is an incomplete type./53/ It declares a tag that
4424specifies a type that may be used only when the size of an object of
4425the specified type is not needed./54/ If the type is to be completed,
4426another declaration of the tag in the same scope (but not in an
4427enclosed block, which declares a new type known only within that
4428block) shall define the content. A declaration of the form
4429
4430 struct-or-union identifier ;
4431
4432specifies a structure or union type and declares a tag, both visible
4433only within the scope in which the declaration occurs. It specifies a
4434new type distinct from any type with the same tag in an enclosing
4435scope (if any).
4436
4437 A type specifier of the form
4438
4439 struct-or-union { struct-declaration-list }
4440 enum { enumerator-list }
4441
4442specifies a new structure, union, or enumerated type, within the
4443translation unit, that can only be referred to by the declaration of
4444which it is a part./55/
4445
4446Examples
4447
4448 This mechanism allows declaration of a self-referential structure.
4449
4450 struct tnode {
4451 int count;
4452 struct tnode *left, *right;
4453 };
4454
4455specifies a structure that contains an integer and two pointers to
4456objects of the same type. Once this declaration has been given, the
4457declaration
4458
4459 struct tnode s, *sp;
4460
4461declares s to be an object of the given type and sp to be a pointer to
4462an object of the given type. With these declarations, the expression
4463sp->left refers to the left struct tnode pointer of the object to
4464which sp points; the expression s.right->count designates the count
4465member of the right struct tnode pointed to from s .
4466
4467 The following alternative formulation uses the typedef mechanism:
4468
4469 typedef struct tnode TNODE;
4470 struct tnode {
4471 int count;
4472 TNODE *left, *right;
4473 };
4474 TNODE s, *sp;
4475
4476 To illustrate the use of prior declaration of a tag to specify a
4477pair of mutually-referential structures, the declarations
4478
4479 struct s1 { struct s2 *s2p; /*...*/ }; /* D1 */
4480 struct s2 { struct s1 *s1p; /*...*/ }; /* D2 */
4481
4482specify a pair of structures that contain pointers to each other.
4483Note, however, that if s2 were already declared as a tag in an
4484enclosing scope, the declaration D1 would refer to it, not to the tag
4485s2 declared in D2 . To eliminate this context sensitivity, the
4486otherwise vacuous declaration
4487
4488 struct s2;
4489
4490may be inserted ahead of D1. This declares a new tag s2 in the inner
4491scope; the declaration D2 then completes the specification of the new type.
4492
4493Forward references: type definitions ($3.5.6).
4494
4495
44963.5.3 Type qualifiers
4497
4498Syntax
4499
4500 type-qualifier:
4501 const
4502 volatile
4503
4504Constraints
4505
4506 The same type qualifier shall not appear more than once in the same
4507specifier list or qualifier list, either directly or via one or more
4508typedef s.
4509
4510Semantics
4511
4512 The properties associated with qualified types are meaningful only
4513for expressions that are lvalues./56/
4514
4515 If an attempt is made to modify an object defined with a
4516const-qualified type through use of an lvalue with non-const-qualified
4517type, the behavior is undefined. If an attempt is made to refer to an
4518object defined with a volatile-qualified type through use of an lvalue
4519with non-volatile-qualified type, the behavior is undefined./57/
4520
4521 An object that has volatile-qualified type may be modified in ways
4522unknown to the implementation or have other unknown side effects.
4523Therefore any expression referring to such an object shall be
4524evaluated strictly according to the rules of the abstract machine, as
4525described in $2.1.2.3. Furthermore, at every sequence point the value
4526last stored in the object shall agree with that prescribed by the
4527abstract machine, except as modified by the unknown factors mentioned
4528previously./58/ What constitutes an access to an object that has
4529volatile-qualified type is implementation-defined.
4530
4531 If the specification of an array type includes any type qualifiers,
4532the element type is so-qualified, not the array type. If the
4533specification of a function type includes any type qualifiers, the
4534behavior is undefined./59/
4535
4536 For two qualified types to be compatible, both shall have the
4537identically qualified version of a compatible type; the order of type
4538qualifiers within a list of specifiers or qualifiers does not affect
4539the specified type.
4540
4541Examples
4542
4543 An object declared
4544
4545 extern const volatile int real_time_clock;
4546
4547may be modifiable by hardware, but cannot be assigned to, incremented,
4548or decremented.
4549
4550 The following declarations and expressions illustrate the behavior
4551when type qualifiers modify an aggregate type:
4552
4553 const struct s { int mem; } cs = { 1 };
4554 struct s ncs; /* the object ncs is modifiable */
4555 typedef int A[2][3];
4556 const A a = {{4, 5, 6}, {7, 8, 9}}; /* array of array of const int */
4557 int *pi;
4558 const int *pci;
4559
4560 ncs = cs; /* valid */
4561 cs = ncs; /* violates modifiable lvalue constraint for = */
4562 pi = &ncs.mem; /* valid */
4563 pi = &cs.mem; /* violates type constraints for = */
4564 pci = &cs.mem; /* valid */
4565 pi = a[0]; /* invalid: a[0] has type ``const int * '' */
4566
4567
45683.5.4 Declarators
4569
4570Syntax
4571
4572 declarator:
4573 pointer<opt> direct-declarator
4574
4575 direct-declarator:
4576 identifier
4577 ( declarator )
4578 direct-declarator [ constant-expression<opt> ]
4579
4580 direct-declarator ( parameter-type-list )
4581 direct-declarator ( identifier-list<opt> )
4582
4583 pointer:
4584 * type-qualifier-list<opt>
4585 * type-qualifier-list<opt> pointer
4586
4587 type-qualifier-list:
4588 type-qualifier
4589 type-qualifier-list type-qualifier
4590
4591 parameter-type-list:
4592 parameter-list
4593 parameter-list , ...
4594
4595 parameter-list:
4596 parameter-declaration
4597 parameter-list , parameter-declaration
4598
4599 parameter-declaration:
4600 declaration-specifiers declarator
4601 declaration-specifiers abstract-declarator<opt>
4602
4603 identifier-list:
4604 identifier
4605 identifier-list , identifier
4606
4607Semantics
4608
4609 Each declarator declares one identifier, and asserts that when an
4610operand of the same form as the declarator appears in an expression,
4611it designates a function or object with the scope, storage duration,
4612and type indicated by the declaration specifiers.
4613
4614 In the following subsections, consider a declaration
4615
4616 T D1
4617
4618where T contains the declaration specifiers that specify a type T
4619(such as int) and D1 is a declarator that contains an identifier
4620ident . The type specified for the identifier ident in the various
4621forms of declarator is described inductively using this notation.
4622
4623 If, in the declaration `` T D1 ,'' D1 has the form
4624
4625 identifier
4626
4627then the type specified for ident is T .
4628
4629 If, in the declaration `` T D1 ,'' D1 has the form
4630
4631 ( D )
4632
4633then ident has the type specified by the declaration `` T D .'' Thus,
4634a declarator in parentheses is identical to the unparenthesized
4635declarator, but the binding of complex declarators may be altered by
4636parentheses.
4637
4638"Implementation limits"
4639
4640 The implementation shall allow the specification of types that have
4641at least 12 pointer, array, and function declarators (in any valid
4642combinations) modifying an arithmetic, a structure, a union, or an
4643incomplete type, either directly or via one or more typedef s.
4644
4645Forward references: type definitions ($3.5.6).
4646
4647
46483.5.4.1 Pointer declarators
4649
4650Semantics
4651
4652 If, in the declaration `` T D1 ,'' D1 has the form
4653
4654 * type-qualifier-list<opt> D
4655
4656and the type specified for ident in the declaration `` T D '' is ``
4657"derived-declarator-type-list T" ,'' then the type specified for ident
4658is `` "derived-declarator-type-list type-qualifier-list" pointer to T.''
4659For each type qualifier in the list, ident is a so-qualified pointer.
4660
4661 For two pointer types to be compatible, both shall be identically
4662qualified and both shall be pointers to compatible types.
4663
4664Examples
4665
4666 The following pair of declarations demonstrates the difference
4667between a ``variable pointer to a constant value'' and a ``constant
4668pointer to a variable value.''
4669
4670 const int *ptr_to_constant;
4671 int *const constant_ptr;
4672
4673The contents of the const int pointed to by ptr_to_constant shall not
4674be modified, but ptr_to_constant itself may be changed to point to
4675another const int . Similarly, the contents of the int pointed to by
4676constant_ptr may be modified, but constant_ptr itself shall always
4677point to the same location.
4678
4679 The declaration of the constant pointer constant_ptr may be
4680clarified by including a definition for the type ``pointer to int .''
4681
4682 typedef int *int_ptr;
4683 const int_ptr constant_ptr;
4684
4685declares constant_ptr as an object that has type ``const-qualified
4686pointer to int .''
4687
4688
46893.5.4.2 Array declarators
4690
4691Constraints
4692
4693 The expression that specifies the size of an array shall be an
4694integral constant expression that has a value greater than zero.
4695
4696Semantics
4697
4698 If, in the declaration `` T D1 ,'' D1 has the form
4699
4700 D[ constant-expression<opt>]
4701
4702and the type specified for ident in the declaration `` T D '' is ``
4703"derived-declarator-type-list T" ,'' then the type specified for ident
4704is `` derived-declarator-type-list array of T .''/60/ If the size is
4705not present, the array type is an incomplete type.
4706
4707 For two array types to be compatible, both shall have compatible
4708element types, and if both size specifiers are present, they shall
4709have the same value.
4710
4711Examples
4712
4713 float fa[11], *afp[17];
4714
4715declares an array of float numbers and an array of pointers to float
4716numbers.
4717
4718 Note the distinction between the declarations
4719
4720 extern int *x;
4721 extern int y[];
4722
4723The first declares x to be a pointer to int ; the second declares y to
4724be an array of int of unspecified size (an incomplete type), the
4725storage for which is defined elsewhere.
4726
4727Forward references: function definitions ($3.7.1), initialization ($3.5.7).
4728
4729
47303.5.4.3 Function declarators (including prototypes)
4731
4732Constraints
4733
4734 A function declarator shall not specify a return type that is a
4735function type or an array type.
4736
4737 The only storage-class specifier that shall occur in a parameter
4738declaration is register.
4739
4740 An identifier list in a function declarator that is not part of a
4741function definition shall be empty.
4742
4743Semantics
4744
4745 If, in the declaration `` T D1 ,'' D1 has the form
4746
4747 D( parameter-type-list)
4748 D( identifier-list<opt>)
4749
4750and the type specified for ident in the declaration `` T D '' is ``
4751"derived-declarator-type-list T" ,'' then the type specified for ident
4752is `` derived-declarator-type-list function returning T .''
4753
4754 A parameter type list specifies the types of, and may declare
4755identifiers for, the parameters of the function. If the list
4756terminates with an ellipsis ( , ... ), no information about the number
4757or types of the parameters after the comma is supplied./61/ The
4758special case of void as the only item in the list specifies that the
4759function has no parameters.
4760
4761 In a parameter declaration, a single typedef name in parentheses is
4762taken to be an abstract declarator that specifies a function with a
4763single parameter, not as redundant parentheses around the identifier
4764for a declarator.
4765
4766 The storage-class specifier in the declaration specifiers for a
4767parameter declaration, if present, is ignored unless the declared
4768parameter is one of the members of the parameter type list for a
4769function definition.
4770
4771 An identifier list declares only the identifiers of the parameters
4772of the function. An empty list in a function declarator that is part
4773of a function definition specifies that the function has no
4774parameters. The empty list in a function declarator that is not part
4775of a function definition specifies that no information about the
4776number or types of the parameters is supplied./62/
4777
4778 For two function types to be compatible, both shall specify
4779compatible return types./63/ Moreover, the parameter type lists, if
4780both are present, shall agree in the number of parameters and in use
4781of the ellipsis terminator; corresponding parameters shall have
4782compatible types. If one type has a parameter type list and the other
4783type is specified by a function declarator that is not part of a
4784function definition and that contains an empty identifier list, the
4785parameter list shall not have an ellipsis terminator and the type of
4786each parameter shall be compatible with the type that results from the
4787application of the default argument promotions. If one type has a
4788parameter type list and the other type is specified by a function
4789definition that contains a (possibly empty) identifier list, both
4790shall agree in the number of parameters, and the type of each
4791prototype parameter shall be compatible with the type that results
4792from the application of the default argument promotions to the type of
4793the corresponding identifier. (For each parameter declared with
4794function or array type, its type for these comparisons is the one that
4795results from conversion to a pointer type, as in $3.7.1. For each
4796parameter declared with qualified type, its type for these comparisons
4797is the unqualified version of its declared type.)
4798
4799Examples
4800
4801 The declaration
4802
4803 int f(void), *fip(), (*pfi)();
4804
4805declares a function f with no parameters returning an int , a function
4806fip with no parameter specification returning a pointer to an int ,
4807and a pointer pfi to a function with no parameter specification
4808returning an int . It is especially useful to compare the last two.
4809The binding of *fip() is *(fip()) , so that the declaration suggests,
4810and the same construction in an expression requires, the calling of a
4811function fip , and then using indirection through the pointer result
4812to yield an int . In the declarator (*pfi)() , the extra parentheses
4813are necessary to indicate that indirection through a pointer to a
4814function yields a function designator, which is then used to call the
4815function; it returns an int.
4816
4817 If the declaration occurs outside of any function, the identifiers
4818have file scope and external linkage. If the declaration occurs
4819inside a function, the identifiers of the functions f and fip have
4820block scope and external linkage, and the identifier of the pointer
4821pfi has block scope and no linkage.
4822
4823 Here are two more intricate examples.
4824
4825 int (*apfi[3])(int *x, int *y);
4826
4827declares an array apfi of three pointers to functions returning int .
4828Each of these functions has two parameters that are pointers to int .
4829The identifiers x and y are declared for descriptive purposes only and
4830go out of scope at the end of the declaration of apfi . The
4831declaration
4832
4833 int (*fpfi(int (*)(long), int))(int, ...);
4834
4835declares a function fpfi that returns a pointer to a function
4836returning an int. The function fpfi has two parameters: a pointer to
4837a function returning an int (with one parameter of type long ), and an
4838int . The pointer returned by fpfi points to a function that has at
4839least one parameter, which has type int .
4840
4841Forward references: function definitions ($3.7.1), type names ($3.5.5).
4842
4843
48443.5.5 Type names
4845
4846Syntax
4847
4848 type-name:
4849 specifier-qualifier-list abstract-declarator<opt>
4850
4851 abstract-declarator:
4852 pointer
4853 pointer<opt> direct-abstract-declarator
4854
4855 direct-abstract-declarator:
4856 ( abstract-declarator )
4857 direct-abstract-declarator<opt> [ constant-expression<opt> ]
4858 direct-abstract-declarator<opt> ( parameter-type-list<opt> )
4859
4860Semantics
4861
4862 In several contexts it is desired to specify a type. This is
4863accomplished using a type name, which is syntactically a declaration
4864for a function or an object of that type that omits the
4865identifier./64/
4866
4867Examples
4868
4869 The constructions
4870
4871 (a) int
4872 (b) int *
4873 (c) int *[3]
4874 (d) int (*)[3]
4875 (e) int *()
4876 (f) int (*)(void)
4877 (g) int (*const [])(unsigned int, ...)
4878
4879name respectively the types (a) int , (b) pointer to int , (c) array
4880of three pointers to int , (d) pointer to an array of three int's, (e)
4881function with no parameter specification returning a pointer to int ,
4882(f) pointer to function with no parameters returning an int , and (g)
4883array of an unspecified number of constant pointers to functions, each
4884with one parameter that has type unsigned int and an unspecified
4885number of other parameters, returning an int .
4886
4887
48883.5.6 Type definitions
4889
4890Syntax
4891
4892 typedef-name:
4893 identifier
4894
4895Semantics
4896
4897 In a declaration whose storage-class specifier is typedef , each
4898declarator defines an identifier to be a typedef name that specifies
4899the type specified for the identifier in the way described in $3.5.4.
4900A typedef declaration does not introduce a new type, only a synonym
4901for the type so specified. That is, in the following declarations:
4902
4903 typedef T type_ident;
4904 type_ident D;
4905
4906type_ident is defined as a typedef name with the type specified by the
4907declaration specifiers in T (known as T ), and the identifier in D has
4908the type `` "derived-declarator-type-list T" '' where the
4909derived-declarator-type-list is specified by the declarators of D . A
4910typedef name shares the same name space as other identifiers declared
4911in ordinary declarators. If the identifier is redeclared in an inner
4912scope or is declared as a member of a structure or union in the same
4913or an inner scope, the type specifiers shall not be omitted in the
4914inner declaration.
4915
4916Examples
4917
4918 After
4919
4920 typedef int MILES, KLICKSP();
4921 typedef struct { double re, im; } complex;
4922
4923the constructions
4924
4925 MILES distance;
4926 extern KLICKSP *metricp;
4927 complex x;
4928 complex z, *zp;
4929
4930are all valid declarations. The type of distance is int , that of
4931metricp is ``pointer to function with no parameter specification
4932returning int ,'' and that of x and z is the specified structure; zp
4933is a pointer to such a structure. The object distance has a type
4934compatible with any other int object.
4935
4936 After the declarations
4937
4938 typedef struct s1 { int x; } t1, *tp1;
4939 typedef struct s2 { int x; } t2, *tp2;
4940
4941type t1 and the type pointed to by tp1 are compatible. Type t1 is
4942also compatible with type struct s1 , but not compatible with the
4943types struct s2 , t2 , the type pointed to by tp2 , and int .
4944
4945 The following constructions
4946
4947 typedef signed int t;
4948 typedef int plain;
4949 struct tag {
4950 unsigned t:4;
4951 const t:5;
4952 plain r:5;
4953 };
4954
4955declare a typedef name t with type signed int , a typedef name plain
4956with type int , and a structure with three bit-field members, one
4957named t that contains values in the range [0,15], an unnamed
4958const-qualified bit-field which (if it could be accessed) would
4959contain values in at least the range [-15,+15], and one named r that
4960contains values in the range [0,31] or values in at least the range
4961[-15,+15]. (The choice of range is implementation-defined.) If these
4962declarations are followed in an inner scope by
4963
4964 t f(t (t));
4965 long t;
4966
4967then a function f is declared with type ``function returning signed
4968int with one unnamed parameter with type pointer to function returning
4969signed int with one unnamed parameter with type signed int ,'' and an
4970identifier t with type long .
4971
4972
49733.5.7 Initialization
4974
4975Syntax
4976
4977 initializer:
4978 assignment-expression
4979 { initializer-list }
4980 { initializer-list , }
4981
4982 initializer-list:
4983 initializer
4984 initializer-list , initializer
4985
4986Constraints
4987
4988 There shall be no more initializers in an initializer list than
4989there are objects to be initialized.
4990
4991 The type of the entity to be initialized shall be an object type or
4992an array of unknown size.
4993
4994 All the expressions in an initializer for an object that has static
4995storage duration or in an initializer list for an object that has
4996aggregate or union type shall be constant expressions.
4997
4998 If the declaration of an identifier has block scope, and the
4999identifier has external or internal linkage, there shall be no
5000initializer for the identifier.
5001
5002Semantics
5003
5004 An initializer specifies the initial value stored in an object.
5005
5006 All unnamed structure or union members are ignored during initialization.
5007
5008 If an object that has static storage duration is not initialized
5009explicitly, it is initialized implicitly as if every member that has
5010arithmetic type were assigned 0 and every member that has pointer type
5011were assigned a null pointer constant. If an object that has
5012automatic storage duration is not initialized explicitly, its value is
5013indeterminate./65/
5014
5015 The initializer for a scalar shall be a single expression,
5016optionally enclosed in braces. The initial value of the object is
5017that of the expression; the same type constraints and conversions as
5018for simple assignment apply.
5019
5020 A brace-enclosed initializer for a union object initializes the
5021member that appears first in the declaration list of the union type.
5022
5023 The initializer for a structure or union object that has automatic
5024storage duration either shall be an initializer list as described
5025below, or shall be a single expression that has compatible structure
5026or union type. In the latter case, the initial value of the object is
5027that of the expression.
5028
5029 The rest of this section deals with initializers for objects that
5030have aggregate or union type.
5031
5032 An array of character type may be initialized by a character string
5033literal, optionally enclosed in braces. Successive characters of the
5034character string literal (including the terminating null character if
5035there is room or if the array is of unknown size) initialize the
5036members of the array.
5037
5038 An array with element type compatible with wchar_t may be
5039initialized by a wide string literal, optionally enclosed in braces.
5040Successive codes of the wide string literal (including the terminating
5041zero-valued code if there is room or if the array is of unknown size)
5042initialize the members of the array.
5043
5044 Otherwise, the initializer for an object that has aggregate type
5045shall be a brace-enclosed list of initializers for the members of the
5046aggregate, written in increasing subscript or member order; and the
5047initializer for an object that has union type shall be a
5048brace-enclosed initializer for the first member of the union.
5049
5050 If the aggregate contains members that are aggregates or unions, or
5051if the first member of a union is an aggregate or union, the rules
5052apply recursively to the subaggregates or contained unions. If the
5053initializer of a subaggregate or contained union begins with a left
5054brace, the initializers enclosed by that brace and its matching right
5055brace initialize the members of the subaggregate or the first member
5056of the contained union. Otherwise, only enough initializers from the
5057list are taken to account for the members of the first subaggregate or
5058the first member of the contained union; any remaining initializers
5059are left to initialize the next member of the aggregate of which the
5060current subaggregate or contained union is a part.
5061
5062 If there are fewer initializers in a list than there are members of
5063an aggregate, the remainder of the aggregate shall be initialized
5064implicitly the same as objects that have static storage duration.
5065
5066 If an array of unknown size is initialized, its size is determined
5067by the number of initializers provided for its members. At the end of
5068its initializer list, the array no longer has incomplete type.
5069
5070Examples
5071
5072 The declaration
5073
5074 int x[] = { 1, 3, 5 };
5075
5076defines and initializes x as a one-dimensional array object that has
5077three members, as no size was specified and there are three
5078initializers.
5079
5080 float y[4][3] = {
5081 { 1, 3, 5 },
5082 { 2, 4, 6 },
5083 { 3, 5, 7 },
5084 };
5085
5086is a definition with a fully bracketed initialization: 1, 3, and 5
5087initialize the first row of the array object y[0] , namely y[0][0] ,
5088y[0][1] , and y[0][2] . Likewise the next two lines initialize y[1]
5089and y[2] . The initializer ends early, so y[3] is initialized with
5090zeros. Precisely the same effect could have been achieved by
5091
5092 float y[4][3] = {
5093 1, 3, 5, 2, 4, 6, 3, 5, 7
5094 };
5095
5096The initializer for y[0] does not begin with a left brace, so three
5097items from the list are used. Likewise the next three are taken
5098successively for y[1] and y[2] . Also,
5099
5100 float z[4][3] = {
5101 { 1 }, { 2 }, { 3 }, { 4 }
5102 };
5103
5104initializes the first column of z as specified and initializes the
5105rest with zeros.
5106
5107 struct { int a[3], b; } w[] = { { 1 }, 2 };
5108
5109is a definition with an inconsistently bracketed initialization. It
5110defines an array with two member structures: w[0].a[0] is 1 and
5111w[1].a[0] is 2; all the other elements are zero.
5112
5113 The declaration
5114
5115 short q[4][3][2] = {
5116 { 1 },
5117 { 2, 3 },
5118 { 4, 5, 6 }
5119 };
5120
5121contains an incompletely but consistently bracketed initialization.
5122It defines a three-dimensional array object: q[0][0][0] is 1,
5123q[1][0][0] is 2, q[1][0][1] is 3, and 4, 5, and 6 initialize
5124q[2][0][0] , q[2][0][1] , and q[2][1][0] , respectively; all the rest
5125are zero. The initializer for q[0][0][0] does not begin with a left
5126brace, so up to six items from the current list may be used. There is
5127only one, so the values for the remaining five members are initialized
5128with zero. Likewise, the initializers for q[1][0][0] and q[2][0][0]
5129do not begin with a left brace, so each uses up to six items,
5130initializing their respective two-dimensional subaggregates. If there
5131had been more than six items in any of the lists, a diagnostic message
5132would occur. The same initialization result could have been achieved
5133by:
5134
5135 short q[4][3][2] = {
5136 1, 0, 0, 0, 0, 0,
5137 2, 3, 0, 0, 0, 0,
5138 4, 5, 6
5139 };
5140
5141or by:
5142
5143 short q[4][3][2] = {
5144 {
5145 { 1 },
5146 },
5147 {
5148 { 2, 3 },
5149 },
5150 {
5151 { 4, 5 },
5152 { 6 },
5153 }
5154 };
5155
5156in a fully-bracketed form.
5157
5158 Note that the fully-bracketed and minimally-bracketed forms of
5159initialization are, in general, less likely to cause confusion.
5160
5161 Finally, the declaration
5162
5163 char s[] = "abc", t[3] = "abc";
5164
5165defines ``plain'' char array objects s and t whose members are
5166initialized with character string literals. This declaration is
5167identical to
5168
5169 char s[] = { 'a', 'b', 'c', '\0' },
5170 t[] = { 'a', 'b', 'c' };
5171
5172The contents of the arrays are modifiable. On the other hand, the
5173declaration
5174
5175 char *p = "abc";
5176
5177defines p with type ``pointer to char '' that is initialized to point
5178to an object with type ``array of char '' whose members are
5179initialized with a character string literal. If an attempt is made to
5180use p to modify the contents of the array, the behavior is undefined.
5181
5182Forward references: common definitions <stddef.h> ($4.1.5).
5183
5184
51853.6 STATEMENTS
5186
5187Syntax
5188
5189 statement:
5190 labeled-statement
5191 compound-statement
5192 expression-statement
5193 selection-statement
5194 iteration-statement
5195 jump-statement
5196
5197Semantics
5198
5199 A statement specifies an action to be performed. Except as
5200indicated, statements are executed in sequence.
5201
5202 A full expression is an expression that is not part of another
5203expression. Each of the following is a full expression: an
5204initializer; the expression in an expression statement; the
5205controlling expression of a selection statement ( if or switch ); the
5206controlling expression of a while or do statement; each of the three
5207expressions of a for statement; the expression in a return statement.
5208The end of a full expression is a sequence point.
5209
5210Forward references: expression and null statements ($3.6.3), selection
5211statements ($3.6.4), iteration statements ($3.6.5), the return
5212statement ($3.6.6.4).
5213
5214
52153.6.1 Labeled statements
5216
5217Syntax
5218
5219 labeled-statement:
5220 identifier : statement
5221 case constant-expression : statement
5222 default : statement
5223
5224Constraints
5225
5226 A case or default label shall appear only in a switch statement.
5227Further constraints on such labels are discussed under the switch
5228statement.
5229
5230Semantics
5231
5232 Any statement may be preceded by a prefix that declares an
5233identifier as a label name. Labels in themselves do not alter the
5234flow of control, which continues unimpeded across them.
5235
5236Forward references: the goto statement ($3.6.6.1), the switch
5237statement ($3.6.4.2).
5238
5239
52403.6.2 Compound statement, or block
5241
5242Syntax
5243
5244 compound-statement:
5245 { declaration-list<opt> statement-list<opt> }
5246
5247 declaration-list:
5248 declaration
5249 declaration-list declaration
5250
5251 statement-list:
5252 statement
5253 statement-list statement
5254
5255Semantics
5256
5257 A compound statement (also called a block )allows a set of
5258statements to be grouped into one syntactic unit, which may have its
5259own set of declarations and initializations (as discussed in
5260$3.1.2.4). The initializers of objects that have automatic storage
5261duration are evaluated and the values are stored in the objects in the
5262order their declarators appear in the translation unit.
5263
5264
52653.6.3 Expression and null statements
5266
5267Syntax
5268
5269 expression-statement:
5270 expression<opt> ;
5271
5272Semantics
5273
5274 The expression in an expression statement is evaluated as a void
5275expression for its side effects./66/
5276
5277 A null statement (consisting of just a semicolon) performs no
5278operations.
5279
5280Examples
5281
5282 If a function call is evaluated as an expression statement for its
5283side effects only, the discarding of its value may be made explicit by
5284converting the expression to a void expression by means of a cast:
5285
5286 int p(int);
5287 /*...*/
5288 (void)p(0);
5289
5290
5291 In the program fragment
5292
5293 char *s;
5294 /*...*/
5295 while (*s++ != '\0')
5296 ;
5297
5298a null statement is used to supply an empty loop body to the iteration
5299statement.
5300
5301 A null statement may also be used to carry a label just before the
5302closing } of a compound statement.
5303
5304 while (loop1) {
5305 /*...*/
5306 while (loop2) {
5307 /*...*/
5308 if (want_out)
5309 goto end_loop1;
5310 /*...*/
5311 }
5312 /*...*/
5313 end_loop1: ;
5314 }
5315
5316
5317
5318Forward references: iteration statements ($3.6.5).
5319
5320
53213.6.4 Selection statements
5322
5323Syntax
5324
5325 selection-statement:
5326 if ( expression ) statement
5327 if ( expression ) statement else statement
5328 switch ( expression ) statement
5329
5330Semantics
5331
5332 A selection statement selects among a set of statements depending
5333on the value of a controlling expression.
5334
5335
53363.6.4.1 The if statement
5337
5338Constraints
5339
5340 The controlling expression of an if statement shall have scalar type.
5341
5342Semantics
5343
5344 In both forms, the first substatement is executed if the expression
5345compares unequal to 0. In the else form, the second substatement is
5346executed if the expression compares equal to 0. If the first
5347substatement is reached via a label, the second substatement is not
5348executed.
5349
5350 An else is associated with the lexically immediately preceding else
5351-less if that is in the same block (but not in an enclosed block).
5352
5353
53543.6.4.2 The switch statement
5355
5356Constraints
5357
5358 The controlling expression of a switch statement shall have
5359integral type. The expression of each case label shall be an integral
5360constant expression. No two of the case constant expressions in the
5361same switch statement shall have the same value after conversion.
5362There may be at most one default label in a switch statement. (Any
5363enclosed switch statement may have a default label or case constant
5364expressions with values that duplicate case constant expressions in
5365the enclosing switch statement.)
5366
5367Semantics
5368
5369 A switch statement causes control to jump to, into, or past the
5370statement that is the switch body, depending on the value of a
5371controlling expression, and on the presence of a default label and the
5372values of any case labels on or in the switch body. A case or default
5373label is accessible only within the closest enclosing switch
5374statement.
5375
5376 The integral promotions are performed on the controlling
5377expression. The constant expression in each case label is converted
5378to the promoted type of the controlling expression. If a converted
5379value matches that of the promoted controlling expression, control
5380jumps to the statement following the matched case label. Otherwise,
5381if there is a default label, control jumps to the labeled statement.
5382If no converted case constant expression matches and there is no
5383default label, no part of the switch body is executed.
5384
5385"Implementation limits"
5386
5387 As discussed previously ($2.2.4.1), the implementation may limit
5388the number of case values in a switch statement.
5389
5390
53913.6.5 Iteration statements
5392
5393Syntax
5394
5395 iteration-statement:
5396 while ( expression ) statement
5397 do statement while ( expression ) ;
5398 for ( expression<opt> ; expression<opt> ;
5399 expression<opt> ) statement
5400
5401Constraints
5402
5403 The controlling expression of an iteration statement shall have scalar type.
5404Semantics
5405
5406 An iteration statement causes a statement called the loop body to
5407be executed repeatedly until the controlling expression compares equal
5408to 0.
5409
5410
54113.6.5.1 The while statement
5412
5413 The evaluation of the controlling expression takes place before
5414each execution of the loop body.
5415
5416
54173.6.5.2 The do statement
5418
5419 The evaluation of the controlling expression takes place after each
5420execution of the loop body.
5421
5422
54233.6.5.3 The for statement
5424
5425 Except for the behavior of a continue statement in the loop body,
5426the statement
5427
5428 for ( expression-1 ; expression-2 ; expression-3 ) statement
5429
5430and the sequence of statements
5431
5432 expression-1 ;
5433 while ( expression-2) {
5434 statement
5435 expression-3 ;
5436 }
5437
5438are equivalent./67/ expression-1 expression-2 , expression-3
5439
5440 Both expression-1 and expression-3 may be omitted. Each is
5441evaluated as a void expression. An omitted expression-2 is replaced
5442by a nonzero constant.
5443
5444Forward references: the continue statement ($3.6.6.2).
5445
5446
54473.6.6 Jump statements
5448
5449Syntax
5450
5451 jump-statement:
5452 goto identifier ;
5453 continue ;
5454 break ;
5455 return expression<opt> ;
5456
5457Semantics
5458
5459 A jump statement causes an unconditional jump to another place.
5460
5461
54623.6.6.1 The goto statement
5463
5464Constraints
5465
5466 The identifier in a goto statement shall name a label located
5467somewhere in the current function.
5468
5469Semantics
5470
5471 A goto statement causes an unconditional jump to the statement
5472prefixed by the named label in the current function.
5473
5474
54753.6.6.2 The continue statement
5476
5477Constraints
5478
5479 A continue statement shall appear only in or as a loop body.
5480
5481Semantics
5482
5483 A continue statement causes a jump to the loop-continuation portion
5484of the smallest enclosing iteration statement; that is, to the end of
5485the loop body. More precisely, in each of the statements
5486
5487 while (/*...*/) { do { for (/*...*/) {
5488 /*...*/ /*...*/ /*...*/
5489 continue; continue; continue;
5490 /*...*/ /*...*/ /*...*/
5491 contin: ; contin: ; contin: ;
5492 } } while (/*...*/); }
5493
5494unless the continue statement shown is in an enclosed iteration
5495statement (in which case it is interpreted within that statement), it
5496is equivalent to goto contin; ./68/
5497
5498
54993.6.6.3 The break statement
5500
5501Constraints
5502
5503 A break statement shall appear only in or as a switch body or loop body.
5504
5505Semantics
5506
5507 A break statement terminates execution of the smallest enclosing
5508switch or iteration statement.
5509
5510
55113.6.6.4 The return statement
5512
5513Constraints
5514
5515 A return statement with an expression shall not appear in a
5516function whose return type is void .
5517
5518Semantics
5519
5520 A return statement terminates execution of the current function and
5521returns control to its caller. A function may have any number of
5522return statements, with and without expressions.
5523
5524 If a return statement with an expression is executed, the value of
5525the expression is returned to the caller as the value of the function
5526call expression. If the expression has a type different from that of
5527the function in which it appears, it is converted as if it were
5528assigned to an object of that type.
5529
5530 If a return statement without an expression is executed, and the
5531value of the function call is used by the caller, the behavior is
5532undefined. Reaching the } that terminates a function is equivalent to
5533executing a return statement without an expression.
5534
5535
55363.7 EXTERNAL DEFINITIONS
5537
5538Syntax
5539
5540 translation-unit:
5541 external-declaration
5542 translation-unit external-declaration
5543
5544 external-declaration:
5545 function-definition
5546 declaration
5547
5548Constraints
5549
5550 The storage-class specifiers auto and register shall not appear in
5551the declaration specifiers in an external declaration.
5552
5553 There shall be no more than one external definition for each
5554identifier declared with internal linkage in a translation unit.
5555Moreover, if an identifier declared with internal linkage is used in
5556an expression (other than as a part of the operand of a sizeof
5557operator), there shall be exactly one external definition for the
5558identifier in the translation unit.
5559
5560Semantics
5561
5562 As discussed in $2.1.1.1, the unit of program text after
5563preprocessing is a translation unit, which consists of a sequence of
5564external declarations. These are described as ``external'' because
5565they appear outside any function (and hence have file scope). As
5566discussed in $3.5, a declaration that also causes storage to be
5567reserved for an object or a function named by the identifier is a
5568definition.
5569
5570 An external definition is an external declaration that is also a
5571definition of a function or an object. If an identifier declared with
5572external linkage is used in an expression (other than as part of the
5573operand of a sizeof operator), somewhere in the entire program there
5574shall be exactly one external definition for the identifier./69/
5575
5576
55773.7.1 Function definitions
5578
5579Syntax
5580
5581 function-definition:
5582 declaration-specifiers<opt> declarator
5583 declaration-list<opt> compound-statement
5584
5585Constraints
5586
5587 The identifier declared in a function definition (which is the name
5588of the function) shall have a function type, as specified by the
5589declarator portion of the function definition./70/
5590
5591 The return type of a function shall be void or an object type other
5592than array.
5593
5594 The storage-class specifier, if any, in the declaration specifiers
5595shall be either extern or static .
5596
5597 If the declarator includes a parameter type list, the declaration
5598of each parameter shall include an identifier (except for the special
5599case of a parameter list consisting of a single parameter of type void,
5600in which there shall not be an identifier). No declaration list
5601shall follow.
5602
5603 If the declarator includes an identifier list, only the identifiers
5604it names shall be declared in the declaration list. An identifier
5605declared as a typedef name shall not be redeclared as a parameter.
5606The declarations in the declaration list shall contain no
5607storage-class specifier other than register and no initializations.
5608
5609Semantics
5610
5611 The declarator in a function definition specifies the name of the
5612function being defined and the identifiers of its parameters. If the
5613declarator includes a parameter type list, the list also specifies the
5614types of all the parameters; such a declarator also serves as a
5615function prototype for later calls to the same function in the same
5616translation unit. If the declarator includes an identifier list,/71/
5617the types of the parameters may be declared in a following declaration
5618list. Any parameter that is not declared has type int .
5619
5620 If a function that accepts a variable number of arguments is
5621defined without a parameter type list that ends with the ellipsis
5622notation, the behavior is undefined.
5623
5624 On entry to the function the value of each argument expression
5625shall be converted to the type of its corresponding parameter, as if
5626by assignment to the parameter. Array expressions and function
5627designators as arguments are converted to pointers before the call. A
5628declaration of a parameter as ``array of type '' shall be adjusted to
5629``pointer to type ,'' and a declaration of a parameter as ``function
5630returning type '' shall be adjusted to ``pointer to function returning
5631type ,'' as in $3.2.2.1. The resulting parameter type shall be an
5632object type.
5633
5634 Each parameter has automatic storage duration. Its identifier is
5635an lvalue./72/ The layout of the storage for parameters is
5636unspecified.
5637
5638Examples
5639
5640 extern int max(int a, int b)
5641 {
5642 return a > b ? a : b;
5643 }
5644
5645Here extern is the storage-class specifier and int is the type
5646specifier (each of which may be omitted as those are the defaults);
5647max(int a, int b) is the function declarator; and
5648
5649 { return a > b ? a : b; }
5650
5651is the function body. The following similar definition uses the
5652identifier-list form for the parameter declarations:
5653
5654 extern int max(a, b)
5655 int a, b;
5656 {
5657 return a > b ? a : b;
5658 }
5659
5660Here int a, b; is the declaration list for the parameters, which may
5661be omitted because those are the defaults. The difference between
5662these two definitions is that the first form acts as a prototype
5663declaration that forces conversion of the arguments of subsequent
5664calls to the function, whereas the second form may not.
5665
5666 To pass one function to another, one might say
5667
5668 int f(void);
5669 /*...*/
5670 g(f);
5671
5672Note that f must be declared explicitly in the calling function, as
5673its appearance in the expression g(f) was not followed by ( . Then
5674the definition of g might read
5675
5676 g(int (*funcp)(void))
5677 {
5678 /*...*/ (*funcp)() /* or funcp() ... */
5679 }
5680
5681or, equivalently,
5682
5683 g(int func(void))
5684 {
5685 /*...*/ func() /* or (*func)() ... */
5686 }
5687
5688
56893.7.2 External object definitions
5690
5691Semantics
5692
5693 If the declaration of an identifier for an object has file scope
5694and an initializer, the declaration is an external definition for the
5695identifier.
5696
5697 A declaration of an identifier for an object that has file scope
5698without an initializer, and without a storage-class specifier or with
5699the storage-class specifier static , constitutes a tentative
5700definition. If a translation unit contains one or more tentative
5701definitions for an identifier, and the translation unit contains no
5702external definition for that identifier, then the behavior is exactly
5703as if the translation unit contains a file scope declaration of that
5704identifier, with the composite type as of the end of the translation
5705unit, with an initializer equal to 0.
5706
5707 If the declaration of an identifier for an object is a tentative
5708definition and has internal linkage, the declared type shall not be an
5709incomplete type.
5710
5711Examples
5712
5713 int i1 = 1; /* definition, external linkage */
5714 static int i2 = 2; /* definition, internal linkage */
5715 extern int i3 = 3; /* definition, external linkage */
5716 int i4; /* tentative definition, external linkage */
5717 static int i5; /* tentative definition, internal linkage */
5718
5719 int i1; /* valid tentative definition, refers to previous */
5720 int i2; /* $3.1.2.2 renders undefined, linkage disagreement */
5721 int i3; /* valid tentative definition, refers to previous */
5722 int i4; /* valid tentative definition, refers to previous */
5723 int i5; /* $3.1.2.2 renders undefined, linkage disagreement */
5724
5725
5726
5727 extern int i1; /* refers to previous, whose linkage is external */
5728 extern int i2; /* refers to previous, whose linkage is internal */
5729 extern int i3; /* refers to previous, whose linkage is external */
5730 extern int i4; /* refers to previous, whose linkage is external */
5731 extern int i5; /* refers to previous, whose linkage is internal */
5732
5733
57343.8 PREPROCESSING DIRECTIVES
5735
5736Syntax
5737
5738 preprocessing-file:
5739 group<opt>
5740
5741 group:
5742 group-part
5743 group group-part
5744
5745 group-part:
5746 pp-tokens<opt> new-line
5747 if-section
5748 control-line
5749
5750 if-section:
5751 if-group elif-groups<opt> else-group<opt> endif-line
5752
5753 if-group:
5754 # if constant-expression new-line group<opt>
5755 # ifdef identifier new-line group<opt>
5756 # ifndef identifier new-line group<opt>
5757
5758 elif-groups:
5759 elif-group
5760 elif-groups elif-group
5761
5762 elif-group:
5763 # elif constant-expression new-line group<opt>
5764
5765 else-group:
5766 # else new-line group<opt>
5767
5768 endif-line:
5769 # endif new-line
5770
5771 control-line:
5772 # include pp-tokens new-line
5773 # define identifier replacement-list new-line
5774 # define identifier lparen identifier-list<opt> )
5775 replacement-list new-line
5776 # undef identifier new-line
5777 # line pp-tokens new-line
5778 # error pp-tokens<opt> new-line
5779 # pragma pp-tokens<opt> new-line
5780 # new-line
5781
5782 lparen:
5783 the left-parenthesis character without preceding white-space
5784
5785 replacement-list:
5786 pp-tokens<opt>
5787
5788 pp-tokens:
5789 preprocessing-token
5790 pp-tokens preprocessing-token
5791
5792 new-line:
5793 the new-line character
5794
5795Description
5796
5797 A preprocessing directive consists of a sequence of preprocessing
5798tokens that begins with a # preprocessing token that is either the
5799first character in the source file (optionally after white space
5800containing no new-line characters) or that follows white space
5801containing at least one new-line character, and is ended by the next
5802new-line character./73/
5803
5804Constraints
5805
5806 The only white-space characters that shall appear between
5807preprocessing tokens within a preprocessing directive (from just after
5808the introducing # preprocessing token through just before the
5809terminating new-line character) are space and horizontal-tab
5810(including spaces that have replaced comments in translation phase 3).
5811
5812Semantics
5813
5814 The implementation can process and skip sections of source files
5815conditionally, include other source files, and replace macros. These
5816capabilities are called preprocessing , because conceptually they
5817occur before translation of the resulting translation unit.
5818
5819 The preprocessing tokens within a preprocessing directive are not
5820subject to macro expansion unless otherwise stated.
5821
5822
58233.8.1 Conditional inclusion
5824
5825Constraints
5826
5827 The expression that controls conditional inclusion shall be an
5828integral constant expression except that: it shall not contain a cast;
5829identifiers (including those lexically identical to keywords) are
5830interpreted as described below;/74/ and it may contain unary operator
5831expressions of the form
5832
5833 defined identifier
5834 defined ( identifier )
5835
5836which evaluate to 1 if the identifier is currently defined as a macro
5837name (that is, if it is predefined or if it has been the subject of a
5838#define preprocessing directive without an intervening #undef
5839directive with the same subject identifier), 0 if it is not.
5840
5841 Each preprocessing token that remains after all macro replacements
5842have occurred shall be in the lexical form of a token.
5843
5844Semantics
5845
5846 Preprocessing directives of the forms
5847
5848 # if constant-expression new-line group<opt>
5849 # elif constant-expression new-line group<opt>
5850
5851check whether the controlling constant expression evaluates to
5852nonzero.
5853
5854 Prior to evaluation, macro invocations in the list of preprocessing
5855tokens that will become the controlling constant expression are
5856replaced (except for those macro names modified by the defined unary
5857operator), just as in normal text. If the token defined is generated
5858as a result of this replacement process, the behavior is undefined.
5859After all replacements are finished, the resulting preprocessing
5860tokens are converted into tokens, and then all remaining identifiers
5861are replaced with 0 . The resulting tokens comprise the controlling
5862constant expression which is evaluated according to the rules of $3.4
5863using arithmetic that has at least the ranges specified in $2.2.4.2,
5864except that int and unsigned int act as if they have the same
5865representation as, respectively, long and unsigned long . This
5866includes interpreting character constants, which may involve
5867converting escape sequences into execution character set members.
5868Whether the numeric value for these character constants matches the
5869value obtained when an identical character constant occurs in an
5870expression (other than within a #if or #elif directive) is
5871implementation-defined./75/ Also, whether a single-character character
5872constant may have a negative value is implementation-defined.
5873
5874 Preprocessing directives of the forms
5875
5876 # ifdef identifier new-line group<opt>
5877 # ifndef identifier new-line group<opt>
5878
5879check whether the identifier is or is not currently defined as a macro
5880name. Their conditions are equivalent to #if defined identifier and
5881#if !defined identifier respectively.
5882
5883 Each directive's condition is checked in order. If it evaluates to
5884false (zero), the group that it controls is skipped: directives are
5885processed only through the name that determines the directive in order
5886to keep track of the level of nested conditionals; the rest of the
5887directives' preprocessing tokens are ignored, as are the other
5888preprocessing tokens in the group. Only the first group whose control
5889condition evaluates to true (nonzero) is processed. If none of the
5890conditions evaluates to true, and there is a #else directive, the
5891group controlled by the #else is processed; lacking a #else directive,
5892all the groups until the #endif are skipped./76/
5893
5894Forward references: macro replacement ($3.8.3), source file inclusion
5895($3.8.2).
5896
5897
58983.8.2 Source file inclusion
5899
5900Constraints
5901
5902 A #include directive shall identify a header or source file that
5903can be processed by the implementation.
5904
5905Semantics
5906
5907 A preprocessing directive of the form
5908
5909 # include <h-char-sequence> new-line
5910
5911searches a sequence of implementation-defined places for a header
5912identified uniquely by the specified sequence between the < and >
5913delimiters, and causes the replacement of that directive by the entire
5914contents of the header. How the places are specified or the header
5915identified is implementation-defined.
5916
5917 A preprocessing directive of the form
5918
5919 # include "q-char-sequence" new-line
5920
5921causes the replacement of that directive by the entire contents of the
5922source file identified by the specified sequence between the
5923delimiters. The named source file is searched for in an
5924implementation-defined manner. If this search is not supported, or if
5925the search fails, the directive is reprocessed as if it read
5926
5927 # include <h-char-sequence> new-line
5928
5929with the identical contained sequence (including > characters, if any)
5930from the original directive.
5931
5932 A preprocessing directive of the form
5933
5934 # include pp-tokens new-line
5935
5936(that does not match one of the two previous forms) is permitted. The
5937preprocessing tokens after include in the directive are processed just
5938as in normal text. (Each identifier currently defined as a macro name
5939is replaced by its replacement list of preprocessing tokens.) The
5940directive resulting after all replacements shall match one of the two
5941previous forms./77/ The method by which a sequence of preprocessing
5942tokens between a < and a > preprocessing token pair or a pair of
5943characters is combined into a single header name preprocessing token
5944is implementation-defined.
5945
5946 There shall be an implementation-defined mapping between the
5947delimited sequence and the external source file name. The
5948implementation shall provide unique mappings for sequences consisting
5949of one or more letters (as defined in $2.2.1) followed by a period (.)
5950and a single letter. The implementation may ignore the distinctions
5951of alphabetical case and restrict the mapping to six significant
5952characters before the period.
5953
5954 A #include preprocessing directive may appear in a source file that
5955has been read because of a #include directive in another file, up to
5956an implementation-defined nesting limit (see $2.2.4.1).
5957
5958Examples
5959
5960 The most common uses of #include preprocessing directives are as in
5961the following:
5962
5963 #include <stdio.h>
5964 #include "myprog.h"
5965
5966
5967 This example illustrates a macro-replaced #include directive:
5968
5969 #if VERSION == 1
5970 #define INCFILE "vers1.h"
5971 #elif VERSION == 2
5972 #define INCFILE "vers2.h"
5973 /* and so on */
5974 #else
5975 #define INCFILE "versN.h"
5976 #endif
5977 /*...*/
5978 #include INCFILE
5979
5980Forward references: macro replacement ($3.8.3).
5981
5982
59833.8.3 Macro replacement
5984
5985Constraints
5986
5987 Two replacement lists are identical if and only if the
5988preprocessing tokens in both have the same number, ordering, spelling,
5989and white-space separation, where all white-space separations are
5990considered identical.
5991
5992 An identifier currently defined as a macro without use of lparen
5993(an object-like macro) may be redefined by another #define
5994preprocessing directive provided that the second definition is an
5995object-like macro definition and the two replacement lists are
5996identical.
5997
5998 An identifier currently defined as a macro using lparen (a
5999function-like macro) may be redefined by another #define preprocessing
6000directive provided that the second definition is a function-like macro
6001definition that has the same number and spelling of parameters, and
6002the two replacement lists are identical.
6003
6004 The number of arguments in an invocation of a function-like macro
6005shall agree with the number of parameters in the macro definition, and
6006there shall exist a ) preprocessing token that terminates the
6007invocation.
6008
6009 A parameter identifier in a function-like macro shall be uniquely
6010declared within its scope.
6011
6012Semantics
6013
6014 The identifier immediately following the define is called the macro
6015name. Any white-space characters preceding or following the
6016replacement list of preprocessing tokens are not considered part of
6017the replacement list for either form of macro.
6018
6019 If a # preprocessing token, followed by an identifier, occurs
6020lexically at the point at which a preprocessing directive could begin,
6021the identifier is not subject to macro replacement.
6022
6023 A preprocessing directive of the form
6024
6025 # define identifier replacement-list new-line
6026
6027defines an object-like macro that causes each subsequent instance of
6028the macro name/78/ to be replaced by the replacement list of
6029preprocessing tokens that constitute the remainder of the directive.
6030The replacement list is then rescanned for more macro names as
6031specified below.
6032
6033 A preprocessing directive of the form
6034
6035 # define identifier lparen identifier-list<opt> )
6036 replacement-list new-line
6037
6038defines a function-like macro with arguments, similar syntactically to
6039a function call. The parameters are specified by the optional list of
6040identifiers, whose scope extends from their declaration in the
6041identifier list until the new-line character that terminates the
6042#define preprocessing directive. Each subsequent instance of the
6043function-like macro name followed by a ( as the next preprocessing
6044token introduces the sequence of preprocessing tokens that is replaced
6045by the replacement list in the definition (an invocation of the
6046macro). The replaced sequence of preprocessing tokens is terminated
6047by the matching ) preprocessing token, skipping intervening matched
6048pairs of left and right parenthesis preprocessing tokens. Within the
6049sequence of preprocessing tokens making up an invocation of a
6050function-like macro, new-line is considered a normal white-space
6051character.
6052
6053 The sequence of preprocessing tokens bounded by the outside-most
6054matching parentheses forms the list of arguments for the function-like
6055macro. The individual arguments within the list are separated by
6056comma preprocessing tokens, but comma preprocessing tokens bounded by
6057nested parentheses do not separate arguments. If (before argument
6058substitution) any argument consists of no preprocessing tokens, the
6059behavior is undefined. If there are sequences of preprocessing tokens
6060within the list of arguments that would otherwise act as preprocessing
6061directives, the behavior is undefined.
6062
6063
60643.8.3.1 Argument substitution
6065
6066 After the arguments for the invocation of a function-like macro
6067have been identified, argument substitution takes place. A parameter
6068in the replacement list, unless preceded by a # or ## preprocessing
6069token or followed by a ## preprocessing token (see below), is replaced
6070by the corresponding argument after all macros contained therein have
6071been expanded. Before being substituted, each argument's
6072preprocessing tokens are completely macro replaced as if they formed
6073the rest of the source file; no other preprocessing tokens are
6074available.
6075
6076
60773.8.3.2 The # operator
6078
6079Constraints
6080
6081 Each # preprocessing token in the replacement list for a
6082function-like macro shall be followed by a parameter as the next
6083preprocessing token in the replacement list.
6084
6085Semantics
6086
6087 If, in the replacement list, a parameter is immediately preceded by
6088a # preprocessing token, both are replaced by a single character
6089string literal preprocessing token that contains the spelling of the
6090preprocessing token sequence for the corresponding argument. Each
6091occurrence of white space between the argument's preprocessing tokens
6092becomes a single space character in the character string literal.
6093White space before the first preprocessing token and after the last
6094preprocessing token comprising the argument is deleted. Otherwise,
6095the original spelling of each preprocessing token in the argument is
6096retained in the character string literal, except for special handling
6097for producing the spelling of string literals and character constants:
6098a \ character is inserted before each and \ character of a character
6099constant or string literal (including the delimiting characters). If
6100the replacement that results is not a valid character string literal,
6101the behavior is undefined. The order of evaluation of # and ##
6102operators is unspecified.
6103
6104
61053.8.3.3 The ## operator
6106
6107Constraints
6108
6109 A ## preprocessing token shall not occur at the beginning or at the
6110end of a replacement list for either form of macro definition.
6111
6112Semantics
6113
6114 If, in the replacement list, a parameter is immediately preceded or
6115followed by a ## preprocessing token, the parameter is replaced by the
6116corresponding argument's preprocessing token sequence.
6117
6118 For both object-like and function-like macro invocations, before
6119the replacement list is reexamined for more macro names to replace,
6120each instance of a ## preprocessing token in the replacement list (not
6121from an argument) is deleted and the preceding preprocessing token is
6122concatenated with the following preprocessing token. If the result is
6123not a valid preprocessing token, the behavior is undefined. The
6124resulting token is available for further macro replacement. The order
6125of evaluation of ## operators is unspecified.
6126
6127
61283.8.3.4 Rescanning and further replacement
6129
6130 After all parameters in the replacement list have been substituted,
6131the resulting preprocessing token sequence is rescanned with the rest
6132of the source file's preprocessing tokens for more macro names to
6133replace.
6134
6135 If the name of the macro being replaced is found during this scan
6136of the replacement list (not including the rest of the source file's
6137preprocessing tokens), it is not replaced. Further, if any nested
6138replacements encounter the name of the macro being replaced, it is not
6139replaced. These nonreplaced macro name preprocessing tokens are no
6140longer available for further replacement even if they are later
6141(re)examined in contexts in which that macro name preprocessing token
6142would otherwise have been replaced.
6143
6144 The resulting completely macro-replaced preprocessing token
6145sequence is not processed as a preprocessing directive even if it
6146resembles one.
6147
6148
61493.8.3.5 Scope of macro definitions
6150
6151 A macro definition lasts (independent of block structure) until a
6152corresponding #undef directive is encountered or (if none is
6153encountered) until the end of the translation unit.
6154
6155 A preprocessing directive of the form
6156
6157 # undef identifier new-line
6158
6159causes the specified identifier no longer to be defined as a macro
6160name. It is ignored if the specified identifier is not currently
6161defined as a macro name.
6162
6163Examples
6164
6165 The simplest use of this facility is to define a ``manifest
6166constant,'' as in
6167
6168 #define TABSIZE 100
6169
6170 int table[TABSIZE];
6171
6172 The following defines a function-like macro whose value is the
6173maximum of its arguments. It has the advantages of working for any
6174compatible types of the arguments and of generating in-line code
6175without the overhead of function calling. It has the disadvantages of
6176evaluating one or the other of its arguments a second time (including
6177side effects) and of generating more code than a function if invoked
6178several times.
6179
6180 #define max(a, b) ((a) > (b) ? (a) : (b))
6181
6182The parentheses ensure that the arguments and the resulting expression
6183are bound properly.
6184
6185 To illustrate the rules for redefinition and reexamination, the
6186sequence
6187
6188 #define x 3
6189 #define f(a) f(x * (a))
6190 #undef x
6191 #define x 2
6192 #define g f
6193 #define z z[0]
6194 #define h g(~
6195 #define m(a) a(w)
6196 #define w 0,1
6197 #define t(a) a
6198
6199 f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
6200 g(x+(3,4)-w) | h 5) & m
6201 (f)^m(m);
6202
6203results in
6204
6205 f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
6206 f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
6207
6208
6209 To illustrate the rules for creating character string literals and
6210concatenating tokens, the sequence
6211
6212 #define str(s) # s
6213 #define xstr(s) str(s)
6214 #define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
6215 x ## s, x ## t)
6216 #define INCFILE(n) vers ## n /* from previous #include example */
6217 #define glue(a, b) a ## b
6218 #define xglue(a, b) glue(a, b)
6219 #define HIGHLOW "hello"
6220 #define LOW LOW ", world"
6221
6222 debug(1, 2);
6223 fputs(str(strncmp("abc\0d", "abc", '\4') /* this goes away */
6224 == 0) str(: @\n), s);
6225 #include xstr(INCFILE(2).h)
6226 glue(HIGH, LOW);
6227 xglue(HIGH, LOW)
6228
6229results in
6230
6231 printf("x" "1" "= %d, x" "2" "= %s", x1, x2);
6232 fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n", s);
6233 #include "vers2.h" (after macro replacement, before file access)
6234 "hello";
6235 "hello" ", world"
6236
6237or, after concatenation of the character string literals,
6238
6239 printf("x1= %d, x2= %s", x1, x2);
6240 fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: @\n", s);
6241 #include "vers2.h" (after macro replacement, before file access)
6242 "hello";
6243 "hello, world"
6244
6245Space around the # and ## tokens in the macro definition is optional.
6246
6247 And finally, to demonstrate the redefinition rules, the following
6248sequence is valid.
6249
6250 #define OBJ_LIKE (1-1)
6251 #define OBJ_LIKE /* white space */ (1-1) /* other */
6252 #define FTN_LIKE(a) ( a )
6253 #define FTN_LIKE( a )( /* note the white space */ \
6254 a /* other stuff on this line
6255 */ )
6256
6257But the following redefinitions are invalid:
6258
6259 #define OBJ_LIKE (0) /* different token sequence */
6260 #define OBJ_LIKE (1 - 1) /* different white space */
6261 #define FTN_LIKE(b) ( a ) /* different parameter usage */
6262 #define FTN_LIKE(b) ( b ) /* different parameter spelling */
6263
6264
62653.8.4 Line control
6266
6267Constraints
6268
6269 The string literal of a #line directive, if present, shall be a
6270character string literal.
6271
6272Semantics
6273
6274 The line number of the current source line is one greater than the
6275number of new-line characters read or introduced in translation phase
62761 ($2.1.1.2) while processing the source file to the current token.
6277
6278 A preprocessing directive of the form
6279
6280 # line digit-sequence new-line
6281
6282causes the implementation to behave as if the following sequence of
6283source lines begins with a source line that has a line number as
6284specified by the digit sequence (interpreted as a decimal integer).
6285
6286 A preprocessing directive of the form
6287
6288 # line digit-sequence " s-char-sequence<opt>" new-line
6289
6290sets the line number similarly and changes the presumed name of the
6291source file to be the contents of the character string literal.
6292
6293 A preprocessing directive of the form
6294
6295 # line pp-tokens new-line
6296
6297(that does not match one of the two previous forms) is permitted. The
6298preprocessing tokens after line on the directive are processed just as
6299in normal text (each identifier currently defined as a macro name is
6300replaced by its replacement list of preprocessing tokens). The
6301directive resulting after all replacements shall match one of the two
6302previous forms and is then processed as appropriate.
6303
6304
63053.8.5 Error directive
6306
6307Semantics
6308
6309 A preprocessing directive of the form
6310
6311 # error pp-tokens<opt> new-line
6312
6313causes the implementation to produce a diagnostic message that
6314includes the specified sequence of preprocessing tokens.
6315
6316
63173.8.6 Pragma directive
6318
6319Semantics
6320
6321 A preprocessing directive of the form
6322
6323 # pragma pp-tokens<opt> new-line
6324
6325causes the implementation to behave in an implementation-defined
6326manner. Any pragma that is not recognized by the implementation is
6327ignored.
6328
6329
63303.8.7 Null directive
6331
6332Semantics
6333
6334 A preprocessing directive of the form
6335
6336 # new-line
6337
6338has no effect.
6339
6340
63413.8.8 Predefined macro names
6342
6343 The following macro names shall be defined by the implementation:
6344The line number of the current source line (a decimal constant). The
6345presumed name of the source file (a character string literal). The
6346date of translation of the source file (a character string literal of
6347the form Mmm dd yyyy , where the names of the months are the same as
6348those generated by the asctime function, and the first character of dd
6349is a space character if the value is less than 10). If the date of
6350translation is not available, an implementation-defined valid date
6351shall be supplied. The time of translation of the source file (a
6352character string literal of the form hh:mm:ss as in the time generated
6353by the asctime function). If the time of translation is not
6354available, an implementation-defined valid time shall be supplied.
6355the decimal constant 1./79/
6356
6357 The values of the predefined macros (except for __LINE__ and
6358__FILE__ ) remain constant throughout the translation unit.
6359
6360 None of these macro names, nor the identifier defined , shall be
6361the subject of a #define or a #undef preprocessing directive. All
6362predefined macro names shall begin with a leading underscore followed
6363by an upper-case letter or a second underscore.
6364
6365Forward references: the asctime function ($4.12.3.1).
6366
6367
63683.9 FUTURE LANGUAGE DIRECTIONS
6369
6370
63713.9.1 External names
6372
6373 Restriction of the significance of an external name to fewer than
637431 characters or to only one case is an obsolescent feature that is a
6375concession to existing implementations.
6376
6377
63783.9.2 Character escape sequences
6379
6380 Lower-case letters as escape sequences are reserved for future
6381standardization. Other characters may be used in extensions.
6382
6383
63843.9.3 Storage-class specifiers
6385
6386 The placement of a storage-class specifier other than at the
6387beginning of the declaration specifiers in a declaration is an
6388obsolescent feature.
6389
6390
63913.9.4 Function declarators
6392
6393 The use of function declarators with empty parentheses (not
6394prototype-format parameter type declarators) is an obsolescent
6395feature.
6396
6397
63983.9.5 Function definitions
6399
6400 The use of function definitions with separate parameter identifier
6401and declaration lists (not prototype-format parameter type and
6402identifier declarators) is an obsolescent feature.
6403
6404
64054. LIBRARY
6406
64074.1 INTRODUCTION
6408
64094.1.1 Definitions of terms
6410
6411 A string is a contiguous sequence of characters terminated by and
6412including the first null character. It is represented by a pointer to
6413its initial (lowest addressed) character and its length is the number
6414of characters preceding the null character.
6415
6416 A letter is a printing character in the execution character set
6417corresponding to any of the 52 required lower-case and upper-case
6418letters in the source character set, listed in $2.2.1.
6419
6420 The decimal-point character is the character used by functions that
6421convert floating-point numbers to or from character sequences to
6422denote the beginning of the fractional part of such character
6423sequences./80/ It is represented in the text and examples by a period,
6424but may be changed by the setlocale function.
6425
6426Forward references: character handling ($4.3), the setlocale function
6427($4.4.1.1).
6428
6429
64304.1.2 Standard headers
6431
6432 Each library function is declared in a header, /81/ whose contents
6433are made available by the #include preprocessing directive. The
6434header declares a set of related functions, plus any necessary types
6435and additional macros needed to facilitate their use. Each header
6436declares and defines only those identifiers listed in its associated
6437section. All external identifiers declared in any of the headers are
6438reserved, whether or not the associated header is included. All
6439external identifiers that begin with an underscore are reserved. All
6440other identifiers that begin with an underscore and either an
6441upper-case letter or another underscore are reserved. If the program
6442defines an external identifier with the same name as a reserved
6443external identifier, even in a semantically equivalent form, the
6444behavior is undefined./82/
6445
6446 The standard headers are
6447
6448 <assert.h> <locale.h> <stddef.h>
6449 <ctype.h> <math.h> <stdio.h>
6450 <errno.h> <setjmp.h> <stdlib.h>
6451 <float.h> <signal.h> <string.h>
6452 <limits.h> <stdarg.h> <time.h>
6453
6454
6455 If a file with the same name as one of the above < and > delimited
6456sequences, not provided as part of the implementation, is placed in
6457any of the standard places for a source file to be included, the
6458behavior is undefined.
6459
6460 Headers may be included in any order; each may be included more
6461than once in a given scope, with no effect different from being
6462included only once, except that the effect of including <assert.h>
6463depends on the definition of NDEBUG . If used, a header shall be
6464included outside of any external declaration or definition, and it
6465shall first be included before the first reference to any of the
6466functions or objects it declares, or to any of the types or macros it
6467defines. Furthermore, the program shall not have any macros with
6468names lexically identical to keywords currently defined prior to the
6469inclusion.
6470
6471Forward references: diagnostics ($4.2).
6472
6473
64744.1.3 Errors <errno.h>
6475
6476 The header <errno.h> defines several macros, all relating to the
6477reporting of error conditions.
6478
6479 The macros are
6480
6481 EDOM
6482 ERANGE
6483
6484which expand to distinct nonzero integral constant expressions; and
6485
6486 errno
6487
6488which expands to a modifiable lvalue/83/ that has type int , the value
6489of which is set to a positive error number by several library
6490functions. It is unspecified whether errno is a macro or an
6491identifier declared with external linkage. If a macro definition is
6492suppressed in order to access an actual object, or a program defines
6493an external identifier with the name errno , the behavior is
6494undefined.
6495
6496 The value of errno is zero at program startup, but is never set to
6497zero by any library function./84/ The value of errno may be set to
6498nonzero by a library function call whether or not there is an error,
6499provided the use of errno is not documented in the description of the
6500function in the Standard.
6501
6502 Additional macro definitions, beginning with E and a digit or E and
6503an upper-case letter,/85/ may also be specified by the implementation.
6504
6505
65064.1.4 Limits <float.h> and <limits.h>
6507
6508 The headers <float.h> and <limits.h> define several macros that
6509expand to various limits and parameters.
6510
6511 The macros, their meanings, and their minimum magnitudes are listed
6512in $2.2.4.2.
6513
6514
65154.1.5 Common definitions <stddef.h>
6516
6517 The following types and macros are defined in the standard header
6518<stddef.h> . Some are also defined in other headers, as noted in
6519their respective sections.
6520
6521 The types are
6522
6523 ptrdiff_t
6524
6525which is the signed integral type of the result of subtracting two
6526pointers;
6527
6528 size_t
6529
6530which is the unsigned integral type of the result of the sizeof
6531operator; and
6532
6533 wchar_t
6534
6535which is an integral type whose range of values can represent distinct
6536codes for all members of the largest extended character set specified
6537among the supported locales; the null character shall have the code
6538value zero and each member of the basic character set defined in
6539$2.2.1 shall have a code value equal to its value when used as the
6540lone character in an integer character constant.
6541
6542 The macros are
6543
6544 NULL
6545
6546which expands to an implementation-defined null pointer constant; and
6547
6548 offsetof( type, member-designator)
6549
6550which expands to an integral constant expression that has type size_t,
6551the value of which is the offset in bytes, to the structure member
6552(designated by member-designator ), from the beginning of its
6553structure (designated by type ). The member-designator shall be such
6554that given
6555
6556 static type t;
6557
6558then the expression &(t. member-designator ) evaluates to an address
6559constant. (If the specified member is a bit-field, the behavior is
6560undefined.)
6561
6562Forward references: localization ($4.4).
6563
6564
65654.1.6 Use of library functions
6566
6567 Each of the following statements applies unless explicitly stated
6568otherwise in the detailed descriptions that follow. If an argument to
6569a function has an invalid value (such as a value outside the domain of
6570the function, or a pointer outside the address space of the program,
6571or a null pointer), the behavior is undefined. Any function declared
6572in a header may be implemented as a macro defined in the header, so a
6573library function should not be declared explicitly if its header is
6574included. Any macro definition of a function can be suppressed
6575locally by enclosing the name of the function in parentheses, because
6576the name is then not followed by the left parenthesis that indicates
6577expansion of a macro function name. For the same syntactic reason, it
6578is permitted to take the address of a library function even if it is
6579also defined as a macro./86/ The use of #undef to remove any macro
6580definition will also ensure that an actual function is referred to.
6581Any invocation of a library function that is implemented as a macro
6582will expand to code that evaluates each of its arguments exactly once,
6583fully protected by parentheses where necessary, so it is generally
6584safe to use arbitrary expressions as arguments. Likewise, those
6585function-like macros described in the following sections may be
6586invoked in an expression anywhere a function with a compatible return
6587type could be called./87/
6588
6589 Provided that a library function can be declared without reference
6590to any type defined in a header, it is also permissible to declare the
6591function, either explicitly or implicitly, and use it without
6592including its associated header. If a function that accepts a
6593variable number of arguments is not declared (explicitly or by
6594including its associated header), the behavior is undefined.
6595
6596Examples
6597
6598 The function atoi may be used in any of several ways:
6599
6600 * by use of its associated header (possibly generating a macro expansion)
6601
6602 #include <stdlib.h>
6603 const char *str;
6604 /*...*/
6605 i = atoi(str);
6606
6607
6608
6609 * by use of its associated header (assuredly generating a true
6610function reference)
6611
6612 #include <stdlib.h>
6613 #undef atoi
6614 const char *str;
6615 /*...*/
6616 i = atoi(str);
6617
6618or
6619
6620 #include <stdlib.h>
6621 const char *str;
6622 /*...*/
6623 i = (atoi)(str);
6624
6625 * by explicit declaration
6626
6627 extern int atoi(const char *);
6628 const char *str;
6629 /*...*/
6630 i = atoi(str);
6631
6632 * by implicit declaration
6633
6634 const char *str;
6635 /*...*/
6636 i = atoi(str);
6637
6638
66394.2 DIAGNOSTICS <assert.h>
6640
6641 The header <assert.h> defines the assert macro and refers to
6642another macro,
6643
6644 NDEBUG
6645
6646which is not defined by <assert.h> . If NDEBUG is defined as a macro
6647name at the point in the source file where <assert.h> is included, the
6648assert macro is defined simply as
6649
6650 #define assert(ignore) ((void)0)
6651
6652 The assert macro shall be implemented as a macro, not as an actual
6653function. If the macro definition is suppressed in order to access an
6654actual function, the behavior is undefined.
6655
6656
66574.2.1 Program diagnostics
6658
66594.2.1.1 The assert macro
6660
6661Synopsis
6662
6663 #include <assert.h>
6664 void assert(int expression);
6665
6666Description
6667
6668 The assert macro puts diagnostics into programs. When it is
6669executed, if expression is false (that is, compares equal to 0), the
6670assert macro writes information about the particular call that failed
6671(including the text of the argument, the name of the source file, and
6672the source line number EM the latter are respectively the values of
6673the preprocessing macros __FILE__ and __LINE__ ) on the standard error
6674file in an implementation-defined format./88/
6675 expression , xyz , nnn It then calls the abort function.
6676
6677Returns
6678
6679 The assert macro returns no value.
6680
6681Forward references: the abort function ($4.10.4.1).
6682
6683
66844.3 CHARACTER HANDLING <ctype.h>
6685
6686 The header <ctype.h> declares several functions useful for testing
6687and mapping characters./89/ In all cases the argument is an int , the
6688value of which shall be representable as an unsigned char or shall
6689equal the value of the macro EOF . If the argument has any other
6690value, the behavior is undefined.
6691
6692 The behavior of these functions is affected by the current locale.
6693Those functions that have no implementation-defined aspects in the C
6694locale are noted below.
6695
6696 The term printing character refers to a member of an
6697implementation-defined set of characters, each of which occupies one
6698printing position on a display device; the term control character
6699refers to a member of an implementation-defined set of characters that
6700are not printing characters./90/
6701
6702Forward references: EOF ($4.9.1), localization ($4.4).
6703
6704
67054.3.1 Character testing functions
6706
6707 The functions in this section return nonzero (true) if and only if
6708the value of the argument c conforms to that in the description of the
6709function.
6710
6711
67124.3.1.1 The isalnum function
6713
6714Synopsis
6715
6716 #include <ctype.h>
6717 int isalnum(int c);
6718
6719Description
6720
6721 The isalnum function tests for any character for which isalpha or
6722isdigit is true.
6723
6724
67254.3.1.2 The isalpha function
6726
6727Synopsis
6728
6729 #include <ctype.h>
6730 int isalpha(int c);
6731
6732Description
6733
6734 The isalpha function tests for any character for which isupper or
6735islower is true, or any of an implementation-defined set of characters
6736for which none of iscntrl , isdigit , ispunct , or isspace is true.
6737In the C locale, isalpha returns true only for the characters for
6738which isupper or islower is true.
6739
6740
67414.3.1.3 The iscntrl function
6742
6743Synopsis
6744
6745 #include <ctype.h>
6746 int iscntrl(int c);
6747
6748Description
6749
6750 The iscntrl function tests for any control character.
6751
6752
67534.3.1.4 The isdigit function
6754
6755Synopsis
6756
6757 #include <ctype.h>
6758 int isdigit(int c);
6759
6760Description
6761
6762 The isdigit function tests for any decimal-digit character (as
6763defined in $2.2.1).
6764
6765
67664.3.1.5 The isgraph function
6767
6768Synopsis
6769
6770 #include <ctype.h>
6771 int isgraph(int c);
6772
6773Description
6774
6775 The isgraph function tests for any printing character except space (' ').
6776
6777
67784.3.1.6 The islower function
6779
6780Synopsis
6781
6782 #include <ctype.h>
6783 int islower(int c);
6784
6785Description
6786
6787 The islower function tests for any lower-case letter or any of an
6788implementation-defined set of characters for which none of iscntrl ,
6789isdigit , ispunct , or isspace is true. In the C locale, islower
6790returns true only for the characters defined as lower-case letters (as
6791defined in $2.2.1).
6792
6793
67944.3.1.7 The isprint function
6795
6796Synopsis
6797
6798 #include <ctype.h>
6799 int isprint(int c);
6800
6801Description
6802
6803 The isprint function tests for any printing character including
6804space (' ').
6805
6806
68074.3.1.8 The ispunct function
6808
6809Synopsis
6810
6811 #include <ctype.h>
6812 int ispunct(int c);
6813
6814Description
6815
6816 The ispunct function tests for any printing character except space
6817(' ') or a character for which isalnum is true.
6818
6819
68204.3.1.9 The isspace function
6821
6822Synopsis
6823
6824 #include <ctype.h>
6825 int isspace(int c);
6826
6827Description
6828
6829 The isspace function tests for the standard white-space characters
6830or for any of an implementation-defined set of characters for which
6831isalnum is false. The standard white-space characters are the
6832following: space (' '), form feed ('\f'), new-line ('\n'), carriage
6833return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). In the
6834C locale, isspace returns true only for the standard white-space
6835characters.
6836
6837
68384.3.1.10 The isupper function
6839
6840Synopsis
6841
6842 #include <ctype.h>
6843 int isupper(int c);
6844
6845Description
6846
6847 The isupper function tests for any upper-case letter or any of an
6848implementation-defined set of characters for which none of iscntrl ,
6849isdigit , ispunct , or isspace is true. In the C locale, isupper
6850returns true only for the characters defined as upper-case letters (as
6851defined in $2.2.1).
6852
68534.3.1.11 The isxdigit function
6854
6855Synopsis
6856
6857 #include <ctype.h>
6858 int isxdigit(int c);
6859
6860Description
6861
6862 The isxdigit function tests for any hexadecimal-digit character (as
6863defined in $3.1.3.2).
6864
6865
68664.3.2 Character case mapping functions
6867
68684.3.2.1 The tolower function
6869
6870Synopsis
6871
6872 #include <ctype.h>
6873 int tolower(int c);
6874
6875Description
6876
6877 The tolower function converts an upper-case letter to the
6878corresponding lower-case letter.
6879
6880Returns
6881
6882 If the argument is an upper-case letter, the tolower function
6883returns the corresponding lower-case letter if there is one; otherwise
6884the argument is returned unchanged. In the C locale, tolower maps
6885only the characters for which isupper is true to the corresponding
6886characters for which islower is true.
6887
6888
68894.3.2.2 The toupper function
6890
6891Synopsis
6892
6893 #include <ctype.h>
6894 int toupper(int c);
6895
6896Description
6897
6898 The toupper function converts a lower-case letter to the corresponding upper-case letter.
6899
6900Returns
6901
6902 If the argument is a lower-case letter, the toupper function
6903returns the corresponding upper-case letter if there is one; otherwise
6904the argument is returned unchanged. In the C locale, toupper maps
6905only the characters for which islower is true to the corresponding
6906characters for which isupper is true.
6907
6908
69094.4 LOCALIZATION <locale.h>
6910
6911 The header <locale.h> declares two functions, one type, and defines
6912several macros.
6913
6914 The type is
6915
6916 struct lconv
6917
6918which contains members related to the formatting of numeric values.
6919The structure shall contain at least the following members, in any
6920order. The semantics of the members and their normal ranges is
6921explained in $4.4.2.1. In the C locale, the members shall have the
6922values specified in the comments.
6923
6924 char *decimal_point; /* "." */
6925 char *thousands_sep; /* "" */
6926 char *grouping; /* "" */
6927 char *int_curr_symbol; /* "" */
6928 char *currency_symbol; /* "" */
6929 char *mon_decimal_point; /* "" */
6930 char *mon_thousands_sep; /* "" */
6931 char *mon_grouping; /* "" */
6932 char *positive_sign; /* "" */
6933 char *negative_sign; /* "" */
6934 char int_frac_digits; /* CHAR_MAX */
6935 char frac_digits; /* CHAR_MAX */
6936 char p_cs_precedes; /* CHAR_MAX */
6937 char p_sep_by_space; /* CHAR_MAX */
6938 char n_cs_precedes; /* CHAR_MAX */
6939 char n_sep_by_space; /* CHAR_MAX */
6940 char p_sign_posn; /* CHAR_MAX */
6941 char n_sign_posn; /* CHAR_MAX */
6942
6943 The macros defined are NULL (described in $4.1.5); and
6944
6945 LC_ALL
6946 LC_COLLATE
6947 LC_CTYPE
6948 LC_MONETARY
6949 LC_NUMERIC
6950 LC_TIME
6951
6952which expand to distinct integral constant expressions, suitable for
6953use as the first argument to the setlocale function. Additional macro
6954definitions, beginning with the characters LC_ and an upper-case
6955letter,/91/ may also be specified by the implementation.
6956
6957
69584.4.1 Locale control
6959
69604.4.1.1 The setlocale function
6961
6962Synopsis
6963
6964 #include <locale.h>
6965 char *setlocale(int category, const char *locale);
6966
6967Description
6968
6969 The setlocale function selects the appropriate portion of the
6970program's locale as specified by the category and locale arguments.
6971The setlocale function may be used to change or query the program's
6972entire current locale or portions thereof. The value LC_ALL for
6973category names the program's entire locale; the other values for
6974category name only a portion of the program's locale. LC_COLLATE
6975affects the behavior of the strcoll and strxfrm functions. LC_CTYPE
6976affects the behavior of the character handling functions/92/ and the
6977multibyte functions. LC_MONETARY affects the monetary formatting
6978information returned by the localeconv function. LC_NUMERIC affects
6979the decimal-point character for the formatted input/output functions
6980and the string conversion functions, as well as the non-monetary
6981formatting information returned by the localeconv function. LC_TIME
6982affects the behavior of the strftime function.
6983
6984 A value of "C" for locale specifies the minimal environment for C
6985translation; a value of "" for locale specifies the implementation-defined
6986native environment. Other implementation-defined strings may be passed
6987as the second argument to setlocale .
6988
6989 At program startup, the equivalent of
6990
6991 setlocale(LC_ALL, "C");
6992
6993is executed.
6994
6995 The implementation shall behave as if no library function calls the
6996setlocale function.
6997
6998Returns
6999
7000 If a pointer to a string is given for locale and the selection can
7001be honored, the setlocale function returns the string associated with
7002the specified category for the new locale. If the selection cannot be
7003honored, the setlocale function returns a null pointer and the
7004program's locale is not changed.
7005
7006 A null pointer for locale causes the setlocale function to return
7007the string associated with the category for the program's current
7008locale; the program's locale is not changed.
7009
7010 The string returned by the setlocale function is such that a
7011subsequent call with that string and its associated category will
7012restore that part of the program's locale. The string returned shall
7013not be modified by the program, but may be overwritten by a subsequent
7014call to the setlocale function.
7015
7016Forward references: formatted input/output functions ($4.9.6), the
7017multibyte character functions ($4.10.7), the multibyte string
7018functions ($4.10.8), string conversion functions ($4.10.1), the
7019strcoll function ($4.11.4.3), the strftime function ($4.12.3.5), the
7020strxfrm function ($4.11.4.5).
7021
7022
70234.4.2 Numeric formatting convention inquiry
7024
70254.4.2.1 The localeconv function
7026
7027Synopsis
7028
7029 #include <locale.h>
7030 struct lconv *localeconv(void);
7031
7032Description
7033
7034 The localeconv function sets the components of an object with type
7035struct lconv with values appropriate for the formatting of numeric
7036quantities (monetary and otherwise) according to the rules of the
7037current locale.
7038
7039 The members of the structure with type char * are strings, any of
7040which (except decimal_point ) can point to , to indicate that the
7041value is not available in the current locale or is of zero length.
7042The members with type char are nonnegative numbers, any of which can
7043be CHAR_MAX to indicate that the value is not available in the current
7044locale. The members include the following: The decimal-point
7045character used to format non-monetary quantities. The character used
7046to separate groups of digits to the left of the decimal-point
7047character in formatted non-monetary quantities. A string whose
7048elements indicate the size of each group of digits in formatted
7049non-monetary quantities. The international currency symbol applicable
7050to the current locale. The first three characters contain the
7051alphabetic international currency symbol in accordance with those
7052specified in ISO 4217 Codes for the Representation of Currency and
7053Funds .The fourth character (immediately preceding the null character)
7054is the character used to separate the international currency symbol
7055from the monetary quantity. The local currency symbol applicable to
7056the current locale. The decimal-point used to format monetary
7057quantities. The separator for groups of digits to the left of the
7058decimal-point in formatted monetary quantities. A string whose
7059elements indicate the size of each group of digits in formatted
7060monetary quantities. The string used to indicate a nonnegative-valued
7061formatted monetary quantity. The string used to indicate a
7062negative-valued formatted monetary quantity. The number of fractional
7063digits (those to the right of the decimal-point) to be displayed in a
7064internationally formatted monetary quantity. The number of fractional
7065digits (those to the right of the decimal-point) to be displayed in a
7066formatted monetary quantity. Set to 1 or 0 if the currency_symbol
7067respectively precedes or succeeds the value for a nonnegative
7068formatted monetary quantity. Set to 1 or 0 if the currency_symbol
7069respectively is or is not separated by a space from the value for a
7070nonnegative formatted monetary quantity. Set to 1 or 0 if the
7071currency_symbol respectively precedes or succeeds the value for a
7072negative formatted monetary quantity. Set to 1 or 0 if the
7073currency_symbol respectively is or is not separated by a space from
7074the value for a negative formatted monetary quantity. Set to a value
7075indicating the positioning of the positive_sign for a nonnegative
7076formatted monetary quantity. Set to a value indicating the
7077positioning of the negative_sign for a negative formatted monetary
7078quantity.
7079
7080 The elements of grouping and mon_grouping are interpreted according
7081to the following: No further grouping is to be performed. The
7082previous element is to be repeatedly used for the remainder of the
7083digits. The value is the number of digits that comprise the current
7084group. The next element is examined to determine the size of the next
7085group of digits to the left of the current group.
7086
7087 The value of p_sign_posn and n_sign_posn is interpreted according
7088to the following: Parentheses surround the quantity and
7089currency_symbol. The sign string precedes the quantity and
7090currency_symbol. The sign string succeeds the quantity and
7091currency_symbol. The sign string immediately precedes the
7092currency_symbol. The sign string immediately succeeds the
7093currency_symbol.
7094
7095 The implementation shall behave as if no library function calls the
7096localeconv function.
7097
7098Returns
7099
7100 The localeconv function returns a pointer to the filled-in object.
7101The structure pointed to by the return value shall not be modified by
7102the program, but may be overwritten by a subsequent call to the
7103localeconv function. In addition, calls to the setlocale function
7104with categories LC_ALL , LC_MONETARY , or LC_NUMERIC may overwrite the
7105contents of the structure.
7106
7107Examples
7108
7109 The following table illustrates the rules used by four countries to
7110format monetary quantities.
7111
7112 Country Positive format Negative format International format
7113
7114 Italy L.1.234 -L.1.234 ITL.1.234
7115 Netherlands F 1.234,56 F -1.234,56 NLG 1.234,56
7116 Norway kr1.234,56 kr1.234,56- NOK 1.234,56
7117 Switzerland SFrs.1,234.56 SFrs.1,234.56C CHF 1,234.56
7118
7119
7120 For these four countries, the respective values for the monetary
7121members of the structure returned by localeconv are:
7122
7123 Italy Netherlands Norway Switzerland
7124
7125 int_curr_symbol "ITL." "NLG " "NOK " "CHF "
7126 currency_symbol "L." "F" "kr" "SFrs."
7127 mon_decimal_point "" "," "," "."
7128 mon_thousands_sep "." "." "." ","
7129 mon_grouping "\3" "\3" "\3" "\3"
7130 positive_sign "" "" "" ""
7131 negative_sign "-" "-" "-" "C"
7132 int_frac_digits 0 2 2 2
7133 frac_digits 0 2 2 2
7134 p_cs_precedes 1 1 1 1
7135 p_sep_by_space 0 1 0 0
7136 n_cs_precedes 1 1 1 1
7137 n_sep_by_space 0 1 0 0
7138 p_sign_posn 1 1 1 1
7139 n_sign_posn 1 4 2 2
7140
7141
7142
71434.5 MATHEMATICS <math.h>
7144
7145 The header <math.h> declares several mathematical functions and
7146defines one macro. The functions take double-precision arguments and
7147return double-precision values./93/ Integer arithmetic functions and
7148conversion functions are discussed later.
7149
7150 The macro defined is
7151
7152 HUGE_VAL
7153
7154which expands to a positive double expression, not necessarily
7155representable as a float .
7156
7157Forward references: integer arithmetic functions ($4.10.6), the atof
7158function ($4.10.1.1), the strtod function ($4.10.1.4).
7159
7160
71614.5.1 Treatment of error conditions
7162
7163 The behavior of each of these functions is defined for all
7164representable values of its input arguments. Each function shall
7165execute as if it were a single operation, without generating any
7166externally visible exceptions.
7167
7168 For all functions, a domain error occurs if an input argument is
7169outside the domain over which the mathematical function is defined.
7170The description of each function lists any required domain errors; an
7171implementation may define additional domain errors, provided that such
7172errors are consistent with the mathematical definition of the
7173function./94/ On a domain error, the function returns an
7174implementation-defined value; the value of the macro EDOM is stored in
7175errno .
7176
7177 Similarly, a range error occurs if the result of the function
7178cannot be represented as a double value. If the result overflows (the
7179magnitude of the result is so large that it cannot be represented in
7180an object of the specified type), the function returns the value of
7181the macro HUGE_VAL , with the same sign as the correct value of the
7182function; the value of the macro ERANGE is stored in errno . If the
7183result underflows (the magnitude of the result is so small that it
7184cannot be represented in an object of the specified type), the
7185function returns zero; whether the integer expression errno acquires
7186the value of the macro ERANGE is implementation-defined.
7187
7188
71894.5.2 Trigonometric functions
7190
71914.5.2.1 The acos function
7192
7193Synopsis
7194
7195 #include <math.h>
7196 double acos(double x);
7197
7198Description
7199
7200 The acos function computes the principal value of the arc cosine of x.
7201A domain error occurs for arguments not in the range [-1, +1].
7202
7203Returns
7204
7205 The acos function returns the arc cosine in the range [0, PI] radians.
7206
7207
72084.5.2.2 The asin function
7209
7210Synopsis
7211
7212 #include <math.h>
7213 double asin(double x);
7214
7215Description
7216
7217 The asin function computes the principal value of the arc sine of x.
7218A domain error occurs for arguments not in the range [-1, +1].
7219
7220Returns
7221
7222 The asin function returns the arc sine in the range [-PI/2, +PI/2]
7223radians.
7224
7225
72264.5.2.3 The atan function
7227
7228Synopsis
7229
7230 #include <math.h>
7231 double atan(double x);
7232
7233Description
7234
7235 The atan function computes the principal value of the arc tangent of x.
7236
7237Returns
7238
7239 The atan function returns the arc tangent in the range [-PI/2, +PI/2]
7240radians.
7241
7242
72434.5.2.4 The atan2 function
7244
7245Synopsis
7246
7247 #include <math.h>
7248 double atan2(double y, double x);
7249
7250Description
7251
7252 The atan2 function computes the principal value of the arc tangent
7253of y/x , using the signs of both arguments to determine the quadrant
7254of the return value. A domain error may occur if both arguments are
7255zero.
7256
7257Returns
7258
7259 The atan2 function returns the arc tangent of y/x , in the range
7260[-PI, +PI] radians.
7261
7262
72634.5.2.5 The cos function
7264
7265Synopsis
7266
7267 #include <math.h>
7268 double cos(double x);
7269
7270Description
7271
7272 The cos function computes the cosine of x (measured in radians). A
7273large magnitude argument may yield a result with little or no
7274significance.
7275
7276Returns
7277
7278 The cos function returns the cosine value.
7279
7280
72814.5.2.6 The sin function
7282
7283Synopsis
7284
7285 #include <math.h>
7286 double sin(double x);
7287
7288Description
7289
7290 The sin function computes the sine of x (measured in radians). A
7291large magnitude argument may yield a result with little or no
7292significance.
7293
7294Returns
7295
7296 The sin function returns the sine value.
7297
7298
72994.5.2.7 The tan function
7300
7301Synopsis
7302
7303 #include <math.h>
7304 double tan(double x);
7305
7306Description
7307
7308 The tan function returns the tangent of x (measured in radians). A large magnitude argument may yield a result with little or no significance.
7309
7310Returns
7311
7312 The tan function returns the tangent value.
7313
7314
73154.5.3 Hyperbolic functions
7316
73174.5.3.1 The cosh function
7318
7319Synopsis
7320
7321 #include <math.h>
7322 double cosh(double x);
7323
7324Description
7325
7326 The cosh function computes the hyperbolic cosine of x. A range
7327error occurs if the magnitude of x is too large.
7328
7329Returns
7330
7331 The cosh function returns the hyperbolic cosine value.
7332
7333
73344.5.3.2 The sinh function
7335
7336Synopsis
7337
7338 #include <math.h>
7339 double sinh(double x);
7340
7341Description
7342
7343 The sinh function computes the hyperbolic sine of x . A range error occurs if the magnitude of x is too large.
7344
7345Returns
7346
7347 The sinh function returns the hyperbolic sine value.
7348
7349
73504.5.3.3 The tanh function
7351
7352Synopsis
7353
7354 #include <math.h>
7355 double tanh(double x);
7356
7357Description
7358
7359 The tanh function computes the hyperbolic tangent of x .
7360
7361Returns
7362
7363 The tanh function returns the hyperbolic tangent value.
7364
7365
73664.5.4 Exponential and logarithmic functions
7367
73684.5.4.1 The exp function
7369
7370Synopsis
7371
7372 #include <math.h>
7373 double exp(double x);
7374
7375Description
7376
7377 The exp function computes the exponential function of x . A range
7378error occurs if the magnitude of x is too large.
7379
7380Returns
7381
7382 The exp function returns the exponential value.
7383
7384
73854.5.4.2 The frexp function
7386
7387Synopsis
7388
7389 #include <math.h>
7390 double frexp(double value, int *exp);
7391
7392Description
7393
7394 The frexp function breaks a floating-point number into a normalized
7395fraction and an integral power of 2. It stores the integer in the int
7396object pointed to by exp .
7397
7398Returns
7399
7400 The frexp function returns the value x , such that x is a double
7401with magnitude in the interval [1/2, 1) or zero, and value equals x
7402times 2 raised to the power *exp . If value is zero, both parts of
7403the result are zero.
7404
7405
74064.5.4.3 The ldexp function
7407
7408Synopsis
7409
7410 #include <math.h>
7411 double ldexp(double x, int exp);
7412
7413Description
7414
7415 The ldexp function multiplies a floating-point number by an
7416integral power of 2. A range error may occur.
7417
7418Returns
7419
7420 The ldexp function returns the value of x times 2 raised to the
7421power exp .
7422
7423
74244.5.4.4 The log function
7425
7426Synopsis
7427
7428 #include <math.h>
7429 double log(double x);
7430
7431Description
7432
7433 The log function computes the natural logarithm of x. A domain
7434error occurs if the argument is negative. A range error occurs if the
7435argument is zero and the logarithm of zero cannot be represented.
7436
7437Returns
7438
7439 The log function returns the natural logarithm.
7440
7441
74424.5.4.5 The log10 function
7443
7444Synopsis
7445
7446 #include <math.h>
7447 double log10(double x);
7448
7449Description
7450
7451 The log10 function computes the base-ten logarithm of x . A domain
7452error occurs if the argument is negative. A range error occurs if the
7453argument is zero and the logarithm of zero cannot be represented.
7454
7455Returns
7456
7457 The log10 function returns the base-ten logarithm.
7458
7459
74604.5.4.6 The modf function
7461
7462Synopsis
7463
7464 #include <math.h>
7465 double modf(double value, double *iptr);
7466
7467Description
7468
7469 The modf function breaks the argument value into integral and
7470fractional parts, each of which has the same sign as the argument. It
7471stores the integral part as a double in the object pointed to by iptr.
7472
7473Returns
7474
7475 The modf function returns the signed fractional part of value .
7476
7477
74784.5.5 Power functions
7479
74804.5.5.1 The pow function
7481
7482Synopsis
7483
7484 #include <math.h>
7485 double pow(double x, double y);
7486
7487Description
7488
7489 The pow function computes x raised to the power y . A domain error
7490occurs if x is negative and y is not an integer. A domain error
7491occurs if the result cannot be represented when x is zero and y is
7492less than or equal to zero. A range error may occur.
7493
7494Returns
7495
7496 The pow function returns the value of x raised to the power y .
7497
7498
74994.5.5.2 The sqrt function
7500
7501Synopsis
7502
7503 #include <math.h>
7504 double sqrt(double x);
7505
7506Description
7507
7508 The sqrt function computes the nonnegative square root of x . A
7509domain error occurs if the argument is negative.
7510
7511Returns
7512
7513 The sqrt function returns the value of the square root.
7514
7515
75164.5.6 Nearest integer, absolute value, and remainder functions
7517
75184.5.6.1 The ceil function
7519
7520Synopsis
7521
7522 #include <math.h>
7523 double ceil(double x);
7524
7525Description
7526
7527 The ceil function computes the smallest integral value not less than x .
7528
7529Returns
7530
7531 The ceil function returns the smallest integral value not less than
7532x , expressed as a double.
7533
7534
75354.5.6.2 The fabs function
7536
7537Synopsis
7538
7539 #include <math.h>
7540 double fabs(double x);
7541
7542Description
7543
7544 The fabs function computes the absolute value of a floating-point
7545number x .
7546
7547Returns
7548
7549 The fabs function returns the absolute value of x.
7550
7551
75524.5.6.3 The floor function
7553
7554Synopsis
7555
7556 #include <math.h>
7557 double floor(double x);
7558
7559Description
7560
7561 The floor function computes the largest integral value not greater
7562than x .
7563
7564Returns
7565
7566 The floor function returns the largest integral value not greater
7567than x , expressed as a double.
7568
7569
75704.5.6.4 The fmod function
7571
7572Synopsis
7573
7574 #include <math.h>
7575 double fmod(double x, double y);
7576
7577Description
7578
7579 The fmod function computes the floating-point remainder of x/y .
7580
7581Returns
7582
7583 The fmod function returns the value x i y , for some integer i such
7584that, if y is nonzero, the result has the same sign as x and magnitude
7585less than the magnitude of y . If y is zero, whether a domain error
7586occurs or the fmod function returns zero is implementation-defined.
7587
7588
75894.6 NON-LOCAL JUMPS <setjmp.h>
7590
7591 The header <setjmp.h> defines the macro setjmp , and declares one
7592function and one type, for bypassing the normal function call and
7593return discipline./95/
7594
7595 The type declared is
7596
7597 jmp_buf
7598
7599which is an array type suitable for holding the information needed to
7600restore a calling environment.
7601
7602 It is unspecified whether setjmp is a macro or an identifier
7603declared with external linkage. If a macro definition is suppressed
7604in order to access an actual function, or a program defines an
7605external identifier with the name setjmp , the behavior is undefined.
7606
7607
76084.6.1 Save calling environment
7609
76104.6.1.1 The setjmp macro
7611
7612Synopsis
7613
7614 #include <setjmp.h>
7615 int setjmp(jmp_buf env);
7616
7617Description
7618
7619 The setjmp macro saves its calling environment in its jmp_buf
7620argument for later use by the longjmp function.
7621
7622Returns
7623
7624 If the return is from a direct invocation, the setjmp macro returns
7625the value zero. If the return is from a call to the longjmp function,
7626the setjmp macro returns a nonzero value.
7627
7628"Environmental constraint"
7629
7630 An invocation of the setjmp macro shall appear only in one of the
7631following contexts:
7632
7633 * the entire controlling expression of a selection or iteration statement;
7634
7635 * one operand of a relational or equality operator with the other
7636 operand an integral constant expression, with the resulting expression
7637 being the entire controlling expression of a selection or iteration
7638 statement;
7639
7640 * the operand of a unary ! operator with the resulting expression
7641 being the entire controlling expression of a selection or iteration
7642 statement; or
7643
7644 * the entire expression of an expression statement (possibly cast to void).
7645
7646
76474.6.2 Restore calling environment
7648
76494.6.2.1 The longjmp function
7650
7651Synopsis
7652
7653 #include <setjmp.h>
7654 void longjmp(jmp_buf env, int val);
7655
7656Description
7657
7658 The longjmp function restores the environment saved by the most
7659recent invocation of the setjmp macro in the same invocation of the
7660program, with the corresponding jmp_buf argument. If there has been
7661no such invocation, or if the function containing the invocation of
7662the setjmp macro has terminated execution/96/ in the interim, the
7663behavior is undefined.
7664
7665 All accessible objects have values as of the time longjmp was
7666called, except that the values of objects of automatic storage
7667duration that do not have volatile type and have been changed between
7668the setjmp invocation and longjmp call are indeterminate.
7669
7670 As it bypasses the usual function call and return mechanisms, the
7671longjmp function shall execute correctly in contexts of interrupts,
7672signals and any of their associated functions. However, if the
7673longjmp function is invoked from a nested signal handler (that is,
7674from a function invoked as a result of a signal raised during the
7675handling of another signal), the behavior is undefined.
7676
7677Returns
7678
7679 After longjmp is completed, program execution continues as if the
7680corresponding invocation of the setjmp macro had just returned the
7681value specified by val . The longjmp function cannot cause the setjmp
7682macro to return the value 0; if val is 0, the setjmp macro returns the
7683value 1.
7684
7685
76864.7 SIGNAL HANDLING <signal.h>
7687
7688 The header <signal.h> declares a type and two functions and defines
7689several macros, for handling various signals (conditions that may be
7690reported during program execution).
7691
7692 The type defined is
7693
7694 sig_atomic_t
7695
7696which is the integral type of an object that can be accessed as an
7697atomic entity, even in the presence of asynchronous interrupts.
7698
7699 The macros defined are
7700
7701 SIG_DFL
7702 SIG_ERR
7703 SIG_IGN
7704
7705which expand to distinct constant expressions that have type
7706compatible with the second argument to and the return value of the
7707signal function, and whose value compares unequal to the address of
7708any declarable function; and the following, each of which expands to a
7709positive integral constant expression that is the signal number
7710corresponding to the specified condition:
7711
7712SIGABRT abnormal termination, such as is initiated by the abort function
7713
7714SIGFPE an erroneous arithmetic operation, such as zero divide or an
7715 operation resulting in overflow
7716
7717SIGILL detection of an invalid function image, such as an illegal
7718 instruction
7719
7720SIGINT receipt of an interactive attention signal
7721
7722SIGSEGV an invalid access to storage
7723
7724SIGTERM a termination request sent to the program
7725
7726 An implementation need not generate any of these signals, except as
7727a result of explicit calls to the raise function. Additional signals
7728and pointers to undeclarable functions, with macro definitions
7729beginning, respectively, with the letters SIG and an upper-case letter
7730or with SIG_ and an upper-case letter,/97/ may also be specified by
7731the implementation. The complete set of signals, their semantics, and
7732their default handling is implementation-defined; all signal values
7733shall be positive.
7734
7735
77364.7.1 Specify signal handling
7737
77384.7.1.1 The signal function
7739
7740Synopsis
7741
7742 #include <signal.h>
7743 void (*signal(int sig, void (*func)(int)))(int);
7744
7745Description
7746
7747 The signal function chooses one of three ways in which receipt of
7748the signal number sig is to be subsequently handled. If the value of
7749func is SIG_DFL , default handling for that signal will occur. If the
7750value of func is SIG_IGN , the signal will be ignored. Otherwise,
7751func shall point to a function to be called when that signal occurs.
7752Such a function is called a signal handler .
7753
7754 When a signal occurs, if func points to a function, first the
7755equivalent of signal(sig, SIG_DFL); is executed or an
7756implementation-defined blocking of the signal is performed. (If the
7757value of sig is SIGILL, whether the reset to SIG_DFL occurs is
7758implementation-defined.) Next the equivalent of (*func)(sig); is
7759executed. The function func may terminate by executing a return
7760statement or by calling the abort , exit , or longjmp function. If
7761func executes a return statement and the value of sig was SIGFPE or
7762any other implementation-defined value corresponding to a
7763computational exception, the behavior is undefined. Otherwise, the
7764program will resume execution at the point it was interrupted.
7765
7766 If the signal occurs other than as the result of calling the abort
7767or raise function, the behavior is undefined if the signal handler
7768calls any function in the standard library other than the signal
7769function itself or refers to any object with static storage duration
7770other than by assigning a value to a static storage duration variable
7771of type volatile sig_atomic_t . Furthermore, if such a call to the
7772signal function results in a SIG_ERR return, the value of errno is
7773indeterminate.
7774
7775 At program startup, the equivalent of
7776
7777 signal(sig, SIG_IGN);
7778
7779may be executed for some signals selected in an implementation-defined
7780manner; the equivalent of
7781
7782 signal(sig, SIG_DFL);
7783
7784is executed for all other signals defined by the implementation.
7785
7786 The implementation shall behave as if no library function calls the
7787signal function.
7788
7789Returns
7790
7791 If the request can be honored, the signal function returns the
7792value of func for the most recent call to signal for the specified
7793signal sig . Otherwise, a value of SIG_ERR is returned and a positive
7794value is stored in errno .
7795
7796Forward references: the abort function ($4.10.4.1).
7797
7798
77994.7.2 Send signal
7800
78014.7.2.1 The raise function
7802
7803Synopsis
7804
7805 #include <signal.h>
7806 int raise(int sig);
7807
7808Description
7809
7810 The raise function sends the signal sig to the executing program.
7811
7812Returns
7813
7814 The raise function returns zero if successful, nonzero if unsuccessful.
7815
7816
78174.8 VARIABLE ARGUMENTS <stdarg.h>
7818
7819 The header <stdarg.h> declares a type and defines three macros, for
7820advancing through a list of arguments whose number and types are not
7821known to the called function when it is translated.
7822
7823 A function may be called with a variable number of arguments of
7824varying types. As described in $3.7.1, its parameter list contains
7825one or more parameters. The rightmost parameter plays a special role
7826in the access mechanism, and will be designated parmN in this
7827description.
7828
7829 The type declared is
7830
7831 va_list
7832
7833which is a type suitable for holding information needed by the macros
7834va_start , va_arg , and va_end . If access to the varying arguments
7835is desired, the called function shall declare an object (referred to
7836as ap in this section) having type va_list . The object ap may be
7837passed as an argument to another function; if that function invokes
7838the va_arg macro with parameter ap , the value of ap in the calling
7839function is indeterminate and shall be passed to the va_end macro
7840prior to any further reference to ap .
7841
7842
78434.8.1 Variable argument list access macros
7844
7845 The va_start and va_arg macros described in this section shall be
7846implemented as macros, not as actual functions. It is unspecified
7847whether va_end is a macro or an identifier declared with external
7848linkage. If a macro definition is suppressed in order to access an
7849actual function, or a program defines an external identifier with the
7850name va_end , the behavior is undefined. The va_start and va_end
7851macros shall be invoked in the function accepting a varying number of
7852arguments, if access to the varying arguments is desired.
7853
7854
78554.8.1.1 The va_start macro
7856
7857Synopsis
7858
7859 #include <stdarg.h>
7860 void va_start(va_list ap, parmN);
7861
7862Description
7863
7864 The va_start macro shall be invoked before any access to the
7865unnamed arguments.
7866
7867 The va_start macro initializes ap for subsequent use by va_arg and
7868va_end .
7869
7870 The parameter parmN is the identifier of the rightmost parameter in
7871the variable parameter list in the function definition (the one just
7872before the , ... ). If the parameter parmN is declared with the
7873register storage class, with a function or array type, or with a type
7874that is not compatible with the type that results after application of
7875the default argument promotions, the behavior is undefined.
7876
7877Returns
7878
7879 The va_start macro returns no value.
7880
7881
78824.8.1.2 The va_arg macro
7883
7884Synopsis
7885
7886 #include <stdarg.h>
7887 type va_arg(va_list ap, type);
7888
7889Description
7890
7891 The va_arg macro expands to an expression that has the type and
7892value of the next argument in the call. The parameter ap shall be the
7893same as the va_list ap initialized by va_start . Each invocation of
7894va_arg modifies ap so that the values of successive arguments are
7895returned in turn. The parameter type is a type name specified such
7896that the type of a pointer to an object that has the specified type
7897can be obtained simply by postfixing a * to type . If there is no
7898actual next argument, or if type is not compatible with the type of
7899the actual next argument (as promoted according to the default
7900argument promotions), the behavior is undefined.
7901
7902Returns
7903
7904 The first invocation of the va_arg macro after that of the va_start
7905macro returns the value of the argument after that specified by parmN.
7906Successive invocations return the values of the remaining arguments
7907in succession.
7908
7909
79104.8.1.3 The va_end macro
7911
7912Synopsis
7913
7914 #include <stdarg.h>
7915 void va_end(va_list ap);
7916
7917Description
7918
7919 The va_end macro facilitates a normal return from the function
7920whose variable argument list was referred to by the expansion of
7921va_start that initialized the va_list ap . The va_end macro may
7922modify ap so that it is no longer usable (without an intervening
7923invocation of va_start ). If there is no corresponding invocation of
7924the va_start macro, or if the va_end macro is not invoked before the
7925return, the behavior is undefined.
7926
7927Returns
7928
7929 The va_end macro returns no value.
7930
7931Example
7932
7933 The function f1 gathers into an array a list of arguments that are
7934pointers to strings (but not more than MAXARGS arguments), then passes
7935the array as a single argument to function f2 . The number of
7936pointers is specified by the first argument to f1 .
7937
7938 #include <stdarg.h>
7939 #define MAXARGS 31
7940
7941 void f1(int n_ptrs, ...)
7942 {
7943 va_list ap;
7944 char *array[MAXARGS];
7945 int ptr_no = 0;
7946
7947 if (n_ptrs > MAXARGS)
7948 n_ptrs = MAXARGS;
7949 va_start(ap, n_ptrs);
7950 while (ptr_no < n_ptrs)
7951 array[ptr_no++] = va_arg(ap, char *);
7952 va_end(ap);
7953 f2(n_ptrs, array);
7954 }
7955
7956Each call to f1 shall have visible the definition of the function or a
7957declaration such as
7958
7959 void f1(int, ...);
7960
7961
79624.9 INPUT/OUTPUT <stdio.h>
7963
79644.9.1 Introduction
7965
7966 The header <stdio.h> declares three types, several macros, and many
7967functions for performing input and output.
7968
7969 The types declared are size_t (described in $4.1.5);
7970
7971 FILE
7972
7973which is an object type capable of recording all the information
7974needed to control a stream, including its file position indicator, a
7975pointer to its associated buffer, an error indicator that records
7976whether a read/write error has occurred, and an end-of-file indicator
7977that records whether the end of the file has been reached; and
7978
7979 fpos_t
7980
7981which is an object type capable of recording all the information
7982needed to specify uniquely every position within a file.
7983
7984 The macros are NULL (described in $4.1.5);
7985
7986 _IOFBF
7987 _IOLBF
7988 _IONBF
7989
7990which expand to distinct integral constant expressions, suitable for
7991use as the third argument to the setvbuf function;
7992
7993 BUFSIZ
7994
7995which expands to an integral constant expression, which is the size of
7996the buffer used by the setbuf function;
7997
7998 EOF
7999
8000which expands to a negative integral constant expression that is
8001returned by several functions to indicate end-of-file ,that is, no
8002more input from a stream;
8003
8004 FOPEN_MAX
8005
8006which expands to an integral constant expression that is the minimum
8007number of files that the implementation guarantees can be open
8008simultaneously;
8009
8010 FILENAME_MAX
8011
8012which expands to an integral constant expression that is the maximum
8013length for a file name string that the implementation guarantees can
8014be opened;/98/
8015
8016 L_tmpnam
8017
8018which expands to an integral constant expression that is the size of
8019an array of char large enough to hold a temporary file name string
8020generated by the tmpnam function;
8021
8022 SEEK_CUR
8023 SEEK_END
8024 SEEK_SET
8025
8026which expand to distinct integral constant expressions, suitable for
8027use as the third argument to the fseek function;
8028
8029 TMP_MAX
8030
8031which expands to an integral constant expression that is the minimum
8032number of unique file names that shall be generated by the tmpnam
8033function;
8034
8035 stderr
8036 stdin
8037 stdout
8038
8039which are expressions of type ``pointer to FILE '' that point to the
8040FILE objects associated, respectively, with the standard error, input,
8041and output streams.
8042
8043Forward references: files ($4.9.3), the fseek function ($4.9.9.2),
8044streams ($4.9.2), the tmpnam function ($4.9.4.4).
8045
8046
80474.9.2 Streams
8048
8049 Input and output, whether to or from physical devices such as
8050terminals and tape drives, or whether to or from files supported on
8051structured storage devices, are mapped into logical data streams
8052,whose properties are more uniform than their various inputs and
8053outputs. Two forms of mapping are supported, for text streams and for
8054binary streams ./99/
8055
8056 A text stream is an ordered sequence of characters composed into
8057lines , each line consisting of zero or more characters plus a
8058terminating new-line character. Whether the last line requires a
8059terminating new-line character is implementation-defined. Characters
8060may have to be added, altered, or deleted on input and output to
8061conform to differing conventions for representing text in the host
8062environment. Thus, there need not be a one-to-one correspondence
8063between the characters in a stream and those in the external
8064representation. Data read in from a text stream will necessarily
8065compare equal to the data that were earlier written out to that stream
8066only if: the data consist only of printable characters and the control
8067characters horizontal tab and new-line; no new-line character is
8068immediately preceded by space characters; and the last character is a
8069new-line character. Whether space characters that are written out
8070immediately before a new-line character appear when read in is
8071implementation-defined.
8072
8073 A binary stream is an ordered sequence of characters that can
8074transparently record internal data. Data read in from a binary stream
8075shall compare equal to the data that were earlier written out to that
8076stream, under the same implementation. Such a stream may, however,
8077have an implementation-defined number of null characters appended.
8078
8079"Environmental limits"
8080
8081 An implementation shall support text files with lines containing at
8082least 254 characters, including the terminating new-line character.
8083The value of the macro BUFSIZ shall be at least 256.
8084
8085
80864.9.3 Files
8087
8088 A stream is associated with an external file (which may be a
8089physical device) by opening a file, which may involve creating a new
8090file. Creating an existing file causes its former contents to be
8091discarded, if necessary, so that it appears as if newly created. If a
8092file can support positioning requests (such as a disk file, as opposed
8093to a terminal), then a file position indicator /100/ associated with
8094the stream is positioned at the start (character number zero) of the
8095file, unless the file is opened with append mode in which case it is
8096implementation-defined whether the file position indicator is
8097positioned at the beginning or the end of the file. The file position
8098indicator is maintained by subsequent reads, writes, and positioning
8099requests, to facilitate an orderly progression through the file. All
8100input takes place as if characters were read by successive calls to the
8101fgetc function; all output takes place as if characters were written by
8102successive calls to the fputc function.
8103
8104 Binary files are not truncated, except as defined in $4.9.5.3.
8105Whether a write on a text stream causes the associated file to be
8106truncated beyond that point is implementation-defined.
8107
8108 When a stream is unbuffered, characters are intended to appear
8109from the source or at the destination as soon as possible. Otherwise
8110characters may be accumulated and transmitted to or from the host
8111environment as a block. When a stream is fully buffered, characters
8112are intended to be transmitted to or from the host environment as a
8113block when a buffer is filled. When a stream is line buffered,
8114characters are intended to be transmitted to or from the host
8115environment as a block when a new-line character is encountered.
8116Furthermore, characters are intended to be transmitted as a block to
8117the host environment when a buffer is filled, when input is requested
8118on an unbuffered stream, or when input is requested on a line buffered
8119stream that requires the transmission of characters from the host
8120environment. Support for these characteristics is
8121implementation-defined, and may be affected via the setbuf and setvbuf
8122functions.
8123
8124 A file may be disassociated from its controlling stream by closing
8125the file. Output streams are flushed (any unwritten buffer contents
8126are transmitted to the host environment) before the stream is
8127disassociated from the file. The value of a pointer to a FILE object
8128is indeterminate after the associated file is closed (including the
8129standard text streams). Whether a file of zero length (on which no
8130characters have been written by an output stream) actually exists is
8131implementation-defined.
8132
8133 The file may be subsequently reopened, by the same or another
8134program execution, and its contents reclaimed or modified (if it can
8135be repositioned at its start). If the main function returns to its
8136original caller, or if the exit function is called, all open files are
8137closed (hence all output streams are flushed) before program
8138termination. Other paths to program termination, such as calling the
8139abort function, need not close all files properly.
8140
8141 The address of the FILE object used to control a stream may be
8142significant; a copy of a FILE object may not necessarily serve in
8143place of the original.
8144
8145 At program startup, three text streams are predefined and need not
8146be opened explicitly --- standard input (for reading conventional
8147input), standard output (for writing conventional output), and
8148standard error (for writing diagnostic output). When opened, the
8149standard error stream is not fully buffered; the standard input and
8150standard output streams are fully buffered if and only if the stream
8151can be determined not to refer to an interactive device.
8152
8153 Functions that open additional (nontemporary) files require a file
8154name, which is a string. The rules for composing valid file names are
8155implementation-defined. Whether the same file can be simultaneously
8156open multiple times is also implementation-defined.
8157
8158"Environmental limits"
8159
8160 The value of the macro FOPEN_MAX shall be at least eight, including
8161the three standard text streams.
8162
8163Forward references: the exit function ($4.10.4.3), the fgetc function
8164($4.9.7.1), the fopen function ($4.9.5.3), the fputc function
8165($4.9.7.3), the setbuf function ($4.9.5.5), the setvbuf function
8166($4.9.5.6).
8167
8168
81694.9.4 Operations on files
8170
81714.9.4.1 The remove function
8172
8173Synopsis
8174
8175 #include <stdio.h>
8176 int remove(const char *filename);
8177
8178Description
8179
8180 The remove function causes the file whose name is the string
8181pointed to by filename to be no longer accessible by that name. A
8182subsequent attempt to open that file using that name will fail, unless
8183it is created anew. If the file is open, the behavior of the remove
8184function is implementation-defined.
8185
8186Returns
8187
8188 The remove function returns zero if the operation succeeds, nonzero
8189if it fails.
8190
8191
81924.9.4.2 The rename function
8193
8194Synopsis
8195
8196 #include <stdio.h>
8197 int rename(const char *old, const char *new);
8198
8199Description
8200
8201 The rename function causes the file whose name is the string
8202pointed to by old to be henceforth known by the name given by the
8203string pointed to by new . The file named old is effectively removed.
8204If a file named by the string pointed to by new exists prior to the
8205call to the rename function, the behavior is implementation-defined.
8206
8207Returns
8208
8209 The rename function returns zero if the operation succeeds, nonzero
8210if it fails,/101/ in which case if the file existed previously it is
8211still known by its original name.
8212
8213
82144.9.4.3 The tmpfile function
8215
8216Synopsis
8217
8218 #include <stdio.h>
8219 FILE *tmpfile(void);
8220
8221Description
8222
8223 The tmpfile function creates a temporary binary file that will
8224automatically be removed when it is closed or at program termination.
8225If the program terminates abnormally, whether an open temporary file
8226is removed is implementation-defined. The file is opened for update
8227with wb+ mode.
8228
8229Returns
8230
8231 The tmpfile function returns a pointer to the stream of the file
8232that it created. If the file cannot be created, the tmpfile function
8233returns a null pointer.
8234
8235Forward references: the fopen function ($4.9.5.3).
8236
8237
82384.9.4.4 The tmpnam function
8239
8240Synopsis
8241
8242 #include <stdio.h>
8243 char *tmpnam(char *s);
8244
8245Description
8246
8247 The tmpnam function generates a string that is a valid file name
8248and that is not the same as the name of an existing file./102/
8249
8250 The tmpnam function generates a different string each time it is
8251called, up to TMP_MAX times. If it is called more than TMP_MAX times,
8252the behavior is implementation-defined.
8253
8254 The implementation shall behave as if no library function calls the
8255tmpnam function.
8256
8257Returns
8258
8259 If the argument is a null pointer, the tmpnam function leaves its
8260result in an internal static object and returns a pointer to that
8261object. Subsequent calls to the tmpnam function may modify the same
8262object. If the argument is not a null pointer, it is assumed to point
8263to an array of at least L_tmpnam char s; the tmpnam function writes
8264its result in that array and returns the argument as its value.
8265
8266"Environmental limits"
8267
8268 The value of the macro TMP_MAX shall be at least 25.
8269
8270
82714.9.5 File access functions
8272
82734.9.5.1 The fclose function
8274
8275Synopsis
8276
8277 #include <stdio.h>
8278 int fclose(FILE *stream);
8279
8280Description
8281
8282 The fclose function causes the stream pointed to by stream to be
8283flushed and the associated file to be closed. Any unwritten buffered
8284data for the stream are delivered to the host environment to be
8285written to the file; any unread buffered data are discarded. The
8286stream is disassociated from the file. If the associated buffer was
8287automatically allocated, it is deallocated.
8288
8289Returns
8290
8291 The fclose function returns zero if the stream was successfully
8292closed, or EOF if any errors were detected.
8293
8294
82954.9.5.2 The fflush function
8296
8297Synopsis
8298
8299 #include <stdio.h>
8300 int fflush(FILE *stream);
8301
8302Description
8303
8304 If stream points to an output stream or an update stream in which
8305the most recent operation was output, the fflush function causes any
8306unwritten data for that stream to be delivered to the host environment
8307to be written to the file; otherwise, the behavior is undefined.
8308
8309 If stream is a null pointer, the fflush function performs this
8310flushing action on all streams for which the behavior is defined
8311above.
8312
8313Returns
8314
8315 The fflush function returns EOF if a write error occurs, otherwise zero.
8316
8317Forward references: the ungetc function ($4.9.7.11).
8318
8319
83204.9.5.3 The fopen function
8321
8322Synopsis
8323
8324 #include <stdio.h>
8325 FILE *fopen(const char *filename, const char *mode);
8326
8327Description
8328
8329 The fopen function opens the file whose name is the string pointed
8330to by filename , and associates a stream with it.
8331
8332 The argument mode points to a string beginning with one of the
8333following sequences:/103/
8334
8335"r" open text file for reading
8336"w" truncate to zero length or create text file for writing
8337"a" append; open or create text file for writing at end-of-file
8338"rb" open binary file for reading
8339"wb" truncate to zero length or create binary file for writing
8340"ab" append; open or create binary file for writing at end-of-file
8341"r+" open text file for update (reading and writing)
8342"w+" truncate to zero length or create text file for update
8343"a+" append; open or create text file for update, writing at
8344 end-of-file
8345"r+b" or "rb+" open binary file for update (reading and writing)
8346"w+b" or "wb+" truncate to zero length or create binary file for update
8347"a+b" or "ab+" append; open or create binary file for update, writing at
8348 end-of-file
8349
8350
8351 Opening a file with read mode ('r' as the first character in the
8352mode argument) fails if the file does not exist or cannot be read.
8353
8354 Opening a file with append mode ('a' as the first character in the
8355mode argument) causes all subsequent writes to the file to be forced
8356to the then current end-of-file, regardless of intervening calls to
8357the fseek function. In some implementations, opening a binary file
8358with append mode ('b' as the second or third character in the mode
8359argument) may initially position the file position indicator for the
8360stream beyond the last data written, because of null character
8361padding.
8362
8363 When a file is opened with update mode ('+' as the second or third
8364character in the mode argument), both input and output may be
8365performed on the associated stream. However, output may not be
8366directly followed by input without an intervening call to the fflush
8367function or to a file positioning function ( fseek , fsetpos , or
8368rewind ), and input may not be directly followed by output without an
8369intervening call to a file positioning function, unless the input
8370operation encounters end-of-file. Opening a file with update mode may
8371open or create a binary stream in some implementations.
8372
8373 When opened, a stream is fully buffered if and only if it can be
8374determined not to refer to an interactive device. The error and
8375end-of-file indicators for the stream are cleared.
8376
8377Returns
8378
8379 The fopen function returns a pointer to the object controlling the
8380stream. If the open operation fails, fopen returns a null pointer.
8381
8382Forward references: file positioning functions ($4.9.9).
8383
8384
83854.9.5.4 The freopen function
8386
8387Synopsis
8388
8389 #include <stdio.h>
8390 FILE *freopen(const char *filename, const char *mode,
8391 FILE *stream);
8392
8393Description
8394
8395 The freopen function opens the file whose name is the string
8396pointed to by filename and associates the stream pointed to by stream
8397with it. The mode argument is used just as in the fopen
8398function./104/
8399
8400 The freopen function first attempts to close any file that is
8401associated with the specified stream. Failure to close the file
8402successfully is ignored. The error and end-of-file indicators for the
8403stream are cleared.
8404
8405Returns
8406
8407 The freopen function returns a null pointer if the open operation
8408fails. Otherwise, freopen returns the value of stream .
8409
8410
84114.9.5.5 The setbuf function
8412
8413Synopsis
8414
8415 #include <stdio.h>
8416 void setbuf(FILE *stream, char *buf);
8417
8418Description
8419
8420 Except that it returns no value, the setbuf function is equivalent
8421to the setvbuf function invoked with the values _IOFBF for mode and
8422BUFSIZ for size , or (if buf is a null pointer), with the value _IONBF
8423for mode .
8424
8425Returns
8426
8427 The setbuf function returns no value.
8428
8429Forward references: the setvbuf function ($4.9.5.6).
8430
8431
84324.9.5.6 The setvbuf function
8433
8434Synopsis
8435
8436 #include <stdio.h>
8437 int setvbuf(FILE *stream, char *buf, int mode, size_t size);
8438
8439Description
8440
8441 The setvbuf function may be used after the stream pointed to by
8442stream has been associated with an open file but before any other
8443operation is performed on the stream. The argument mode determines
8444how stream will be buffered, as follows: _IOFBF causes input/output to
8445be fully buffered; _IOLBF causes output to be line buffered; _IONBF
8446causes input/output to be unbuffered. If buf is not a null pointer,
8447the array it points to may be used instead of a buffer allocated by
8448the setvbuf function./105/ The argument size specifies the size of the
8449array. The contents of the array at any time are indeterminate.
8450
8451Returns
8452
8453 The setvbuf function returns zero on success, or nonzero if an
8454invalid value is given for mode or if the request cannot be honored.
8455
8456
84574.9.6 Formatted input/output functions
8458
84594.9.6.1 The fprintf function
8460
8461Synopsis
8462
8463 #include <stdio.h>
8464 int fprintf(FILE *stream, const char *format, ...);
8465
8466Description
8467
8468 The fprintf function writes output to the stream pointed to by
8469stream , under control of the string pointed to by format that
8470specifies how subsequent arguments are converted for output. If there
8471are insufficient arguments for the format, the behavior is undefined.
8472If the format is exhausted while arguments remain, the excess
8473arguments are evaluated (as always) but are otherwise ignored. The
8474fprintf function returns when the end of the format string is
8475encountered.
8476
8477 The format shall be a multibyte character sequence, beginning and
8478ending in its initial shift state. The format is composed of zero or
8479more directives: ordinary multibyte characters (not % ), which are
8480copied unchanged to the output stream; and conversion specifications,
8481each of which results in fetching zero or more subsequent arguments.
8482Each conversion specification is introduced by the character % .
8483After the % , the following appear in sequence:
8484
8485 * Zero or more flags that modify the meaning of the conversion
8486 specification.
8487
8488 * An optional decimal integer specifying a minimum field width ./106/
8489 If the converted value has fewer characters than the field width, it
8490 will be padded with spaces on the left (or right, if the left
8491 adjustment flag, described later, has been given) to the field width.
8492
8493 * An optional precision that gives the minimum number of digits to
8494 appear for the d , i , o , u , x , and X conversions, the number of
8495 digits to appear after the decimal-point character for e , E , and f
8496 conversions, the maximum number of significant digits for the g and G
8497 conversions, or the maximum number of characters to be written from a
8498 string in s conversion. The precision takes the form of a period (.)
8499 followed by an optional decimal integer; if the integer is
8500 omitted, it is treated as zero.
8501
8502 * An optional h specifying that a following d , i , o , u , x , or X
8503 conversion specifier applies to a short int or unsigned short int
8504 argument (the argument will have been promoted according to the
8505 integral promotions, and its value shall be converted to short int or
8506 unsigned short int before printing); an optional h specifying that a
8507 following n conversion specifier applies to a pointer to a short int
8508 argument; an optional l (ell) specifying that a following d , i , o ,
8509 u , x , or X conversion specifier applies to a long int or unsigned
8510 long int argument; an optional l specifying that a following n
8511 conversion specifier applies to a pointer to a long int argument; or
8512 an optional L specifying that a following e , E , f , g , or G
8513 conversion specifier applies to a long double argument. If an h , l ,
8514 or L appears with any other conversion specifier, the behavior is
8515 undefined.
8516
8517 * A character that specifies the type of conversion to be applied.
8518
8519 A field width or precision, or both, may be indicated by an
8520asterisk * instead of a digit string. In this case, an int argument
8521supplies the field width or precision. The arguments specifying field
8522width or precision, or both, shall appear (in that order) before the
8523argument (if any) to be converted. A negative field width argument is
8524taken as a - flag followed by a positive field width. A negative
8525precision argument is taken as if it were missing.
8526
8527 The flag characters and their meanings are
8528
8529- The result of the conversion will be left-justified within the field.
8530
8531+ The result of a signed conversion will always begin with a plus or
8532 minus sign.
8533
8534space If the first character of a signed conversion is not a sign,
8535 or if a signed conversion results in no characters, a space will be
8536 prepended to the result. If the space and + flags both appear, the
8537 space flag will be ignored.
8538
8539# The result is to be converted to an ``alternate form.'' For
8540 o conversion, it increases the precision to force the first digit of
8541 the result to be a zero. For x (or X ) conversion, a nonzero result
8542 will have 0x (or 0X ) prepended to it. For e , E , f , g , and G
8543 conversions, the result will always contain a decimal-point character,
8544 even if no digits follow it (normally, a decimal-point character
8545 appears in the result of these conversions only if a digit follows
8546 it). For g and G conversions, trailing zeros will not be removed from
8547 the result. For other conversions, the behavior is undefined.
8548
85490 For d, i, o, u, x, X, e, E, f, g and G conversions, leading zeros
8550 (following any indication of sign or base) are used to pad to the
8551 field width; no space padding is performed. If the 0 and - flags
8552 both appear, the 0 flag will be ignored. For d, i, o, u, x and X
8553 conversions, if a precision is specified, the 0 flag will be
8554 ignored. For other conversions, the behavior is undefined.
8555
8556 The conversion specifiers and their meanings are
8557
8558d, i, o, u, x, X The int argument is converted to signed decimal ( d
8559 or i ), unsigned octal ( o ), unsigned decimal ( u ), or unsigned
8560 hexadecimal notation ( x or X ); the letters abcdef are used for x
8561 conversion and the letters ABCDEF for X conversion. The precision
8562 specifies the minimum number of digits to appear; if the value being
8563 converted can be represented in fewer digits, it will be expanded with
8564 leading zeros. The default precision is 1. The result of converting
8565 a zero value with an explicit precision of zero is no characters.
8566
8567f The double argument is converted to decimal notation in the style
8568 [-]ddd.ddd , where the number of digits after the decimal-point
8569 character is equal to the precision specification. If the precision
8570 is missing, it is taken as 6; if the precision is explicitly zero, no
8571 decimal-point character appears. If a decimal-point character
8572 appears, at least one digit appears before it. The value is rounded
8573 to the appropriate number of digits.
8574
8575e, E The double argument is converted in the style [-]d.ddde+- dd ,
8576 where there is one digit before the decimal-point character (which is
8577 nonzero if the argument is nonzero) and the number of digits after it
8578 is equal to the precision; if the precision is missing, it is taken as
8579 6; if the precision is zero, no decimal-point character appears. The
8580 value is rounded to the appropriate number of digits. The E
8581 conversion specifier will produce a number with E instead of e
8582 introducing the exponent. The exponent always contains at least two
8583 digits. If the value is zero, the exponent is zero.
8584
8585g, G The double argument is converted in style f or e (or in style E
8586 in the case of a G conversion specifier), with the precision
8587 specifying the number of significant digits. If an explicit precision
8588 is zero, it is taken as 1. The style used depends on the value
8589 converted; style e will be used only if the exponent resulting from
8590 such a conversion is less than -4 or greater than or equal to the
8591 precision. Trailing zeros are removed from the fractional portion of
8592 the result; a decimal-point character appears only if it is followed
8593 by a digit.
8594
8595c The int argument is converted to an unsigned char , and the resulting
8596 character is written.
8597
8598s The argument shall be a pointer to an array of character type./107/
8599 Characters from the array are written up to (but not including) a
8600 terminating null character; if the precision is specified, no more
8601 than that many characters are written. If the precision is not
8602 specified or is greater than the size of the array, the array shall
8603 contain a null character.
8604
8605p The argument shall be a pointer to void . The value of the pointer
8606 is converted to a sequence of printable characters, in an
8607 implementation-defined manner.
8608
8609n The argument shall be a pointer to an integer into which is written
8610 the number of characters written to the output stream so far by this
8611 call to fprintf . No argument is converted.
8612
8613% A % is written. No argument is converted. The complete conversion
8614 specification shall be %% .
8615
8616 If a conversion specification is invalid, the behavior is
8617undefined./108/
8618
8619 If any argument is, or points to, a union or an aggregate (except
8620for an array of character type using %s conversion, or a pointer cast
8621to be a pointer to void using %p conversion), the behavior is
8622undefined.
8623
8624 In no case does a nonexistent or small field width cause truncation
8625of a field; if the result of a conversion is wider than the field
8626width, the field is expanded to contain the conversion result.
8627
8628Returns
8629
8630 The fprintf function returns the number of characters transmitted,
8631or a negative value if an output error occurred.
8632
8633"Environmental limit"
8634
8635 The minimum value for the maximum number of characters produced by
8636any single conversion shall be 509.
8637
8638Examples
8639
8640 To print a date and time in the form ``Sunday, July 3, 10:02,''
8641where weekday and month are pointers to strings:
8642
8643 #include <stdio.h>
8644 fprintf(stdout, "%s, %s %d, %.2d:%.2d\n",
8645 weekday, month, day, hour, min);
8646
8647To print PI to five decimal places:
8648
8649 #include <math.h>
8650 #include <stdio.h>
8651 fprintf(stdout, "pi = %.5f\n", 4 * atan(1.0));
8652
8653
86544.9.6.2 The fscanf function
8655
8656Synopsis
8657
8658 #include <stdio.h>
8659 int fscanf(FILE *stream, const char *format, ...);
8660
8661Description
8662
8663 The fscanf function reads input from the stream pointed to by
8664stream , under control of the string pointed to by format that
8665specifies the admissible input sequences and how they are to be
8666converted for assignment, using subsequent arguments as pointers to
8667the objects to receive the converted input. If there are insufficient
8668arguments for the format, the behavior is undefined. If the format is
8669exhausted while arguments remain, the excess arguments are evaluated
8670(as always) but are otherwise ignored.
8671
8672 The format shall be a multibyte character sequence, beginning and
8673ending in its initial shift state. The format is composed of zero or
8674more directives: one or more white-space characters; an ordinary
8675multibyte character (not % ); or a conversion specification. Each
8676conversion specification is introduced by the character % . After the %,
8677the following appear in sequence:
8678
8679 * An optional assignment-suppressing character * .
8680
8681 * An optional decimal integer that specifies the maximum field width.
8682
8683 * An optional h , l (ell) or L indicating the size of the receiving
8684 object. The conversion specifiers d , i , and n shall be preceded by
8685 h if the corresponding argument is a pointer to short int rather than
8686 a pointer to int , or by l if it is a pointer to long int .
8687 Similarly, the conversion specifiers o , u , and x shall be preceded
8688 by h if the corresponding argument is a pointer to unsigned short int
8689 rather than a pointer to unsigned int , or by l if it is a pointer to
8690 unsigned long int . Finally, the conversion specifiers e , f , and g
8691 shall be preceded by l if the corresponding argument is a pointer to
8692 double rather than a pointer to float , or by L if it is a pointer to
8693 long double . If an h , l , or L appears with any other conversion
8694 specifier, the behavior is undefined.
8695
8696 * A character that specifies the type of conversion to be applied.
8697The valid conversion specifiers are described below.
8698
8699 The fscanf function executes each directive of the format in turn.
8700If a directive fails, as detailed below, the fscanf function returns.
8701Failures are described as input failures (due to the unavailability of
8702input characters), or matching failures (due to inappropriate input).
8703
8704 A directive composed of white space is executed by reading input up
8705to the first non-white-space character (which remains unread), or
8706until no more characters can be read.
8707
8708 A directive that is an ordinary multibyte character is executed by
8709reading the next characters of the stream. If one of the characters
8710differs from one comprising the directive, the directive fails, and
8711the differing and subsequent characters remain unread.
8712
8713 A directive that is a conversion specification defines a set of
8714matching input sequences, as described below for each specifier. A
8715conversion specification is executed in the following steps:
8716
8717 Input white-space characters (as specified by the isspace function)
8718are skipped, unless the specification includes a [ , c , or n
8719specifier.
8720
8721 An input item is read from the stream, unless the specification
8722includes an n specifier. An input item is defined as the longest
8723sequence of input characters (up to any specified maximum field width)
8724which is an initial subsequence of a matching sequence. The first
8725character, if any, after the input item remains unread. If the length
8726of the input item is zero, the execution of the directive fails: this
8727condition is a matching failure, unless an error prevented input from
8728the stream, in which case it is an input failure.
8729
8730 Except in the case of a % specifier, the input item (or, in the
8731case of a %n directive, the count of input characters) is converted to
8732a type appropriate to the conversion specifier. If the input item is
8733not a matching sequence, the execution of the directive fails: this
8734condition is a matching failure. Unless assignment suppression was
8735indicated by a * , the result of the conversion is placed in the
8736object pointed to by the first argument following the format argument
8737that has not already received a conversion result. If this object
8738does not have an appropriate type, or if the result of the conversion
8739cannot be represented in the space provided, the behavior is
8740undefined.
8741
8742 The following conversion specifiers are valid:
8743
8744d Matches an optionally signed decimal integer, whose format is the
8745 same as expected for the subject sequence of the strtol function with
8746 the value 10 for the base argument. The corresponding argument shall
8747 be a pointer to integer.
8748
8749i Matches an optionally signed integer, whose format is the same as
8750 expected for the subject sequence of the strtol function with the
8751 value 0 for the base argument. The corresponding argument shall be a
8752 pointer to integer.
8753
8754o Matches an optionally signed octal integer, whose format is the same
8755 as expected for the subject sequence of the strtoul function with the
8756 value 8 for the base argument. The corresponding argument shall be a
8757 pointer to unsigned integer.
8758
8759u Matches an optionally signed decimal integer, whose format is the same
8760 as expected for the subject sequence of the strtoul function with the
8761 value 10 for the base argument. The corresponding argument shall be a
8762 pointer to unsigned integer.
8763
8764x Matches an optionally signed hexadecimal integer, whose format is the
8765 same as expected for the subject sequence of the strtoul function with
8766 the value 16 for the base argument. The corresponding argument shall
8767 be a pointer to unsigned integer.
8768
8769e,f,g Matches an optionally signed floating-point number, whose format is
8770 the same as expected for the subject string of the strtod function.
8771 The corresponding argument shall be a pointer to floating.
8772
8773s Matches a sequence of non-white-space characters. The corresponding
8774 argument shall be a pointer to the initial character of an array large
8775 enough to accept the sequence and a terminating null character, which
8776 will be added automatically.
8777
8778[ Matches a nonempty sequence of characters from a set of expected
8779 characters (the scanset ). The corresponding argument shall be a
8780 pointer to the initial character of an array large enough to accept
8781 the sequence and a terminating null character, which will be added
8782 automatically. The conversion specifier includes all subsequent
8783 characters in the format string, up to and including the matching
8784 right bracket ( ] ). The characters between the brackets (the
8785 scanlist ) comprise the scanset, unless the character after the left
8786 bracket is a circumflex ( ^ ), in which case the scanset contains all
8787 characters that do not appear in the scanlist between the circumflex
8788 and the right bracket. As a special case, if the conversion specifier
8789 begins with [] or [^] , the right bracket character is in the scanlist
8790 and the next right bracket character is the matching right bracket
8791 that ends the specification. If a - character is in the scanlist and
8792 is not the first, nor the second where the first character is a ^ ,
8793 nor the last character, the behavior is implementation-defined.
8794
8795c Matches a sequence of characters of the number specified by the
8796 field width (1 if no field width is present in the directive). The
8797 corresponding argument shall be a pointer to the initial character of
8798 an array large enough to accept the sequence. No null character is
8799 added.
8800
8801p Matches an implementation-defined set of sequences, which should be
8802 the same as the set of sequences that may be produced by the %p
8803 conversion of the fprintf function. The corresponding argument shall
8804 be a pointer to a pointer to void . The interpretation of the input
8805 item is implementation-defined; however, for any input item other than
8806 a value converted earlier during the same program execution, the
8807 behavior of the %p conversion is undefined.
8808
8809n No input is consumed. The corresponding argument shall be a pointer
8810 to integer into which is to be written the number of characters read
8811 from the input stream so far by this call to the fscanf function.
8812 Execution of a %n directive does not increment the assignment count
8813 returned at the completion of execution of the fscanf function.
8814
8815% Matches a single % ; no conversion or assignment occurs. The complete
8816 conversion specification shall be %% .
8817
8818 If a conversion specification is invalid, the behavior is
8819undefined./110/
8820
8821 The conversion specifiers E , G , and X are also valid and behave
8822the same as, respectively, e , g , and x .
8823
8824 If end-of-file is encountered during input, conversion is
8825terminated. If end-of-file occurs before any characters matching the
8826current directive have been read (other than leading white space,
8827where permitted), execution of the current directive terminates with
8828an input failure; otherwise, unless execution of the current directive
8829is terminated with a matching failure, execution of the following
8830directive (if any) is terminated with an input failure.
8831
8832 If conversion terminates on a conflicting input character, the
8833offending input character is left unread in the input stream.
8834Trailing white space (including new-line characters) is left unread
8835unless matched by a directive. The success of literal matches and
8836suppressed assignments is not directly determinable other than via the
8837%n directive.
8838
8839Returns
8840
8841 The fscanf function returns the value of the macro EOF if an input
8842failure occurs before any conversion. Otherwise, the fscanf function
8843returns the number of input items assigned, which can be fewer than
8844provided for, or even zero, in the event of an early matching failure.
8845
8846Examples
8847
8848 The call:
8849
8850 #include <stdio.h>
8851 int n, i; float x; char name[50];
8852 n = fscanf(stdin, "%d%f%s", &i, &x, name);
8853
8854with the input line:
8855
8856 25 54.32E-1 thompson
8857
8858will assign to n the value 3, to i the value 25, to x the value 5.432,
8859and name will contain thompson\0 . Or:
8860
8861 #include <stdio.h>
8862 int i; float x; char name[50];
8863 fscanf(stdin, "%2d%f%*d %[0123456789]", &i, &x, name);
8864
8865with input:
8866
8867 56789 0123 56a72
8868
8869will assign to i the value 56 and to x the value 789.0, will skip
88700123, and name will contain 56\0 . The next character read from the
8871input stream will be a .
8872
8873 To accept repeatedly from stdin a quantity, a unit of measure and
8874an item name:
8875
8876 #include <stdio.h>
8877 int count; float quant; char units[21], item[21];
8878 while (!feof(stdin) && !ferror(stdin)) {
8879 count = fscanf(stdin, "%f%20s of %20s",
8880 &quant, units, item);
8881 fscanf(stdin,"%*[^\n]");
8882 }
8883
8884
8885 If the stdin stream contains the following lines:
8886
8887 2 quarts of oil
8888 -12.8degrees Celsius
8889 lots of luck
8890 10.0LBS of fertilizer
8891 100ergs of energy
8892
8893the execution of the above example will be equivalent to the following
8894assignments:
8895
8896 quant = 2; strcpy(units, "quarts"); strcpy(item, "oil");
8897 count = 3;
8898 quant = -12.8; strcpy(units, "degrees");
8899 count = 2; /* "C" fails to match "o" */
8900 count = 0; /* "l" fails to match "%f" */
8901 quant = 10.0; strcpy(units, "LBS"); strcpy(item, "fertilizer");
8902 count = 3;
8903 count = 0; /* "100e" fails to match "%f" */
8904 count = EOF;
8905
8906Forward references: the strtod function ($4.10.1.4), the strtol
8907function ($4.10.1.5), the strtoul function ($4.10.1.6).
8908
8909
89104.9.6.3 The printf function
8911
8912Synopsis
8913
8914 #include <stdio.h>
8915 int printf(const char *format, ...);
8916
8917Description
8918
8919 The printf function is equivalent to fprintf with the argument
8920stdout interposed before the arguments to printf .
8921
8922Returns
8923
8924 The printf function returns the number of characters transmitted,
8925or a negative value if an output error occurred.
8926
8927
89284.9.6.4 The scanf function
8929
8930Synopsis
8931
8932 #include <stdio.h>
8933 int scanf(const char *format, ...);
8934
8935Description
8936
8937 The scanf function is equivalent to fscanf with the argument stdin
8938interposed before the arguments to scanf .
8939
8940Returns
8941
8942 The scanf function returns the value of the macro EOF if an input
8943failure occurs before any conversion. Otherwise, the scanf function
8944returns the number of input items assigned, which can be fewer than
8945provided for, or even zero, in the event of an early matching failure.
8946
8947
89484.9.6.5 The sprintf function
8949
8950Synopsis
8951
8952 #include <stdio.h>
8953 int sprintf(char *s, const char *format, ...);
8954
8955Description
8956
8957 The sprintf function is equivalent to fprintf , except that the
8958argument s specifies an array into which the generated output is to be
8959written, rather than to a stream. A null character is written at the
8960end of the characters written; it is not counted as part of the
8961returned sum. If copying takes place between objects that overlap,
8962the behavior is undefined.
8963
8964Returns
8965
8966 The sprintf function returns the number of characters written in
8967the array, not counting the terminating null character.
8968
8969
89704.9.6.6 The sscanf function
8971
8972Synopsis
8973
8974 #include <stdio.h>
8975 int sscanf(const char *s, const char *format, ...);
8976
8977Description
8978
8979 The sscanf function is equivalent to fscanf , except that the
8980argument s specifies a string from which the input is to be obtained,
8981rather than from a stream. Reaching the end of the string is
8982equivalent to encountering end-of-file for the fscanf function. If
8983copying takes place between objects that overlap, the behavior is
8984undefined.
8985
8986Returns
8987
8988 The sscanf function returns the value of the macro EOF if an input
8989failure occurs before any conversion. Otherwise, the sscanf function
8990returns the number of input items assigned, which can be fewer than
8991provided for, or even zero, in the event of an early matching failure.
8992
8993
89944.9.6.7 The vfprintf function
8995
8996Synopsis
8997
8998 #include <stdarg.h>
8999 #include <stdio.h>
9000 int vfprintf(FILE *stream, const char *format, va_list arg);
9001
9002Description
9003
9004 The vfprintf function is equivalent to fprintf , with the variable
9005argument list replaced by arg , which has been initialized by the
9006va_start macro (and possibly subsequent va_arg calls). The vfprintf
9007function does not invoke the va_end macro.
9008
9009Returns
9010
9011 The vfprintf function returns the number of characters transmitted,
9012or a negative value if an output error occurred.
9013
9014Example
9015
9016 The following shows the use of the vfprintf function in a general
9017error-reporting routine.
9018
9019 #include <stdarg.h>
9020 #include <stdio.h>
9021
9022 void error(char *function_name, char *format, ...)
9023 {
9024 va_list args;
9025
9026 va_start(args, format);
9027 /* print out name of function causing error */
9028 fprintf(stderr, "ERROR in %s: ", function_name);
9029 /* print out remainder of message */
9030 vfprintf(stderr, format, args);
9031 va_end(args);
9032 }
9033
9034
90354.9.6.8 The vprintf function
9036
9037Synopsis
9038
9039 #include <stdarg.h>
9040 #include <stdio.h>
9041 int vprintf(const char *format, va_list arg);
9042
9043Description
9044
9045 The vprintf function is equivalent to printf , with the variable
9046argument list replaced by arg , which has been initialized by the
9047va_start macro (and possibly subsequent va_arg calls). The vprintf
9048function does not invoke the va_end macro.rN
9049
9050Returns
9051
9052 The vprintf function returns the number of characters transmitted,
9053or a negative value if an output error occurred.
9054
9055
90564.9.6.9 The vsprintf function
9057
9058Synopsis
9059
9060 #include <stdarg.h>
9061 #include <stdio.h>
9062 int vsprintf(char *s, const char *format, va_list arg);
9063
9064Description
9065
9066 The vsprintf function is equivalent to sprintf , with the variable
9067argument list replaced by arg , which has been initialized by the
9068va_start macro (and possibly subsequent va_arg calls). The vsprintf
9069function does not invoke the va_end macro.rN If copying takes place
9070between objects that overlap, the behavior is undefined.
9071
9072Returns
9073
9074 The vsprintf function returns the number of characters written in
9075the array, not counting the terminating null character.
9076
9077
90784.9.7 Character input/output functions
9079
90804.9.7.1 The fgetc function
9081
9082Synopsis
9083
9084 #include <stdio.h>
9085 int fgetc(FILE *stream);
9086
9087Description
9088
9089 The fgetc function obtains the next character (if present) as an
9090unsigned char converted to an int , from the input stream pointed to
9091by stream , and advances the associated file position indicator for
9092the stream (if defined).
9093
9094Returns
9095
9096 The fgetc function returns the next character from the input stream
9097pointed to by stream . If the stream is at end-of-file, the
9098end-of-file indicator for the stream is set and fgetc returns EOF .
9099If a read error occurs, the error indicator for the stream is set and
9100fgetc returns EOF ./112/
9101
9102
91034.9.7.2 The fgets function
9104
9105Synopsis
9106
9107 #include <stdio.h>
9108 char *fgets(char *s, int n, FILE *stream);
9109
9110Description
9111
9112 The fgets function reads at most one less than the number of
9113characters specified by n from the stream pointed to by stream into
9114the array pointed to by s . No additional characters are read after a
9115new-line character (which is retained) or after end-of-file. A null
9116character is written immediately after the last character read into
9117the array.
9118
9119Returns
9120
9121 The fgets function returns s if successful. If end-of-file is
9122encountered and no characters have been read into the array, the
9123contents of the array remain unchanged and a null pointer is returned.
9124If a read error occurs during the operation, the array contents are
9125indeterminate and a null pointer is returned.
9126
9127
91284.9.7.3 The fputc function
9129
9130Synopsis
9131
9132 #include <stdio.h>
9133 int fputc(int c, FILE *stream);
9134
9135Description
9136
9137 The fputc function writes the character specified by c (converted
9138to an unsigned char ) to the output stream pointed to by stream , at
9139the position indicated by the associated file position indicator for
9140the stream (if defined), and advances the indicator appropriately. If
9141the file cannot support positioning requests, or if the stream was
9142opened with append mode, the character is appended to the output
9143stream.
9144
9145Returns
9146
9147 The fputc function returns the character written. If a write error
9148occurs, the error indicator for the stream is set and fputc returns EOF.
9149
9150
91514.9.7.4 The fputs function
9152
9153Synopsis
9154
9155 #include <stdio.h>
9156 int fputs(const char *s, FILE *stream);
9157
9158Description
9159
9160 The fputs function writes the string pointed to by s to the stream
9161pointed to by stream . The terminating null character is not written.
9162
9163Returns
9164
9165 The fputs function returns EOF if a write error occurs; otherwise
9166it returns a nonnegative value.
9167
9168
91694.9.7.5 The getc function
9170
9171Synopsis
9172
9173 #include <stdio.h>
9174 int getc(FILE *stream);
9175
9176Description
9177
9178 The getc function is equivalent to fgetc , except that if it is
9179implemented as a macro, it may evaluate stream more than once, so the
9180argument should never be an expression with side effects.
9181
9182Returns
9183
9184 The getc function returns the next character from the input stream
9185pointed to by stream . If the stream is at end-of-file, the
9186end-of-file indicator for the stream is set and getc returns EOF . If
9187a read error occurs, the error indicator for the stream is set and
9188getc returns EOF .
9189
9190
91914.9.7.6 The getchar function
9192
9193Synopsis
9194
9195 #include <stdio.h>
9196 int getchar(void);
9197
9198Description
9199
9200 The getchar function is equivalent to getc with the argument stdin .
9201
9202Returns
9203
9204 The getchar function returns the next character from the input
9205stream pointed to by stdin . If the stream is at end-of-file, the
9206end-of-file indicator for the stream is set and getchar returns EOF .
9207If a read error occurs, the error indicator for the stream is set and
9208getchar returns EOF .
9209
9210
92114.9.7.7 The gets function
9212
9213Synopsis
9214
9215 #include <stdio.h>
9216 char *gets(char *s);
9217
9218Description
9219
9220 The gets function reads characters from the input stream pointed to
9221by stdin , into the array pointed to by s , until end-of-file is
9222encountered or a new-line character is read. Any new-line character
9223is discarded, and a null character is written immediately after the
9224last character read into the array.
9225
9226Returns
9227
9228 The gets function returns s if successful. If end-of-file is
9229encountered and no characters have been read into the array, the
9230contents of the array remain unchanged and a null pointer is returned.
9231If a read error occurs during the operation, the array contents are
9232indeterminate and a null pointer is returned.
9233
9234
92354.9.7.8 The putc function
9236
9237Synopsis
9238
9239 #include <stdio.h>
9240 int putc(int c, FILE *stream);
9241
9242Description
9243
9244 The putc function is equivalent to fputc , except that if it is
9245implemented as a macro, it may evaluate stream more than once, so the
9246argument should never be an expression with side effects.
9247
9248Returns
9249
9250 The putc function returns the character written. If a write error
9251occurs, the error indicator for the stream is set and putc returns EOF.
9252
9253
92544.9.7.9 The putchar function
9255
9256Synopsis
9257
9258 #include <stdio.h>
9259 int putchar(int c);
9260
9261Description
9262
9263 The putchar function is equivalent to putc with the second argument
9264stdout.
9265
9266Returns
9267
9268 The putchar function returns the character written. If a write
9269error occurs, the error indicator for the stream is set and putchar
9270returns EOF.
9271
9272
92734.9.7.10 The puts function
9274
9275Synopsis
9276
9277 #include <stdio.h>
9278 int puts(const char *s);
9279
9280Description
9281
9282 The puts function writes the string pointed to by s to the stream
9283pointed to by stdout , and appends a new-line character to the output.
9284The terminating null character is not written.
9285
9286Returns
9287
9288 The puts function returns EOF if a write error occurs; otherwise it
9289returns a nonnegative value.
9290
9291
92924.9.7.11 The ungetc function
9293
9294Synopsis
9295
9296 #include <stdio.h>
9297 int ungetc(int c, FILE *stream);
9298
9299Description
9300
9301 The ungetc function pushes the character specified by c (converted
9302to an unsigned char ) back onto the input stream pointed to by stream.
9303The pushed-back characters will be returned by subsequent reads on
9304that stream in the reverse order of their pushing. A successful
9305intervening call (with the stream pointed to by stream ) to a file
9306positioning function ( fseek , fsetpos , or rewind ) discards any
9307pushed-back characters for the stream. The external storage
9308corresponding to the stream is unchanged.
9309
9310 One character of pushback is guaranteed. If the ungetc function is
9311called too many times on the same stream without an intervening read
9312or file positioning operation on that stream, the operation may fail.
9313
9314 If the value of c equals that of the macro EOF , the operation
9315fails and the input stream is unchanged.
9316
9317 A successful call to the ungetc function clears the end-of-file
9318indicator for the stream. The value of the file position indicator
9319for the stream after reading or discarding all pushed-back characters
9320shall be the same as it was before the characters were pushed back.
9321For a text stream, the value of its file position indicator after a
9322successful call to the ungetc function is unspecified until all
9323pushed-back characters are read or discarded. For a binary stream,
9324its file position indicator is decremented by each successful call to
9325the ungetc function; if its value was zero before a call, it is
9326indeterminate after the call.
9327
9328Returns
9329
9330 The ungetc function returns the character pushed back after
9331conversion, or EOF if the operation fails.
9332
9333Forward references: file positioning functions ($4.9.9).
9334
9335
93364.9.8 Direct input/output functions
9337
93384.9.8.1 The fread function
9339
9340Synopsis
9341
9342 #include <stdio.h>
9343 size_t fread(void *ptr, size_t size, size_t nmemb,
9344 FILE *stream);
9345
9346Description
9347
9348 The fread function reads, into the array pointed to by ptr , up to
9349nmemb members whose size is specified by size , from the stream
9350pointed to by stream . The file position indicator for the stream (if
9351defined) is advanced by the number of characters successfully read.
9352If an error occurs, the resulting value of the file position indicator
9353for the stream is indeterminate. If a partial member is read, its
9354value is indeterminate.
9355
9356Returns
9357
9358 The fread function returns the number of members successfully read,
9359which may be less than nmemb if a read error or end-of-file is
9360encountered. If size or nmemb is zero, fread returns zero and the
9361contents of the array and the state of the stream remain unchanged.
9362
9363
93644.9.8.2 The fwrite function
9365
9366Synopsis
9367
9368 #include <stdio.h>
9369 size_t fwrite(const void *ptr, size_t size, size_t nmemb,
9370 FILE *stream);
9371
9372Description
9373
9374 The fwrite function writes, from the array pointed to by ptr , up
9375to nmemb members whose size is specified by size , to the stream
9376pointed to by stream . The file position indicator for the stream (if
9377defined) is advanced by the number of characters successfully written.
9378If an error occurs, the resulting value of the file position indicator
9379for the stream is indeterminate.
9380
9381Returns
9382
9383 The fwrite function returns the number of members successfully
9384written, which will be less than nmemb only if a write error is
9385encountered.
9386
9387
93884.9.9 File positioning functions
9389
93904.9.9.1 The fgetpos function
9391
9392Synopsis
9393
9394 #include <stdio.h>
9395 int fgetpos(FILE *stream, fpos_t *pos);
9396
9397Description
9398
9399 The fgetpos function stores the current value of the file position
9400indicator for the stream pointed to by stream in the object pointed to
9401by pos . The value stored contains unspecified information usable by
9402the fsetpos function for repositioning the stream to its position at
9403the time of the call to the fgetpos function.
9404
9405Returns
9406
9407 If successful, the fgetpos function returns zero; on failure, the
9408fgetpos function returns nonzero and stores an implementation-defined
9409positive value in errno .
9410
9411Forward references: the fsetpos function ($4.9.9.3).
9412
9413
94144.9.9.2 The fseek function
9415
9416Synopsis
9417
9418 #include <stdio.h>
9419 int fseek(FILE *stream, long int offset, int whence);
9420
9421Description
9422
9423 The fseek function sets the file position indicator for the stream
9424pointed to by stream .
9425
9426 For a binary stream, the new position, measured in characters from
9427the beginning of the file, is obtained by adding offset to the
9428position specified by whence. The specified point is the beginning
9429of the file for SEEK_SET, the current value of the file position
9430indicator for SEEK_CUR, or end-of-file for SEEK_END. A binary
9431stream need not meaningfully support fseek calls with a whence value
9432of SEEK_END.
9433
9434 For a text stream, either offset shall be zero, or offset shall be
9435a value returned by an earlier call to the ftell function on the same
9436stream and whence shall be SEEK_SET .
9437
9438 A successful call to the fseek function clears the end-of-file
9439indicator for the stream and undoes any effects of the ungetc function
9440on the same stream. After an fseek call, the next operation on an
9441update stream may be either input or output.
9442
9443Returns
9444
9445 The fseek function returns nonzero only for a request that cannot
9446be satisfied.
9447
9448Forward references: the ftell function ($4.9.9.4).
9449
9450
94514.9.9.3 The fsetpos function
9452
9453Synopsis
9454
9455 #include <stdio.h>
9456 int fsetpos(FILE *stream, const fpos_t *pos);
9457
9458Description
9459
9460 The fsetpos function sets the file position indicator for the
9461stream pointed to by stream according to the value of the object
9462pointed to by pos , which shall be a value returned by an earlier call
9463to the fgetpos function on the same stream.
9464
9465 A successful call to the fsetpos function clears the end-of-file
9466indicator for the stream and undoes any effects of the ungetc function
9467on the same stream. After an fsetpos call, the next operation on an
9468update stream may be either input or output.
9469
9470Returns
9471
9472 If successful, the fsetpos function returns zero; on failure, the
9473fsetpos function returns nonzero and stores an implementation-defined
9474positive value in errno .
9475
9476
94774.9.9.4 The ftell function
9478
9479Synopsis
9480
9481 #include <stdio.h>
9482 long int ftell(FILE *stream);
9483
9484Description
9485
9486 The ftell function obtains the current value of the file position
9487indicator for the stream pointed to by stream . For a binary stream,
9488the value is the number of characters from the beginning of the file.
9489For a text stream, its file position indicator contains unspecified
9490information, usable by the fseek function for returning the file
9491position indicator for the stream to its position at the time of the
9492ftell call; the difference between two such return values is not
9493necessarily a meaningful measure of the number of characters written
9494or read.
9495
9496Returns
9497
9498 If successful, the ftell function returns the current value of the
9499file position indicator for the stream. On failure, the ftell
9500function returns -1L and stores an implementation-defined positive
9501value in errno .
9502
9503
95044.9.9.5 The rewind function
9505
9506Synopsis
9507
9508 #include <stdio.h>
9509 void rewind(FILE *stream);
9510
9511Description
9512
9513 The rewind function sets the file position indicator for the stream
9514pointed to by stream to the beginning of the file. It is equivalent to
9515
9516 (void)fseek(stream, 0L, SEEK_SET)
9517
9518except that the error indicator for the stream is also cleared.
9519
9520Returns
9521
9522 The rewind function returns no value.
9523
9524
95254.9.10 Error-handling functions
9526
95274.9.10.1 The clearerr function
9528
9529Synopsis
9530
9531 #include <stdio.h>
9532 void clearerr(FILE *stream);
9533
9534Description
9535
9536 The clearerr function clears the end-of-file and error indicators
9537for the stream pointed to by stream .
9538
9539Returns
9540
9541 The clearerr function returns no value.
9542
9543
95444.9.10.2 The feof function
9545
9546Synopsis
9547
9548 #include <stdio.h>
9549 int feof(FILE *stream);
9550
9551Description
9552
9553 The feof function tests the end-of-file indicator for the stream
9554pointed to by stream .
9555
9556Returns
9557
9558 The feof function returns nonzero if and only if the end-of-file
9559indicator is set for stream .
9560
9561
95624.9.10.3 The ferror function
9563
9564
9565Synopsis
9566
9567 #include <stdio.h>
9568 int ferror(FILE *stream);
9569
9570Description
9571
9572 The ferror function tests the error indicator for the stream
9573pointed to by stream .
9574
9575Returns
9576
9577 The ferror function returns nonzero if and only if the error
9578indicator is set for stream .
9579
9580
95814.9.10.4 The perror function
9582
9583Synopsis
9584
9585 #include <stdio.h>
9586 void perror(const char *s);
9587
9588Description
9589
9590 The perror function maps the error number in the integer expression
9591errno to an error message. It writes a sequence of characters to the
9592standard error stream thus: first (if s is not a null pointer and the
9593character pointed to by s is not the null character), the string
9594pointed to by s followed by a colon and a space; then an appropriate
9595error message string followed by a new-line character. The contents
9596of the error message strings are the same as those returned by the
9597strerror function with argument errno , which are
9598implementation-defined.
9599
9600Returns
9601
9602 The perror function returns no value.
9603
9604Forward references: the strerror function ($4.11.6.2).
9605
9606
96074.10 GENERAL UTILITIES <stdlib.h>
9608
9609 The header <stdlib.h> declares four types and several functions of
9610general utility, and defines several macros./113/
9611
9612 The types declared are size_t and wchar_t (both described in $4.1.5),
9613
9614 div_t
9615
9616which is a structure type that is the type of the value returned by
9617the div function, and
9618
9619 ldiv_t
9620
9621which is a structure type that is the type of the value returned by
9622the ldiv function.
9623
9624 The macros defined are NULL (described in $4.1.5);
9625
9626 EXIT_FAILURE
9627
9628and
9629
9630 EXIT_SUCCESS
9631
9632which expand to integral expressions that may be used as the argument
9633to the exit function to return unsuccessful or successful termination
9634status, respectively, to the host environment;
9635
9636 RAND_MAX
9637
9638which expands to an integral constant expression, the value of which
9639is the maximum value returned by the rand function; and
9640
9641 MB_CUR_MAX
9642
9643which expands to a positive integer expression whose value is the
9644maximum number of bytes in a multibyte character for the extended
9645character set specified by the current locale (category LC_CTYPE ),
9646and whose value is never greater than MB_LEN_MAX .
9647
9648
96494.10.1 String conversion functions
9650
9651 The functions atof , atoi , and atol need not affect the value of
9652the integer expression errno on an error. If the value of the result
9653cannot be represented, the behavior is undefined.
9654
9655
96564.10.1.1 The atof function
9657
9658Synopsis
9659
9660 #include <stdlib.h>
9661 double atof(const char *nptr);
9662
9663Description
9664
9665 The atof function converts the initial portion of the string
9666pointed to by nptr to double representation. Except for the behavior
9667on error, it is equivalent to
9668
9669 strtod(nptr, (char **)NULL)
9670
9671Returns
9672
9673 The atof function returns the converted value.
9674
9675Forward references: the strtod function ($4.10.1.4).
9676
9677
96784.10.1.2 The atoi function
9679
9680Synopsis
9681
9682 #include <stdlib.h>
9683 int atoi(const char *nptr);
9684
9685Description
9686
9687 The atoi function converts the initial portion of the string
9688pointed to by nptr to int representation. Except for the behavior on
9689error, it is equivalent to
9690
9691 (int)strtol(nptr, (char **)NULL, 10)
9692
9693Returns
9694
9695 The atoi function returns the converted value.
9696
9697Forward references: the strtol function ($4.10.1.5).
9698
9699
97004.10.1.3 The atol function
9701
9702Synopsis
9703
9704 #include <stdlib.h>
9705 long int atol(const char *nptr);
9706
9707Description
9708
9709 The atol function converts the initial portion of the string
9710pointed to by nptr to long int representation. Except for the
9711behavior on error, it is equivalent to
9712
9713 strtol(nptr, (char **)NULL, 10)
9714
9715Returns
9716
9717 The atol function returns the converted value.
9718
9719Forward references: the strtol function ($4.10.1.5).
9720
9721
97224.10.1.4 The strtod function
9723
9724Synopsis
9725
9726 #include <stdlib.h>
9727 double strtod(const char *nptr, char **endptr);
9728
9729Description
9730
9731 The strtod function converts the initial portion of the string
9732pointed to by nptr to double representation. First it decomposes the
9733input string into three parts: an initial, possibly empty, sequence of
9734white-space characters (as specified by the isspace function), a
9735subject sequence resembling a floating-point constant; and a final
9736string of one or more unrecognized characters, including the
9737terminating null character of the input string. Then it attempts to
9738convert the subject sequence to a floating-point number, and returns
9739the result.
9740
9741 The expected form of the subject sequence is an optional plus or
9742minus sign, then a nonempty sequence of digits optionally containing a
9743decimal-point character, then an optional exponent part as defined in
9744$3.1.3.1, but no floating suffix. The subject sequence is defined as
9745the longest subsequence of the input string, starting with the first
9746non-white-space character, that is an initial subsequence of a
9747sequence of the expected form. The subject sequence contains no
9748characters if the input string is empty or consists entirely of white
9749space, or if the first non-white-space character is other than a sign,
9750a digit, or a decimal-point character.
9751
9752 If the subject sequence has the expected form, the sequence of
9753characters starting with the first digit or the decimal-point
9754character (whichever occurs first) is interpreted as a floating
9755constant according to the rules of $3.1.3.1, except that the
9756decimal-point character is used in place of a period, and that if
9757neither an exponent part nor a decimal-point character appears, a
9758decimal point is assumed to follow the last digit in the string. If
9759the subject sequence begins with a minus sign, the value resulting
9760from the conversion is negated. A pointer to the final string is
9761stored in the object pointed to by endptr , provided that endptr is
9762not a null pointer.
9763
9764 In other than the C locale, additional implementation-defined
9765subject sequence forms may be accepted.
9766
9767 If the subject sequence is empty or does not have the expected
9768form, no conversion is performed; the value of nptr is stored in the
9769object pointed to by endptr , provided that endptr is not a null
9770pointer.
9771
9772Returns
9773
9774 The strtod function returns the converted value, if any. If no
9775conversion could be performed, zero is returned. If the correct value
9776would cause overflow, plus or minus HUGE_VAL is returned (according to
9777the sign of the value), and the value of the macro ERANGE is stored in
9778errno . If the correct value would cause underflow, zero is returned
9779and the value of the macro ERANGE is stored in errno .
9780
9781
97824.10.1.5 The strtol function
9783
9784Synopsis
9785
9786 #include <stdlib.h>
9787 long int strtol(const char *nptr, char **endptr, int base);
9788
9789Description
9790
9791 The strtol function converts the initial portion of the string
9792pointed to by nptr to long int representation. First it decomposes
9793the input string into three parts: an initial, possibly empty,
9794sequence of white-space characters (as specified by the isspace
9795function), a subject sequence resembling an integer represented in
9796some radix determined by the value of base , and a final string of one
9797or more unrecognized characters, including the terminating null
9798character of the input string. Then it attempts to convert the
9799subject sequence to an integer, and returns the result.
9800
9801 If the value of base is zero, the expected form of the subject
9802sequence is that of an integer constant as described in $3.1.3.2,
9803optionally preceded by a plus or minus sign, but not including an
9804integer suffix. If the value of base is between 2 and 36, the
9805expected form of the subject sequence is a sequence of letters and
9806digits representing an integer with the radix specified by base ,
9807optionally preceded by a plus or minus sign, but not including an
9808integer suffix. The letters from a (or A ) through z (or Z ) are
9809ascribed the values 10 to 35; only letters whose ascribed values are
9810less than that of base are permitted. If the value of base is 16, the
9811characters 0x or 0X may optionally precede the sequence of letters and
9812digits, following the sign if present.
9813
9814 The subject sequence is defined as the longest subsequence of the
9815input string, starting with the first non-white-space character, that
9816is an initial subsequence of a sequence of the expected form. The
9817subject sequence contains no characters if the input string is empty
9818or consists entirely of white space, or if the first non-white-space
9819character is other than a sign or a permissible letter or digit.
9820
9821 If the subject sequence has the expected form and the value of base
9822is zero, the sequence of characters starting with the first digit is
9823interpreted as an integer constant according to the rules of $3.1.3.2.
9824If the subject sequence has the expected form and the value of base is
9825between 2 and 36, it is used as the base for conversion, ascribing to
9826each letter its value as given above. If the subject sequence begins
9827with a minus sign, the value resulting from the conversion is negated.
9828A pointer to the final string is stored in the object pointed to by
9829endptr , provided that endptr is not a null pointer.
9830
9831 In other than the C locale, additional implementation-defined
9832subject sequence forms may be accepted.
9833
9834 If the subject sequence is empty or does not have the expected
9835form, no conversion is performed; the value of nptr is stored in the
9836object pointed to by endptr , provided that endptr is not a null
9837pointer.
9838
9839Returns
9840
9841 The strtol function returns the converted value, if any. If no
9842conversion could be performed, zero is returned. If the correct value
9843would cause overflow, LONG_MAX or LONG_MIN is returned (according to
9844the sign of the value), and the value of the macro ERANGE is stored in
9845errno .
9846
9847
98484.10.1.6 The strtoul function
9849
9850Synopsis
9851
9852 #include <stdlib.h>
9853 unsigned long int strtoul(const char *nptr, char **endptr,
9854 int base);
9855
9856Description
9857
9858 The strtoul function converts the initial portion of the string
9859pointed to by nptr to unsigned long int representation. First it
9860decomposes the input string into three parts: an initial, possibly
9861empty, sequence of white-space characters (as specified by the isspace
9862function), a subject sequence resembling an unsigned integer
9863represented in some radix determined by the value of base , and a
9864final string of one or more unrecognized characters, including the
9865terminating null character of the input string. Then it attempts to
9866convert the subject sequence to an unsigned integer, and returns the
9867result.
9868
9869 If the value of base is zero, the expected form of the subject
9870sequence is that of an integer constant as described in $3.1.3.2,
9871optionally preceded by a plus or minus sign, but not including an
9872integer suffix. If the value of base is between 2 and 36, the
9873expected form of the subject sequence is a sequence of letters and
9874digits representing an integer with the radix specified by base ,
9875optionally preceded by a plus or minus sign, but not including an
9876integer suffix. The letters from a (or A ) through z (or Z ) are
9877ascribed the values 10 to 35; only letters whose ascribed values are
9878less than that of base are permitted. If the value of base is 16, the
9879characters 0x or 0X may optionally precede the sequence of letters and
9880digits, following the sign if present.
9881
9882 The subject sequence is defined as the longest subsequence of the
9883input string, starting with the first non-white-space character, that
9884is an initial subsequence of a sequence of the expected form. The
9885subject sequence contains no characters if the input string is empty
9886or consists entirely of white space, or if the first non-white-space
9887character is other than a sign or a permissible letter or digit.
9888
9889 If the subject sequence has the expected form and the value of base
9890is zero, the sequence of characters starting with the first digit is
9891interpreted as an integer constant according to the rules of $3.1.3.2.
9892If the subject sequence has the expected form and the value of base is
9893between 2 and 36, it is used as the base for conversion, ascribing to
9894each letter its value as given above. If the subject sequence begins
9895with a minus sign, the value resulting from the conversion is negated.
9896A pointer to the final string is stored in the object pointed to by
9897endptr , provided that endptr is not a null pointer.
9898
9899 In other than the C locale, additional implementation-defined
9900subject sequence forms may be accepted.
9901
9902 If the subject sequence is empty or does not have the expected
9903form, no conversion is performed; the value of nptr is stored in the
9904object pointed to by endptr , provided that endptr is not a null
9905pointer.
9906
9907Returns
9908
9909 The strtoul function returns the converted value, if any. If no
9910conversion could be performed, zero is returned. If the correct value
9911would cause overflow, ULONG_MAX is returned, and the value of the
9912macro ERANGE is stored in errno .
9913
9914
99154.10.2 Pseudo-random sequence generation functions
9916
99174.10.2.1 The rand function
9918
9919Synopsis
9920
9921 #include <stdlib.h>
9922 int rand(void);
9923
9924Description
9925
9926 The rand function computes a sequence of pseudo-random integers in
9927the range 0 to RAND_MAX .
9928
9929 The implementation shall behave as if no library function calls the
9930rand function.
9931
9932Returns
9933
9934 The rand function returns a pseudo-random integer.
9935
9936"Environmental limit"
9937
9938 The value of the RAND_MAX macro shall be at least 32767.
9939
9940
99414.10.2.2 The srand function
9942
9943Synopsis
9944
9945 #include <stdlib.h>
9946 void srand(unsigned int seed);
9947
9948Description
9949
9950 The srand function uses the argument as a seed for a new sequence
9951of pseudo-random numbers to be returned by subsequent calls to rand .
9952If srand is then called with the same seed value, the sequence of
9953pseudo-random numbers shall be repeated. If rand is called before any
9954calls to srand have been made, the same sequence shall be generated as
9955when srand is first called with a seed value of 1.
9956
9957 The implementation shall behave as if no library function calls the
9958srand function.
9959
9960Returns
9961
9962 The srand function returns no value.
9963
9964Example
9965
9966 The following functions define a portable implementation of rand
9967and srand. Specifying the semantics makes it possible to determine
9968reproducibly the behavior of programs that use pseudo-random
9969sequences. This facilitates the testing of portable applications in
9970different implementations.
9971
9972 static unsigned long int next = 1;
9973
9974 int rand(void) /* RAND_MAX assumed to be 32767 */
9975 {
9976 next = next * 1103515245 + 12345;
9977 return (unsigned int)(next/65536) % 32768;
9978 }
9979
9980 void srand(unsigned int seed)
9981 {
9982 next = seed;
9983 }
9984
9985
9986
99874.10.3 Memory management functions
9988
9989 The order and contiguity of storage allocated by successive calls
9990to the calloc , malloc , and realloc functions is unspecified. The
9991pointer returned if the allocation succeeds is suitably aligned so
9992that it may be assigned to a pointer to any type of object and then
9993used to access such an object in the space allocated (until the space
9994is explicitly freed or reallocated). Each such allocation shall yield
9995a pointer to an object disjoint from any other object. The pointer
9996returned points to the start (lowest byte address) of the allocated
9997space. If the space cannot be allocated, a null pointer is returned.
9998If the size of the space requested is zero, the behavior is
9999implementation-defined; the value returned shall be either a null
10000pointer or a unique pointer. The value of a pointer that refers to
10001freed space is indeterminate.
10002
10003
100044.10.3.1 The calloc function
10005
10006Synopsis
10007
10008 #include <stdlib.h>
10009 void *calloc(size_t nmemb, size_t size);
10010
10011Description
10012
10013 The calloc function allocates space for an array of nmemb objects,
10014each of whose size is size . The space is initialized to all bits
10015zero./114/
10016
10017Returns
10018
10019 The calloc function returns either a null pointer or a pointer to
10020the allocated space.
10021
10022
100234.10.3.2 The free function
10024
10025
10026Synopsis
10027
10028 #include <stdlib.h>
10029 void free(void *ptr);
10030
10031Description
10032
10033 The free function causes the space pointed to by ptr to be
10034deallocated, that is, made available for further allocation. If ptr
10035is a null pointer, no action occurs. Otherwise, if the argument does
10036not match a pointer earlier returned by the calloc , malloc , or
10037realloc function, or if the space has been deallocated by a call to
10038free or realloc , the behavior is undefined.
10039
10040Returns
10041
10042 The free function returns no value.
10043
10044
100454.10.3.3 The malloc function
10046
10047Synopsis
10048
10049 #include <stdlib.h>
10050 void *malloc(size_t size);
10051
10052Description
10053
10054 The malloc function allocates space for an object whose size is
10055specified by size and whose value is indeterminate.
10056
10057Returns
10058
10059 The malloc function returns either a null pointer or a pointer to
10060the allocated space.
10061
10062
100634.10.3.4 The realloc function
10064
10065Synopsis
10066
10067 #include <stdlib.h>
10068 void *realloc(void *ptr, size_t size);
10069
10070Description
10071
10072 The realloc function changes the size of the object pointed to by
10073ptr to the size specified by size . The contents of the object shall
10074be unchanged up to the lesser of the new and old sizes. If the new
10075size is larger, the value of the newly allocated portion of the object
10076is indeterminate. If ptr is a null pointer, the realloc function
10077behaves like the malloc function for the specified size. Otherwise,
10078if ptr does not match a pointer earlier returned by the calloc ,
10079malloc , or realloc function, or if the space has been deallocated by
10080a call to the free or realloc function, the behavior is undefined. If
10081the space cannot be allocated, the object pointed to by ptr is
10082unchanged. If size is zero and ptr is not a null pointer, the object
10083it points to is freed.
10084
10085Returns
10086
10087 The realloc function returns either a null pointer or a pointer to
10088the possibly moved allocated space.
10089
10090
100914.10.4 Communication with the environment
10092
100934.10.4.1 The abort function
10094
10095Synopsis
10096
10097 #include <stdlib.h>
10098 void abort(void);
10099
10100Description
10101
10102 The abort function causes abnormal program termination to occur,
10103unless the signal SIGABRT is being caught and the signal handler does
10104not return. Whether open output streams are flushed or open streams
10105closed or temporary files removed is implementation-defined. An
10106implementation-defined form of the status unsuccessful termination is
10107returned to the host environment by means of the function call
10108raise(SIGABRT) .
10109
10110Returns
10111
10112 The abort function cannot return to its caller.
10113
101144.10.4.2 The atexit function
10115
10116Synopsis
10117
10118 #include <stdlib.h>
10119 int atexit(void (*func)(void));
10120
10121Description
10122
10123 The atexit function registers the function pointed to by func , to
10124be called without arguments at normal program termination.
10125
10126"Implementation limits"
10127
10128 The implementation shall support the registration of at least 32
10129functions.
10130
10131Returns
10132
10133 The atexit function returns zero if the registration succeeds,
10134nonzero if it fails.
10135
10136Forward references: the exit function ($4.10.4.3).
10137
10138
101394.10.4.3 The exit function
10140
10141Synopsis
10142
10143 #include <stdlib.h>
10144 void exit(int status);
10145
10146Description
10147
10148 The exit function causes normal program termination to occur. If
10149more than one call to the exit function is executed by a program, the
10150behavior is undefined.
10151
10152 First, all functions registered by the atexit function are called,
10153in the reverse order of their registration./115/
10154
10155 Next, all open output streams are flushed, all open streams are
10156closed, and all files created by the tmpfile function are removed.
10157
10158 Finally, control is returned to the host environment. If the value
10159of status is zero or EXIT_SUCCESS , an implementation-defined form of
10160the status successful termination is returned. If the value of status
10161is EXIT_FAILURE , an implementation-defined form of the status
10162unsuccessful termination is returned. Otherwise the status returned
10163is implementation-defined.
10164
10165Returns
10166
10167 The exit function cannot return to its caller.
10168
10169
101704.10.4.4 The getenv function
10171
10172Synopsis
10173
10174 #include <stdlib.h>
10175 char *getenv(const char *name);
10176
10177Description
10178
10179 The getenv function searches an environment list, provided by the
10180host environment, for a string that matches the string pointed to by
10181name . The set of environment names and the method for altering the
10182environment list are implementation-defined.
10183
10184 The implementation shall behave as if no library function calls the
10185getenv function.
10186
10187Returns
10188
10189 The getenv function returns a pointer to a string associated with
10190the matched list member. The array pointed to shall not be modified
10191by the program, but may be overwritten by a subsequent call to the
10192getenv function. If the specified name cannot be found, a null
10193pointer is returned.
10194
10195
101964.10.4.5 The system function
10197
10198Synopsis
10199
10200 #include <stdlib.h>
10201 int system(const char *string);
10202
10203Description
10204
10205 The system function passes the string pointed to by string to the
10206host environment to be executed by a command processor in an
10207implementation-defined manner. A null pointer may be used for string
10208to inquire whether a command processor exists.
10209
10210Returns
10211
10212 If the argument is a null pointer, the system function returns
10213nonzero only if a command processor is available. If the argument is
10214not a null pointer, the system function returns an
10215implementation-defined value.
10216
10217
102184.10.5 Searching and sorting utilities
10219
102204.10.5.1 The bsearch function
10221
10222Synopsis
10223
10224 #include <stdlib.h>
10225 void *bsearch(const void *key, const void *base,
10226 size_t nmemb, size_t size,
10227 int (*compar)(const void *, const void *));
10228
10229Description
10230
10231 The bsearch function searches an array of nmemb objects, the
10232initial member of which is pointed to by base , for a member that
10233matches the object pointed to by key . The size of each member of the
10234array is specified by size .
10235
10236 The contents of the array shall be in ascending sorted order
10237according to a comparison function pointed to by compar ,/116/ induces
10238which is called with two arguments that point to the key object and to
10239an array member, in that order. The function shall return an integer
10240less than, equal to, or greater than zero if the key object is
10241considered, respectively, to be less than, to match, or to be greater
10242than the array member.
10243
10244Returns
10245
10246 The bsearch function returns a pointer to a matching member of the
10247array, or a null pointer if no match is found. If two members compare
10248as equal, which member is matched is unspecified.
10249
10250
102514.10.5.2 The qsort function
10252
10253Synopsis
10254
10255 #include <stdlib.h>
10256 void qsort(void *base, size_t nmemb, size_t size,
10257 int (*compar)(const void *, const void *));
10258
10259Description
10260
10261 The qsort function sorts an array of nmemb objects, the initial
10262member of which is pointed to by base . The size of each object is
10263specified by size .
10264
10265 The contents of the array are sorted in ascending order according
10266to a comparison function pointed to by compar , which is called with
10267two arguments that point to the objects being compared. The function
10268shall return an integer less than, equal to, or greater than zero if
10269the first argument is considered to be respectively less than, equal
10270to, or greater than the second.
10271
10272 If two members compare as equal, their order in the sorted array is
10273unspecified.
10274
10275Returns
10276
10277 The qsort function returns no value.
10278
10279
102804.10.6 Integer arithmetic functions
10281
102824.10.6.1 The abs function
10283
10284Synopsis
10285
10286 #include <stdlib.h>
10287 int abs(int j);
10288
10289Description
10290
10291 The abs function computes the absolute value of an integer j . If
10292the result cannot be represented, the behavior is undefined./117/
10293
10294Returns
10295
10296 The abs function returns the absolute value.
10297
10298
102994.10.6.2 The div function
10300
10301Synopsis
10302
10303 #include <stdlib.h>
10304 div_t div(int numer, int denom);
10305
10306Description
10307
10308 The div function computes the quotient and remainder of the
10309division of the numerator numer by the denominator denom . If the
10310division is inexact, the sign of the resulting quotient is that of the
10311algebraic quotient, and the magnitude of the resulting quotient is the
10312largest integer less than the magnitude of the algebraic quotient. If
10313the result cannot be represented, the behavior is undefined;
10314otherwise, quot * denom + rem shall equal numer .
10315
10316Returns
10317
10318 The div function returns a structure of type div_t , comprising
10319both the quotient and the remainder. The structure shall contain the
10320following members, in either order.
10321
10322 int quot; /* quotient */
10323 int rem; /* remainder */
10324
10325
103264.10.6.3 The labs function
10327
10328Synopsis
10329
10330 #include <stdlib.h>
10331 long int labs(long int j);
10332
10333Description
10334
10335 The labs function is similar to the abs function, except that the
10336argument and the returned value each have type long int .
10337
10338
103394.10.6.4 The ldiv function
10340
10341Synopsis
10342
10343 #include <stdlib.h>
10344 ldiv_t ldiv(long int numer, long int denom);
10345
10346Description
10347
10348 The ldiv function is similar to the div function, except that the
10349arguments and the members of the returned structure (which has type
10350ldiv_t ) all have type long int .
10351
10352
103534.10.7 Multibyte character functions
10354
10355 The behavior of the multibyte character functions is affected by
10356the LC_CTYPE category of the current locale. For a state-dependent
10357encoding, each function is placed into its initial state by a call for
10358which its character pointer argument, s , is a null pointer.
10359Subsequent calls with s as other than a null pointer cause the
10360internal state of the function to be altered as necessary. A call
10361with s as a null pointer causes these functions to return a nonzero
10362value if encodings have state dependency, and zero otherwise. After
10363the LC_CTYPE category is changed, the shift state of these functions
10364is indeterminate.
10365
10366
103674.10.7.1 The mblen function
10368
10369Synopsis
10370
10371 #include <stdlib.h>
10372 int mblen(const char *s, size_t n);
10373
10374Description
10375
10376 If s is not a null pointer, the mblen function determines the
10377number of bytes comprising the multibyte character pointed to by s .
10378Except that the shift state of the mbtowc function is not affected, it
10379is equivalent to
10380
10381 mbtowc((wchar_t *)0, s, n);
10382
10383
10384 The implementation shall behave as if no library function calls the
10385mblen function.
10386
10387Returns
10388
10389 If s is a null pointer, the mblen function returns a nonzero or
10390zero value, if multibyte character encodings, respectively, do or do
10391not have state-dependent encodings. If s is not a null pointer, the
10392mblen function either returns 0 (if s points to the null character),
10393or returns the number of bytes that comprise the multibyte character
10394(if the next n or fewer bytes form a valid multibyte character), or
10395returns -1 (if they do not form a valid multibyte character).
10396
10397Forward references: the mbtowc function ($4.10.7.2).
10398
10399
104004.10.7.2 The mbtowc function
10401
10402Synopsis
10403
10404 #include <stdlib.h>
10405 int mbtowc(wchar_t *pwc, const char *s, size_t n);
10406
10407Description
10408
10409 If s is not a null pointer, the mbtowc function determines the
10410number of bytes that comprise the multibyte character pointed to by s.
10411It then determines the code for value of type wchar_t that
10412corresponds to that multibyte character. (The value of the code
10413corresponding to the null character is zero.) If the multibyte
10414character is valid and pwc is not a null pointer, the mbtowc function
10415stores the code in the object pointed to by pwc . At most n bytes of
10416the array pointed to by s will be examined.
10417
10418 The implementation shall behave as if no library function calls the
10419mbtowc function.
10420
10421Returns
10422
10423If s is a null pointer, the mbtowc function returns a nonzero or zero
10424value, if multibyte character encodings, respectively, do or do not
10425have state-dependent encodings. If s is not a null pointer, the
10426mbtowc function either returns 0 (if s points to the null character),
10427or returns the number of bytes that comprise the converted multibyte
10428character (if the next n or fewer bytes form a valid multibyte
10429character), or returns -1 (if they do not form a valid multibyte
10430character).
10431
10432 In no case will the value returned be greater than n or the value
10433of the MB_CUR_MAX macro.
10434
10435
104364.10.7.3 The wctomb function
10437
10438Synopsis
10439
10440 #include <stdlib.h>
10441 int wctomb(char *s, wchar_t wchar);
10442
10443Description
10444
10445 The wctomb function determines the number of bytes needed to
10446represent the multibyte character corresponding to the code whose
10447value is wchar (including any change in shift state). It stores the
10448multibyte character representation in the array object pointed to by s
10449(if s is not a null pointer). At most MB_CUR_MAX characters are
10450stored. If the value of wchar is zero, the wctomb function is left in
10451the initial shift state.
10452
10453 The implementation shall behave as if no library function calls the
10454wctomb function.
10455
10456Returns
10457
10458 If s is a null pointer, the wctomb function returns a nonzero or
10459zero value, if multibyte character encodings, respectively, do or do
10460not have state-dependent encodings. If s is not a null pointer, the
10461wctomb function returns -1 if the value of wchar does not correspond
10462to a valid multibyte character, or returns the number of bytes that
10463comprise the multibyte character corresponding to the value of wchar .
10464
10465 In no case will the value returned be greater than the value of the
10466MB_CUR_MAX macro.
10467
10468
104694.10.8 Multibyte string functions
10470
10471 The behavior of the multibyte string functions is affected by the
10472LC_CTYPE category of the current locale.
10473
10474
104754.10.8.1 The mbstowcs function
10476
10477Synopsis
10478
10479 #include <stdlib.h>
10480 size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);
10481
10482Description
10483
10484 The mbstowcs function converts a sequence of multibyte characters
10485that begins in the initial shift state from the array pointed to by s
10486into a sequence of corresponding codes and stores not more than n
10487codes into the array pointed to by pwcs . No multibyte characters
10488that follow a null character (which is converted into a code with
10489value zero) will be examined or converted. Each multibyte character
10490is converted as if by a call to the mbtowc function, except that the
10491shift state of the mbtowc function is not affected.
10492
10493 No more than n elements will be modified in the array pointed to by
10494pwcs . If copying takes place between objects that overlap, the
10495behavior is undefined.
10496
10497Returns
10498
10499 If an invalid multibyte character is encountered, the mbstowcs
10500function returns (size_t)-1 . Otherwise, the mbstowcs function
10501returns the number of array elements modified, not including a
10502terminating zero code, if any.rN
10503
10504
105054.10.8.2 The wcstombs function
10506
10507Synopsis
10508
10509 #include <stdlib.h>
10510 size_t wcstombs(char *s, const wchar_t *pwcs, size_t n);
10511
10512Description
10513
10514 The wcstombs function converts a sequence of codes that correspond
10515to multibyte characters from the array pointed to by pwcs into a
10516sequence of multibyte characters that begins in the initial shift
10517state and stores these multibyte characters into the array pointed to
10518by s , stopping if a multibyte character would exceed the limit of n
10519total bytes or if a null character is stored. Each code is converted
10520as if by a call to the wctomb function, except that the shift state of
10521the wctomb function is not affected.
10522
10523 No more than n bytes will be modified in the array pointed to by s
10524. If copying takes place between objects that overlap, the behavior
10525is undefined.
10526
10527Returns
10528
10529 If a code is encountered that does not correspond to a valid
10530multibyte character, the wcstombs function returns (size_t)-1 .
10531Otherwise, the wcstombs function returns the number of bytes modified,
10532not including a terminating null character, if any.rN
10533
10534
105354.11 STRING HANDLING <string.h>
10536
105374.11.1 String function conventions
10538
10539 The header <string.h> declares one type and several functions, and
10540defines one macro useful for manipulating arrays of character type and
10541other objects treated as arrays of character type./119/ The type is
10542size_t and the macro is NULL (both described in $4.1.5). Various
10543methods are used for determining the lengths of the arrays, but in all
10544cases a char * or void * argument points to the initial (lowest
10545addressed) character of the array. If an array is accessed beyond the
10546end of an object, the behavior is undefined.
10547
10548
105494.11.2 Copying functions
10550
105514.11.2.1 The memcpy function
10552
10553Synopsis
10554
10555 #include <string.h>
10556 void *memcpy(void *s1, const void *s2, size_t n);
10557
10558Description
10559
10560 The memcpy function copies n characters from the object pointed to
10561by s2 into the object pointed to by s1 . If copying takes place
10562between objects that overlap, the behavior is undefined.
10563
10564Returns
10565
10566 The memcpy function returns the value of s1 .
10567
10568
105694.11.2.2 The memmove function
10570
10571Synopsis
10572
10573 #include <string.h>
10574 void *memmove(void *s1, const void *s2, size_t n);
10575
10576Description
10577
10578 The memmove function copies n characters from the object pointed to
10579by s2 into the object pointed to by s1 . Copying takes place as if
10580the n characters from the object pointed to by s2 are first copied
10581into a temporary array of n characters that does not overlap the
10582objects pointed to by s1 and s2 , and then the n characters from the
10583temporary array are copied into the object pointed to by s1 .
10584
10585Returns
10586
10587 The memmove function returns the value of s1 .
10588
10589
105904.11.2.3 The strcpy function
10591
10592Synopsis
10593
10594 #include <string.h>
10595 char *strcpy(char *s1, const char *s2);
10596
10597Description
10598
10599 The strcpy function copies the string pointed to by s2 (including
10600the terminating null character) into the array pointed to by s1 . If
10601copying takes place between objects that overlap, the behavior is
10602undefined.
10603
10604Returns
10605
10606 The strcpy function returns the value of s1 .
10607
10608
106094.11.2.4 The strncpy function
10610
10611Synopsis
10612
10613 #include <string.h>
10614 char *strncpy(char *s1, const char *s2, size_t n);
10615
10616Description
10617
10618 The strncpy function copies not more than n characters (characters
10619that follow a null character are not copied) from the array pointed to
10620by s2 to the array pointed to by s1 ./120/ If copying takes place
10621between objects that overlap, the behavior is undefined.
10622
10623 If the array pointed to by s2 is a string that is shorter than n
10624characters, null characters are appended to the copy in the array
10625pointed to by s1 , until n characters in all have been written.
10626
10627Returns
10628
10629 The strncpy function returns the value of s1 .
10630
10631
106324.11.3 Concatenation functions
10633
106344.11.3.1 The strcat function
10635
10636Synopsis
10637
10638 #include <string.h>
10639 char *strcat(char *s1, const char *s2);
10640
10641Description
10642
10643 The strcat function appends a copy of the string pointed to by s2
10644(including the terminating null character) to the end of the string
10645pointed to by s1 . The initial character of s2 overwrites the null
10646character at the end of s1 . If copying takes place between objects
10647that overlap, the behavior is undefined.
10648
10649Returns
10650
10651 The strcat function returns the value of s1 .
10652
10653
106544.11.3.2 The strncat function
10655
10656Synopsis
10657
10658 #include <string.h>
10659 char *strncat(char *s1, const char *s2, size_t n);
10660
10661Description
10662
10663 The strncat function appends not more than n characters (a null
10664character and characters that follow it are not appended) from the
10665array pointed to by s2 to the end of the string pointed to by s1 .
10666The initial character of s2 overwrites the null character at the end
10667of s1 . A terminating null character is always appended to the
10668result./121/ If copying takes place between objects that overlap, the
10669behavior is undefined.
10670
10671Returns
10672
10673 The strncat function returns the value of s1 .
10674
10675Forward references: the strlen function ($4.11.6.3).
10676
10677
106784.11.4 Comparison functions
10679
10680 The sign of a nonzero value returned by the comparison functions is
10681determined by the sign of the difference between the values of the
10682first pair of characters (both interpreted as unsigned char ) that
10683differ in the objects being compared.
10684
10685
106864.11.4.1 The memcmp function
10687
10688Synopsis
10689
10690 #include <string.h>
10691 int memcmp(const void *s1, const void *s2, size_t n);
10692
10693Description
10694
10695 The memcmp function compares the first n characters of the object
10696pointed to by s1 to the first n characters of the object pointed to by
10697s2 ./122/
10698
10699Returns
10700
10701 The memcmp function returns an integer greater than, equal to, or
10702less than zero, according as the object pointed to by s1 is greater
10703than, equal to, or less than the object pointed to by s2 .
10704
10705
107064.11.4.2 The strcmp function
10707
10708Synopsis
10709
10710 #include <string.h>
10711 int strcmp(const char *s1, const char *s2);
10712
10713Description
10714
10715 The strcmp function compares the string pointed to by s1 to the
10716string pointed to by s2 .
10717
10718Returns
10719
10720 The strcmp function returns an integer greater than, equal to, or
10721less than zero, according as the string pointed to by s1 is greater
10722than, equal to, or less than the string pointed to by s2 .
10723
10724
107254.11.4.3 The strcoll function
10726
10727Synopsis
10728
10729 #include <string.h>
10730 int strcoll(const char *s1, const char *s2);
10731
10732Description
10733
10734The strcoll function compares the string pointed to by s1 to the
10735string pointed to by s2 , both interpreted as appropriate to the
10736LC_COLLATE category of the current locale.
10737
10738Returns
10739
10740 The strcoll function returns an integer greater than, equal to, or
10741less than zero, according as the string pointed to by s1 is greater
10742than, equal to, or less than the string pointed to by s2 when both are
10743interpreted as appropriate to the current locale.
10744
10745
107464.11.4.4 The strncmp function
10747
10748Synopsis
10749
10750 #include <string.h>
10751 int strncmp(const char *s1, const char *s2, size_t n);
10752
10753Description
10754
10755 The strncmp function compares not more than n characters
10756(characters that follow a null character are not compared) from the
10757array pointed to by s1 to the array pointed to by s2 .
10758
10759Returns
10760
10761 The strncmp function returns an integer greater than, equal to, or
10762less than zero, according as the possibly null-terminated array
10763pointed to by s1 is greater than, equal to, or less than the possibly
10764null-terminated array pointed to by s2 .
10765
10766
107674.11.4.5 The strxfrm function
10768
10769Synopsis
10770
10771 #include <string.h>
10772 size_t strxfrm(char *s1, const char *s2, size_t n);
10773
10774Description
10775
10776 The strxfrm function transforms the string pointed to by s2 and
10777places the resulting string into the array pointed to by s1 . The
10778transformation is such that if the strcmp function is applied to two
10779transformed strings, it returns a value greater than, equal to, or
10780less than zero, corresponding to the result of the strcoll function
10781applied to the same two original strings. No more than n characters
10782are placed into the resulting array pointed to by s1 , including the
10783terminating null character. If n is zero, s1 is permitted to be a
10784null pointer. If copying takes place between objects that overlap,
10785the behavior is undefined.
10786
10787Returns
10788
10789 The strxfrm function returns the length of the transformed string
10790(not including the terminating null character). If the value returned
10791is n or more, the contents of the array pointed to by s1 are
10792indeterminate.
10793
10794Example
10795
10796 The value of the following expression is the size of the array
10797needed to hold the transformation of the string pointed to by s .
10798
10799 1 + strxfrm(NULL, s, 0)
10800
10801
108024.11.5 Search functions
10803
108044.11.5.1 The memchr function
10805
10806Synopsis
10807
10808 #include <string.h>
10809 void *memchr(const void *s, int c, size_t n);
10810
10811Description
10812
10813 The memchr function locates the first occurrence of c (converted to
10814an unsigned char ) in the initial n characters (each interpreted as
10815unsigned char ) of the object pointed to by s .
10816
10817Returns
10818
10819 The memchr function returns a pointer to the located character, or
10820a null pointer if the character does not occur in the object.
10821
10822
108234.11.5.2 The strchr function
10824
10825Synopsis
10826
10827 #include <string.h>
10828 char *strchr(const char *s, int c);
10829
10830Description
10831
10832 The strchr function locates the first occurrence of c (converted to
10833a char ) in the string pointed to by s . The terminating null
10834character is considered to be part of the string.
10835
10836Returns
10837
10838 The strchr function returns a pointer to the located character, or
10839a null pointer if the character does not occur in the string.
10840
10841
108424.11.5.3 The strcspn function
10843
10844Synopsis
10845
10846 #include <string.h>
10847 size_t strcspn(const char *s1, const char *s2);
10848
10849Description
10850
10851 The strcspn function computes the length of the maximum initial
10852segment of the string pointed to by s1 which consists entirely of
10853characters not from the string pointed to by s2 .
10854
10855Returns
10856
10857 The strcspn function returns the length of the segment.
10858
10859
108604.11.5.4 The strpbrk function
10861
10862Synopsis
10863
10864 #include <string.h>
10865 char *strpbrk(const char *s1, const char *s2);
10866
10867Description
10868
10869 The strpbrk function locates the first occurrence in the string
10870pointed to by s1 of any character from the string pointed to by s2 .
10871
10872Returns
10873
10874 The strpbrk function returns a pointer to the character, or a null
10875pointer if no character from s2 occurs in s1 .
10876
10877
108784.11.5.5 The strrchr function
10879
10880Synopsis
10881
10882 #include <string.h>
10883 char *strrchr(const char *s, int c);
10884
10885Description
10886
10887 The strrchr function locates the last occurrence of c (converted to
10888a char ) in the string pointed to by s . The terminating null
10889character is considered to be part of the string.
10890
10891Returns
10892
10893 The strrchr function returns a pointer to the character, or a null
10894pointer if c does not occur in the string.
10895
10896
108974.11.5.6 The strspn function
10898
10899Synopsis
10900
10901 #include <string.h>
10902 size_t strspn(const char *s1, const char *s2);
10903
10904Description
10905
10906 The strspn function computes the length of the maximum initial
10907segment of the string pointed to by s1 which consists entirely of
10908characters from the string pointed to by s2 .
10909
10910Returns
10911
10912 The strspn function returns the length of the segment.
10913
10914
109154.11.5.7 The strstr function
10916
10917Synopsis
10918
10919 #include <string.h>
10920 char *strstr(const char *s1, const char *s2);
10921
10922Description
10923
10924 The strstr function locates the first occurrence in the string
10925pointed to by s1 of the sequence of characters (excluding the
10926terminating null character) in the string pointed to by s2
10927
10928Returns
10929
10930 The strstr function returns a pointer to the located string, or a
10931null pointer if the string is not found. If s2 points to a string
10932with zero length, the function returns s1 .
10933
10934
109354.11.5.8 The strtok function
10936
10937Synopsis
10938
10939 #include <string.h>
10940 char *strtok(char *s1, const char *s2);
10941
10942Description
10943
10944 A sequence of calls to the strtok function breaks the string
10945pointed to by s1 into a sequence of tokens, each of which is delimited
10946by a character from the string pointed to by s2 . The first call in
10947the sequence has s1 as its first argument, and is followed by calls
10948with a null pointer as their first argument. The separator string
10949pointed to by s2 may be different from call to call.
10950
10951 The first call in the sequence searches the string pointed to by s1
10952for the first character that is not contained in the current separator
10953string pointed to by s2 . If no such character is found, then there
10954are no tokens in the string pointed to by s1 and the strtok function
10955returns a null pointer. If such a character is found, it is the start
10956of the first token.
10957
10958 The strtok function then searches from there for a character that
10959is contained in the current separator string. If no such character is
10960found, the current token extends to the end of the string pointed to
10961by s1 , and subsequent searches for a token will return a null
10962pointer. If such a character is found, it is overwritten by a null
10963character, which terminates the current token. The strtok function
10964saves a pointer to the following character, from which the next search
10965for a token will start.
10966
10967 Each subsequent call, with a null pointer as the value of the first
10968argument, starts searching from the saved pointer and behaves as
10969described above.
10970
10971 The implementation shall behave as if no library function calls the
10972strtok function.
10973
10974Returns
10975
10976 The strtok function returns a pointer to the first character of a
10977token, or a null pointer if there is no token.
10978
10979Example
10980
10981 #include <string.h>
10982 static char str[] = "?a???b,,,#c";
10983 char *t;
10984
10985 t = strtok(str, "?"); /* t points to the token "a" */
10986 t = strtok(NULL, ","); /* t points to the token "??b" */
10987 t = strtok(NULL, "#,"); /* t points to the token "c" */
10988 t = strtok(NULL, "?"); /* t is a null pointer */
10989
10990
109914.11.6 Miscellaneous functions
10992
109934.11.6.1 The memset function
10994
10995Synopsis
10996
10997 #include <string.h>
10998 void *memset(void *s, int c, size_t n);
10999
11000Description
11001
11002 The memset function copies the value of c (converted to an unsigned
11003char ) into each of the first n characters of the object pointed to by
11004s .
11005
11006Returns
11007
11008 The memset function returns the value of s .
11009
11010
110114.11.6.2 The strerror function
11012
11013Synopsis
11014
11015 #include <string.h>
11016 char *strerror(int errnum);
11017
11018Description
11019
11020 The strerror function maps the error number in errnum to an error
11021message string.
11022
11023 The implementation shall behave as if no library function calls the
11024strerror function.
11025
11026Returns
11027
11028 The strerror function returns a pointer to the string, the contents
11029of which are implementation-defined. The array pointed to shall not
11030be modified by the program, but may be overwritten by a subsequent
11031call to the strerror function.
11032
11033
110344.11.6.3 The strlen function
11035
11036Synopsis
11037
11038 #include <string.h>
11039 size_t strlen(const char *s);
11040
11041Description
11042
11043 The strlen function computes the length of the string pointed to by s .
11044
11045Returns
11046
11047 The strlen function returns the number of characters that precede
11048the terminating null character.
11049
11050
110514.12 DATE AND TIME <time.h>
11052
110534.12.1 Components of time
11054
11055 The header <time.h> defines two macros, and declares four types and
11056several functions for manipulating time. Many functions deal with a
11057calendar time that represents the current date (according to the
11058Gregorian calendar) and time. Some functions deal with local time,
11059which is the calendar time expressed for some specific time zone, and
11060with Daylight Saving Time, which is a temporary change in the
11061algorithm for determining local time. The local time zone and
11062Daylight Saving Time are implementation-defined.
11063
11064 The macros defined are NULL (described in $4.1.5); and
11065
11066 CLK_TCK
11067
11068which is the number per second of the value returned by the clock function.
11069
11070 The types declared are size_t (described in $4.1.5);
11071
11072 clock_t
11073
11074and
11075
11076 time_t
11077
11078which are arithmetic types capable of representing times; and
11079
11080 struct tm
11081
11082which holds the components of a calendar time, called the broken-down
11083time. The structure shall contain at least the following members, in
11084any order. The semantics of the members and their normal ranges are
11085expressed in the comments./123/
11086
11087 int tm_sec; /* seconds after the minute --- [0, 60] */
11088 int tm_min; /* minutes after the hour --- [0, 59] */
11089 int tm_hour; /* hours since midnight --- [0, 23] */
11090 int tm_mday; /* day of the month --- [1, 31] */
11091 int tm_mon; /* months since January --- [0, 11] */
11092 int tm_year; /* years since 1900 */
11093 int tm_wday; /* days since Sunday --- [0, 6] */
11094 int tm_yday; /* days since January 1 --- [0, 365] */
11095 int tm_isdst; /* Daylight Saving Time flag */
11096
11097The value of tm_isdst is positive if Daylight Saving Time is in
11098effect, zero if Daylight Saving Time is not in effect, and negative if
11099the information is not available.
11100
11101
111024.12.2 Time manipulation functions
11103
111044.12.2.1 The clock function
11105
11106Synopsis
11107
11108 #include <time.h>
11109 clock_t clock(void);
11110
11111Description
11112
11113 The clock function determines the processor time used.
11114
11115Returns
11116
11117 The clock function returns the implementation's best approximation
11118to the processor time used by the program since the beginning of an
11119implementation-defined era related only to the program invocation. To
11120determine the time in seconds, the value returned by the clock
11121function should be divided by the value of the macro CLK_TCK . If the
11122processor time used is not available or its value cannot be
11123represented, the function returns the value (clock_t)-1 .
11124
11125
111264.12.2.2 The difftime function
11127
11128Synopsis
11129
11130 #include <time.h>
11131 double difftime(time_t time1, time_t time0);
11132
11133Description
11134
11135 The difftime function computes the difference between two calendar
11136times: time1 - time0 .
11137
11138Returns
11139
11140 The difftime function returns the difference expressed in seconds
11141as a double .
11142
11143
111444.12.2.3 The mktime function
11145
11146Synopsis
11147
11148 #include <time.h>
11149 time_t mktime(struct tm *timeptr);
11150
11151Description
11152
11153 The mktime function converts the broken-down time, expressed as
11154local time, in the structure pointed to by timeptr into a calendar
11155time value with the same encoding as that of the values returned by
11156the time function. The original values of the tm_wday and tm_yday
11157components of the structure are ignored, and the original values of
11158the other components are not restricted to the ranges indicated
11159above./124/ On successful completion, the values of the tm_wday and
11160tm_yday components of the structure are set appropriately, and the
11161other components are set to represent the specified calendar time, but
11162with their values forced to the ranges indicated above; the final
11163value of tm_mday is not set until tm_mon and tm_year are determined.
11164
11165Returns
11166
11167 The mktime function returns the specified calendar time encoded as
11168a value of type time_t . If the calendar time cannot be represented,
11169the function returns the value (time_t)-1 .
11170
11171Example
11172
11173 What day of the week is July 4, 2001?
11174
11175
11176 #include <stdio.h>
11177 #include <time.h>
11178 static const char *const wday[] = {
11179 "Sunday", "Monday", "Tuesday", "Wednesday",
11180 "Thursday", "Friday", "Saturday", "-unknown-"
11181 };
11182 struct tm time_str;
11183
11184
11185
11186 time_str.tm_year = 2001 - 1900;
11187 time_str.tm_mon = 7 - 1;
11188 time_str.tm_mday = 4;
11189 time_str.tm_hour = 0;
11190 time_str.tm_min = 0;
11191 time_str.tm_sec = 1;
11192 time_str.tm_isdst = -1;
11193 if (mktime(&time_str) == -1)
11194 time_str.tm_wday = 7;
11195 printf("%s\n", wday[time_str.tm_wday]);
11196
11197
111984.12.2.4 The time function
11199
11200Synopsis
11201
11202 #include <time.h>
11203 time_t time(time_t *timer);
11204
11205Description
11206
11207 The time function determines the current calendar time. The
11208encoding of the value is unspecified.
11209
11210Returns
11211
11212 The time function returns the implementation's best approximation
11213to the current calendar time. The value (time_t)-1 is returned if the
11214calendar time is not available. If timer is not a null pointer, the
11215return value is also assigned to the object it points to.
11216
11217
112184.12.3 Time conversion functions
11219
11220 Except for the strftime function, these functions return values in
11221one of two static objects: a broken-down time structure and an array
11222of char . Execution of any of the functions may overwrite the
11223information returned in either of these objects by any of the other
11224functions. The implementation shall behave as if no other library
11225functions call these functions.
11226
11227
112284.12.3.1 The asctime function
11229
11230Synopsis
11231
11232 #include <time.h>
11233 char *asctime(const struct tm *timeptr);
11234
11235Description
11236
11237 The asctime function converts the broken-down time in the structure
11238pointed to by timeptr into a string in the form
11239
11240 Sun Sep 16 01:03:52 1973\n\0
11241
11242using the equivalent of the following algorithm.
11243
11244char *asctime(const struct tm *timeptr)
11245{
11246 static const char wday_name[7][3] = {
11247 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
11248 };
11249 static const char mon_name[12][3] = {
11250 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
11251 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
11252 };
11253 static char result[26];
11254
11255 sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
11256 wday_name[timeptr->tm_wday],
11257 mon_name[timeptr->tm_mon],
11258 timeptr->tm_mday, timeptr->tm_hour,
11259 timeptr->tm_min, timeptr->tm_sec,
11260 1900 + timeptr->tm_year);
11261 return result;
11262}
11263
11264Returns
11265
11266 The asctime function returns a pointer to the string.
11267
11268
112694.12.3.2 The ctime function
11270
11271Synopsis
11272
11273 #include <time.h>
11274 char *ctime(const time_t *timer);
11275
11276Description
11277
11278 The ctime function converts the calendar time pointed to by timer to local time in the form of a string. It is equivalent to
11279
11280 asctime(localtime(timer))
11281
11282Returns
11283
11284 The ctime function returns the pointer returned by the asctime
11285function with that broken-down time as argument.
11286
11287Forward references: the localtime function ($4.12.3.4).
11288
11289
112904.12.3.3 The gmtime function
11291
11292Synopsis
11293
11294 #include <time.h>
11295 struct tm *gmtime(const time_t *timer);
11296
11297Description
11298
11299 The gmtime function converts the calendar time pointed to by timer
11300into a broken-down time, expressed as Coordinated Universal Time
11301(UTC).
11302
11303Returns
11304
11305 The gmtime function returns a pointer to that object, or a null
11306pointer if UTC is not available.
11307
11308
113094.12.3.4 The localtime function
11310
11311Synopsis
11312
11313 #include <time.h>
11314 struct tm *localtime(const time_t *timer);
11315
11316Description
11317
11318 The localtime function converts the calendar time pointed to by
11319timer into a broken-down time, expressed as local time.
11320
11321Returns
11322
11323 The localtime function returns a pointer to that object.
11324
11325
113264.12.3.5 The strftime function
11327
11328Synopsis
11329
11330 #include <time.h>
11331 size_t strftime(char *s, size_t maxsize,
11332 const char *format, const struct tm *timeptr);
11333
11334Description
11335
11336 The strftime function places characters into the array pointed to
11337by s as controlled by the string pointed to by format . The format
11338shall be a multibyte character sequence, beginning and ending in its
11339initial shift state. The format string consists of zero or more
11340conversion specifications and ordinary multibyte characters. A
11341conversion specification consists of a % character followed by a
11342character that determines the conversion specification's behavior.
11343All ordinary multibyte characters (including the terminating null
11344character) are copied unchanged into the array. If copying takes
11345place between objects that overlap, the behavior is undefined. No
11346more than maxsize characters are placed into the array. Each
11347conversion specification is replaced by appropriate characters as
11348described in the following list. The appropriate characters are
11349determined by the program's locale and by the values contained in the
11350structure pointed to by timeptr .
11351
11352"%a" is replaced by the locale's abbreviated weekday name.
11353"%A" is replaced by the locale's full weekday name.
11354"%b" is replaced by the locale's abbreviated month name.
11355"%B" is replaced by the locale's full month name.
11356"%c" is replaced by the locale's appropriate date and time representation.
11357"%d" is replaced by the day of the month as a decimal number (01-31).
11358"%H" is replaced by the hour (24-hour clock) as a decimal number (00-23).
11359"%I" is replaced by the hour (12-hour clock) as a decimal number (01-12).
11360"%j" is replaced by the day of the year as a decimal number (001-366 ).
11361"%m" is replaced by the month as a decimal number (01-12).
11362"%M" is replaced by the minute as a decimal number (00-59).
11363"%p" is replaced by the locale's equivalent of either AM or PM .
11364"%S" is replaced by the second as a decimal number (00-60).
11365"%U" is replaced by the week number of the year (ithe first Sunday as the
11366 first day of week 1) as a decimal number (00-53).
11367"%w" is replaced by the weekday as a decimal number (0-6), where Sunday is
11368 0.
11369"%W" is replaced by the week number of the year (the first Monday as the
11370 first day of week 1) as a decimal number (00-53).
11371"%x" is replaced by the locale's appropriate date representation.
11372"%X" is replaced by the locale's appropriate time representation.
11373"%y" is replaced by the year without century as a decimal number (00-99).
11374"%Y" is replaced by the year with century as a decimal number.
11375"%Z" is replaced by the time zone name, or by no characters if no time
11376 zone is determinable.
11377"%%" is replaced by %.
11378
11379 If a conversion specification is not one of the above, the behavior
11380is undefined.
11381
11382Returns
11383
11384 If the total number of resulting characters including the
11385terminating null character is not more than maxsize , the strftime
11386function returns the number of characters placed into the array
11387pointed to by s not including the terminating null character.
11388Otherwise, zero is returned and the contents of the array are
11389indeterminate.
11390
11391
113924.13 FUTURE LIBRARY DIRECTIONS
11393
11394 The following names are grouped under individual headers for
11395convenience. All external names described below are reserved no
11396matter what headers are included by the program.
11397
11398
113994.13.1 Errors <errno.h>
11400
11401 Macros that begin with E and a digit or E and an upper-case letter
11402(followed by any combination of digits, letters and underscore) may be
11403added to the declarations in the <errno.h> header.
11404
11405
114064.13.2 Character handling <ctype.h>
11407
11408 Function names that begin with either is or to , and a lower-case
11409letter (followed by any combination of digits, letters and underscore)
11410may be added to the declarations in the <ctype.h> header.
11411
11412
114134.13.3 Localization <locale.h>
11414
11415 Macros that begin with LC_ and an upper-case letter (followed by
11416any combination of digits, letters and underscore) may be added to the
11417definitions in the <locale.h> header.
11418
11419
114204.13.4 Mathematics <math.h>
11421
11422 The names of all existing functions declared in the <math.h>
11423header, suffixed with f or l , are reserved respectively for
11424corresponding functions with float and long double arguments and
11425return values.
11426
11427
114284.13.5 Signal handling <signal.h>
11429
11430 Macros that begin with either SIG and an upper-case letter or SIG_
11431and an upper-case letter (followed by any combination of digits,
11432letters and underscore) may be added to the definitions in the
11433<signal.h> header.
11434
11435
114364.13.6 Input/output <stdio.h>
11437
11438 Lower-case letters may be added to the conversion specifiers in
11439fprintf and fscanf . Other characters may be used in extensions.
11440
11441
114424.13.7 General utilities <stdlib.h>
11443
11444 Function names that begin with str and a lower-case letter
11445(followed by any combination of digits, letters and underscore) may be
11446added to the declarations in the <stdlib.h> header.
11447
11448
114494.13.8 String handling <string.h>
11450
11451 Function names that begin with str , mem , or wcs and a lower-case
11452letter (followed by any combination of digits, letters and underscore)
11453may be added to the declarations in the <string.h> header.
11454
11455
11456A. APPENDICES
11457
11458 (These appendices are not a part of American National Standard for
11459Information Systems --- Programming Language C, X3.???-1988.)
11460
11461 These appendices collect information that appears in the Standard,
11462and are not necessarily complete.
11463
11464
11465A.1 LANGUAGE SYNTAX SUMMARY
11466
11467 The notation is described in the introduction to $3 (Language).
11468
11469
11470A.1.1 Lexical grammar
11471
11472A.1.1.1 Tokens
11473
11474 keyword
11475 identifier
11476 constant
11477 string-literal
11478 operator
11479 punctuator
11480 header-name
11481 identifier
11482 pp-number
11483 character-constant
11484 string-literal
11485 operator
11486 punctuator
11487 each non-white-space character that cannot be one of
11488 the above
11489
11490
11491A.1.1.2 Keywords
11492
11493 auto double int struct
11494 break else long switch
11495 case enum register typedef
11496 char extern return union
11497 const float short unsigned
11498 continue for signed void
11499 default goto sizeof volatile
11500 do if static while
11501
11502
11503A.1.1.3 Identifiers
11504
11505 nondigit
11506 identifier nondigit
11507 identifier digit
11508
11509 _ a b c d e f g h i j k l m
11510 n o p q r s t u v w x y z
11511 A B C D E F G H I J K L M
11512 N O P Q R S T U V W X Y Z
11513
11514 0 1 2 3 4 5 6 7 8 9
11515
11516
11517A.1.1.4 Constants
11518
11519 floating-constant
11520 integer-constant
11521 enumeration-constant
11522 character-constant
11523
11524 fractional-constant exponent-part<opt> floating-suffix<opt>
11525 digit-sequence exponent-part floating-suffix<opt>
11526
11527 digit-sequence<opt> . digit-sequence
11528 digit-sequence .
11529
11530 e sign<opt> digit-sequence
11531 E sign<opt> digit-sequence
11532
11533 + -
11534
11535 digit
11536 digit-sequence digit
11537
11538 f l F L
11539
11540 decimal-constant integer-suffix<opt>
11541 octal-constant integer-suffix<opt>
11542 hexadecimal-constant integer-suffix<opt>
11543
11544 nonzero-digit
11545 decimal-constant digit
11546
11547 0
11548 octal-constant octal-digit
11549
11550 0x hexadecimal-digit
11551 0X hexadecimal-digit
11552 hexadecimal-constant hexadecimal-digit
11553
11554 1 2 3 4 5 6 7 8 9
11555
11556 0 1 2 3 4 5 6 7
11557
11558 0 1 2 3 4 5 6 7 8 9
11559 a b c d e f
11560 A B C D E F
11561
11562 unsigned-suffix long-suffix<opt>
11563 long-suffix unsigned-suffix<opt>
11564
11565 u U
11566
11567 l L
11568
11569 identifier
11570
11571 ' c-char-sequence'
11572 L' c-char-sequence'
11573
11574 c-char
11575 c-char-sequence c-char
11576
11577 any member of the source character set except
11578 the single-quote ', backslash \, or new-line character
11579 escape-sequence
11580
11581 simple-escape-sequence
11582 octal-escape-sequence
11583 hexadecimal-escape-sequence
11584
11585 \' \" \? \\
11586 \a \b \f \n \r \t \v
11587
11588 \ octal-digit
11589 \ octal-digit octal-digit
11590 \ octal-digit octal-digit octal-digit
11591
11592 \x hexadecimal-digit
11593 hexadecimal-escape-sequence hexadecimal-digit
11594
11595
11596A.1.1.5 String literals
11597
11598 " s-char-sequence<opt>"
11599 L" s-char-sequence<opt>"
11600
11601 s-char
11602 s-char-sequence s-char
11603
11604 any member of the source character set except
11605 the double-quote ", backslash \, or new-line character
11606 escape-sequence
11607
11608
11609A.1.1.6 Operators
11610
11611 [ ] ( ) . ->
11612 ++ -- & * + - ~ ! sizeof
11613 / % << >> < > <= >= == != ^ | && ||
11614 ? :
11615 = *= /= %= += -= <<= >>= &= ^= |=
11616 , # ##
11617
11618
11619A.1.1.7 Punctuators
11620
11621 [ ] ( ) { } * , : = ; ... #
11622
11623
11624A.1.1.8 Header names
11625
11626 < h-char-sequence>
11627 " q-char-sequence"
11628
11629 h-char
11630 h-char-sequence h-char
11631
11632 any member of the source character set except
11633 the new-line character and >
11634
11635 q-char
11636 q-char-sequence q-char
11637
11638 any member of the source character set except
11639 the new-line character and "
11640
11641
11642A.1.1.9 Preprocessing numbers
11643
11644 digit
11645 . digit
11646 pp-number digit
11647 pp-number nondigit
11648 pp-number e sign
11649 pp-number E sign
11650 pp-number .
11651
11652
11653A.1.2 Phrase structure grammar
11654
11655A.1.2.1 Expressions
11656
11657 identifier
11658 constant
11659 string-literal
11660 ( expression )
11661
11662 primary-expression
11663 postfix-expression [ expression ]
11664 postfix-expression ( argument-expression-list<opt> )
11665 postfix-expression . identifier
11666 postfix-expression -> identifier
11667 postfix-expression ++
11668 postfix-expression --
11669
11670 assignment-expression
11671 argument-expression-list , assignment-expression
11672
11673 postfix-expression
11674 ++ unary-expression
11675 -- unary-expression
11676 unary-operator cast-expression
11677 sizeof unary-expression
11678 sizeof ( type-name )
11679
11680 & * + - ~ !
11681
11682 unary-expression
11683 ( type-name ) cast-expression
11684
11685 cast-expression
11686 multiplicative-expression * cast-expression
11687 multiplicative-expression / cast-expression
11688 multiplicative-expression % cast-expression
11689
11690 multiplicative-expression
11691 additive-expression + multiplicative-expression
11692 additive-expression - multiplicative-expression
11693
11694 additive-expression
11695 shift-expression << additive-expression
11696 shift-expression >> additive-expression
11697
11698 shift-expression
11699 relational-expression < shift-expression
11700 relational-expression > shift-expression
11701 relational-expression <= shift-expression
11702 relational-expression >= shift-expression
11703
11704 relational-expression
11705 equality-expression == relational-expression
11706 equality-expression != relational-expression
11707
11708 equality-expression
11709 AND-expression & equality-expression
11710
11711 AND-expression
11712 exclusive-OR-expression ^ AND-expression
11713
11714 exclusive-OR-expression
11715 inclusive-OR-expression | exclusive-OR-expression
11716
11717 inclusive-OR-expression
11718 logical-AND-expression && inclusive-OR-expression
11719
11720 logical-AND-expression
11721 logical-OR-expression || logical-AND-expression
11722
11723 logical-OR-expression
11724 logical-OR-expression ? expression : conditional-expression
11725
11726 conditional-expression
11727 unary-expression assignment-operator assignment-expression
11728
11729 = *= /= %= += -= <<= >>= &= ^= |=
11730
11731 assignment-expression
11732 expression , assignment-expression
11733
11734 conditional-expression
11735
11736
11737A.1.2.2 Declarations
11738
11739 declaration-specifiers init-declarator-list<opt> ;
11740
11741 storage-class-specifier declaration-specifiers<opt>
11742 type-specifier declaration-specifiers<opt>
11743 type-qualifier declaration-specifiers<opt>
11744
11745 init-declarator
11746 init-declarator-list , init-declarator
11747
11748 declarator
11749 declarator = initializer
11750
11751 typedef
11752 extern
11753 static
11754 auto
11755 register
11756
11757 void
11758 char
11759 short
11760 int
11761 long
11762 float
11763 double
11764 signed
11765 unsigned
11766 struct-or-union-specifier
11767 enum-specifier
11768 typedef-name
11769
11770 struct-or-union identifier<opt> { struct-declaration-list }
11771 struct-or-union identifier
11772
11773 struct
11774 union
11775
11776 struct-declaration
11777 struct-declaration-list struct-declaration
11778
11779 specifier-qualifier-list struct-declarator-list ;
11780
11781 type-specifier specifier-qualifier-list<opt>
11782 type-qualifier specifier-qualifier-list<opt>
11783
11784 struct-declarator
11785 struct-declarator-list , struct-declarator
11786
11787 declarator
11788 declarator<opt> : constant-expression
11789
11790 enum identifier<opt> { enumerator-list }
11791 enum identifier
11792
11793 enumerator
11794 enumerator-list , enumerator
11795
11796 enumeration-constant
11797 enumeration-constant = constant-expression
11798
11799 const
11800 volatile
11801
11802 pointer<opt> direct-declarator
11803
11804 identifier
11805 ( declarator )
11806 direct-declarator [ constant-expression<opt> ]
11807
11808 direct-declarator ( parameter-type-list )
11809 direct-declarator ( identifier-list<opt> )
11810
11811 * type-qualifier-list<opt>
11812 * type-qualifier-list<opt> pointer
11813
11814 type-qualifier
11815 type-qualifier-list type-qualifier
11816
11817 parameter-list
11818 parameter-list , ...
11819
11820 parameter-declaration
11821 parameter-list , parameter-declaration
11822
11823 declaration-specifiers declarator
11824 declaration-specifiers abstract-declarator<opt>
11825
11826 identifier
11827 identifier-list , identifier
11828
11829 specifier-qualifier-list abstract-declarator<opt>
11830
11831 pointer
11832 pointer<opt> direct-abstract-declarator
11833
11834 ( abstract-declarator )
11835 direct-abstract-declarator<opt> [ constant-expression<opt> ]
11836 direct-abstract-declarator<opt> ( parameter-type-list<opt> )
11837
11838 identifier
11839
11840 assignment-expression
11841 { initializer-list }
11842 { initializer-list , }
11843
11844 initializer
11845 initializer-list , initializer
11846
11847
11848A.1.2.3 Statements
11849
11850 labeled-statement
11851 compound-statement
11852 expression-statement
11853 selection-statement
11854 iteration-statement
11855 jump-statement
11856
11857 identifier : statement
11858 case constant-expression : statement
11859 default : statement
11860
11861 { declaration-list<opt> statement-list<opt> }
11862
11863 declaration
11864 declaration-list declaration
11865
11866 statement
11867 statement-list statement
11868
11869 expression<opt> ;
11870
11871 if ( expression ) statement
11872 if ( expression ) statement else statement
11873 switch ( expression ) statement
11874
11875 while ( expression ) statement
11876 do statement while ( expression ) ;
11877 for ( expression<opt> ; expression<opt> ;
11878 expression<opt> ) statement
11879
11880 goto identifier ;
11881 continue ;
11882 break ;
11883 return expression<opt> ;
11884
11885
11886A.1.2.4 External definitions
11887
11888 external-declaration
11889 translation-unit external-declaration
11890
11891 function-definition
11892 declaration
11893
11894 declaration-specifiers<opt> declarator
11895 declaration-list<opt> compound-statement
11896
11897
11898A.1.3 Preprocessing directives
11899
11900 group<opt>
11901
11902 group-part
11903 group group-part
11904
11905 pp-tokens<opt> new-line
11906 if-section
11907 control-line
11908
11909 if-group elif-groups<opt> else-group<opt> endif-line
11910
11911 # if constant-expression new-line group<opt>
11912 # ifdef identifier new-line group<opt>
11913 # ifndef identifier new-line group<opt>
11914
11915 elif-group
11916 elif-groups elif-group
11917
11918 # elif constant-expression new-line group<opt>
11919
11920 # else new-line group<opt>
11921
11922 # endif new-line
11923
11924 control-line:
11925
11926 the left-parenthesis character without preceding white space
11927
11928 pp-tokens<opt>
11929
11930 preprocessing-token
11931 pp-tokens preprocessing-token
11932
11933 the new-line character
11934
11935
11936A.2 SEQUENCE POINTS
11937
11938 The following are the sequence points described in $2.1.2.3.
11939
11940
11941 * The call to a function, after the arguments have been evaluated
11942 ($3.3.2.2).
11943
11944 * The end of the first operand of the following operators: logical
11945 AND && ($3.3.13); logical OR || ($3.3.14); conditional ? ($3.3.15);
11946 comma , ($3.3.17).
11947
11948 * The end of a full expression: an initializer ($3.5.7); the
11949 expression in an expression statement ($3.6.3); the controlling
11950 expression of a selection statement ( if or switch ) ($3.6.4); the
11951 controlling expression of a while or do statement ($3.6.5); the three
11952 expressions of a for statement ($3.6.5.3); the expression in a return
11953 statement ($3.6.6.4).
11954
11955
11956A.3 LIBRARY SUMMARY
11957
11958A.3.1 ERRORS <errno.h>
11959
11960 EDOM
11961 ERANGE
11962 errno
11963
11964
11965A.3.2 COMMON DEFINITIONS <stddef.h>
11966
11967 NULL
11968 offsetof( type, member-designator)
11969 ptrdiff_t
11970 size_t
11971 wchar_t
11972
11973
11974A.3.3 DIAGNOSTICS <assert.h>
11975
11976 NDEBUG
11977 void assert(int expression);
11978
11979
11980A.3.4 CHARACTER HANDLING <ctype.h>
11981
11982 int isalnum(int c);
11983 int isalpha(int c);
11984 int iscntrl(int c);
11985 int isdigit(int c);
11986 int isgraph(int c);
11987 int islower(int c);
11988 int isprint(int c);
11989 int ispunct(int c);
11990 int isspace(int c);
11991 int isupper(int c);
11992 int isxdigit(int c);
11993 int tolower(int c);
11994 int toupper(int c);
11995
11996
11997A.3.5 LOCALIZATION <locale.h>
11998
11999 LC_ALL
12000 LC_COLLATE
12001 LC_CTYPE
12002 LC_MONETARY
12003 LC_NUMERIC
12004 LC_TIME
12005 NULL
12006 struct lconv
12007 char *setlocale(int category, const char *locale);
12008 struct lconv *localeconv(void);
12009
12010
12011A.3.6 MATHEMATICS <math.h>
12012
12013 HUGE_VAL
12014 double acos(double x);
12015 double asin(double x);
12016 double atan(double x);
12017 double atan2(double y, double x);
12018 double cos(double x);
12019 double sin(double x);
12020 double tan(double x);
12021 double cosh(double x);
12022 double sinh(double x);
12023 double tanh(double x);
12024 double exp(double x);
12025 double frexp(double value, int *exp);
12026 double ldexp(double x, int exp);
12027 double log(double x);
12028 double log10(double x);
12029 double modf(double value, double *iptr);
12030 double pow(double x, double y);
12031 double sqrt(double x);
12032 double ceil(double x);
12033 double fabs(double x);
12034 double floor(double x);
12035 double fmod(double x, double y);
12036
12037
12038A.3.7 NON-LOCAL JUMPS <setjmp.h>
12039
12040 jmp_buf
12041 int setjmp(jmp_buf env);
12042 void longjmp(jmp_buf env, int val);
12043
12044
12045A.3.8 SIGNAL HANDLING <signal.h>
12046
12047 sig_atomic_t
12048 SIG_DFL
12049 SIG_ERR
12050 SIG_IGN
12051 SIGABRT
12052 SIGFPE
12053 SIGILL
12054 SIGINT
12055 SIGSEGV
12056 SIGTERM
12057 void (*signal(int sig, void (*func)(int)))(int);
12058 int raise(int sig);
12059
12060
12061A.3.9 VARIABLE ARGUMENTS <stdarg.h>
12062
12063 va_list
12064 void va_start(va_list ap, parmN);
12065 type va_arg(va_list ap, type);
12066 void va_end(va_list ap);
12067
12068
12069A.3.10 INPUT/OUTPUT <stdio.h>
12070
12071 _IOFBF
12072 _IOLBF
12073 _IONBF
12074 BUFSIZ
12075 EOF
12076 FILE
12077 FILENAME_MAX
12078 FOPEN_MAX
12079 fpos_t
12080 L_tmpnam
12081 NULL
12082 SEEK_CUR
12083 SEEK_END
12084 SEEK_SET
12085 size_t
12086 stderr
12087 stdin
12088 stdout
12089 TMP_MAX
12090 int remove(const char *filename);
12091 int rename(const char *old, const char *new);
12092 FILE *tmpfile(void);
12093 char *tmpnam(char *s);
12094 int fclose(FILE *stream);
12095 int fflush(FILE *stream);
12096 FILE *fopen(const char *filename, const char *mode);
12097 FILE *freopen(const char *filename, const char *mode,
12098 FILE *stream);
12099 void setbuf(FILE *stream, char *buf);
12100 int setvbuf(FILE *stream, char *buf, int mode, size_t size);
12101 int fprintf(FILE *stream, const char *format, ...);
12102 int fscanf(FILE *stream, const char *format, ...);
12103 int printf(const char *format, ...);
12104 int scanf(const char *format, ...);
12105 int sprintf(char *s, const char *format, ...);
12106 int sscanf(const char *s, const char *format, ...);
12107 int vfprintf(FILE *stream, const char *format, va_list arg);
12108 int vprintf(const char *format, va_list arg);
12109 int vsprintf(char *s, const char *format, va_list arg);
12110 int fgetc(FILE *stream);
12111 char *fgets(char *s, int n, FILE *stream);
12112 int fputc(int c, FILE *stream);
12113 int fputs(const char *s, FILE *stream);
12114 int getc(FILE *stream);
12115 int getchar(void);
12116 char *gets(char *s);
12117 int putc(int c, FILE *stream);
12118 int putchar(int c);
12119 int puts(const char *s);
12120 int ungetc(int c, FILE *stream);
12121 size_t fread(void *ptr, size_t size, size_t nmemb,
12122 FILE *stream);
12123 size_t fwrite(const void *ptr, size_t size, size_t nmemb,
12124 FILE *stream);
12125 int fgetpos(FILE *stream, fpos_t *pos);
12126 int fseek(FILE *stream, long int offset, int whence);
12127 int fsetpos(FILE *stream, const fpos_t *pos);
12128 long int ftell(FILE *stream);
12129 void rewind(FILE *stream);
12130 void clearerr(FILE *stream);
12131 int feof(FILE *stream);
12132 int ferror(FILE *stream);
12133 void perror(const char *s);
12134
12135
12136A.3.11 GENERAL UTILITIES <stdlib.h>
12137
12138 EXIT_FAILURE
12139 EXIT_SUCCESS
12140 MB_CUR_MAX
12141 NULL
12142 RAND_MAX
12143 div_t
12144 ldiv_t
12145 size_t
12146 wchar_t
12147 double atof(const char *nptr);
12148 int atoi(const char *nptr);
12149 long int atol(const char *nptr);
12150 double strtod(const char *nptr, char **endptr);
12151 long int strtol(const char *nptr, char **endptr, int base);
12152 unsigned long int strtoul(const char *nptr, char **endptr,
12153 int base);
12154 int rand(void);
12155 void srand(unsigned int seed);
12156 void *calloc(size_t nmemb, size_t size);
12157 void free(void *ptr);
12158 void *malloc(size_t size);
12159 void *realloc(void *ptr, size_t size);
12160 void abort(void);
12161 int atexit(void (*func)(void));
12162 void exit(int status);
12163 char *getenv(const char *name);
12164 int system(const char *string);
12165 void *bsearch(const void *key, const void *base,
12166 size_t nmemb, size_t size,
12167 int (*compar)(const void *, const void *));
12168 void qsort(void *base, size_t nmemb, size_t size,
12169 int (*compar)(const void *, const void *));
12170 int abs(int j);
12171 div_t div(int numer, int denom);
12172 long int labs(long int j);
12173 ldiv_t ldiv(long int numer, long int denom);
12174 int mblen(const char *s, size_t n);
12175 int mbtowc(wchar_t *pwc, const char *s, size_t n);
12176 int wctomb(char *s, wchar_t wchar);
12177 size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);
12178 size_t wcstombs(char *s, const wchar_t *pwcs, size_t n);
12179
12180
12181
12182A.3.12 STRING HANDLING <string.h>
12183
12184 NULL
12185 size_t
12186 void *memcpy(void *s1, const void *s2, size_t n);
12187 void *memmove(void *s1, const void *s2, size_t n);
12188 char *strcpy(char *s1, const char *s2);
12189 char *strncpy(char *s1, const char *s2, size_t n);
12190 char *strcat(char *s1, const char *s2);
12191 char *strncat(char *s1, const char *s2, size_t n);
12192 int memcmp(const void *s1, const void *s2, size_t n);
12193 int strcmp(const char *s1, const char *s2);
12194 int strcoll(const char *s1, const char *s2);
12195 int strncmp(const char *s1, const char *s2, size_t n);
12196 size_t strxfrm(char *s1, const char *s2, size_t n);
12197 void *memchr(const void *s, int c, size_t n);
12198 char *strchr(const char *s, int c);
12199 size_t strcspn(const char *s1, const char *s2);
12200 char *strpbrk(const char *s1, const char *s2);
12201 char *strrchr(const char *s, int c);
12202 size_t strspn(const char *s1, const char *s2);
12203 char *strstr(const char *s1, const char *s2);
12204 char *strtok(char *s1, const char *s2);
12205 void *memset(void *s, int c, size_t n);
12206 char *strerror(int errnum);
12207 size_t strlen(const char *s);
12208
12209
12210A.3.13 DATE AND TIME <time.h>
12211
12212 CLK_TCK
12213 NULL
12214 clock_t
12215 time_t
12216 size_t
12217 struct tm
12218 clock_t clock(void);
12219 double difftime(time_t time1, time_t time0);
12220 time_t mktime(struct tm *timeptr);
12221 time_t time(time_t *timer);
12222 char *asctime(const struct tm *timeptr);
12223 char *ctime(const time_t *timer);
12224 struct tm *gmtime(const time_t *timer);
12225 struct tm *localtime(const time_t *timer);
12226 size_t strftime(char *s, size_t maxsize,
12227 const char *format, const struct tm *timeptr);
12228
12229
12230A.4 IMPLEMENTATION LIMITS
12231
12232 The contents of a header <limits.h> are given below, in alphabetic
12233order. The minimum magnitudes shown shall be replaced by
12234implementation-defined magnitudes with the same sign. The values
12235shall all be constant expressions suitable for use in #if
12236preprocessing directives. The components are described further in
12237$2.2.4.2.
12238
12239 #define CHAR_BIT 8
12240 #define CHAR_MAX UCHAR_MAX or SCHAR_MAX
12241 #define CHAR_MIN 0 or SCHAR_MIN
12242 #define MB_LEN_MAX 1
12243 #define INT_MAX +32767
12244 #define INT_MIN -32767
12245 #define LONG_MAX +2147483647
12246 #define LONG_MIN -2147483647
12247 #define SCHAR_MAX +127
12248 #define SCHAR_MIN -127
12249 #define SHRT_MAX +32767
12250 #define SHRT_MIN -32767
12251 #define UCHAR_MAX 255
12252 #define UINT_MAX 65535
12253 #define ULONG_MAX 4294967295
12254 #define USHRT_MAX 65535
12255
12256
12257 The contents of a header <float.h> are given below, in alphabetic
12258order. The value of FLT_RADIX shall be a constant expression suitable
12259for use in #if preprocessing directives. Values that need not be
12260constant expressions shall be supplied for all other components. The
12261minimum magnitudes shown for integers and exponents shall be replaced
12262by implementation-defined magnitudes with the same sign. The
12263components are described further in $2.2.4.2.
12264
12265 #define DBL_DIG 10
12266 #define DBL_EPSILON 1E-9
12267 #define DBL_MANT_DIG
12268 #define DBL_MAX 1E+37
12269 #define DBL_MAX_10_EXP +37
12270 #define DBL_MAX_EXP
12271 #define DBL_MIN 1E-37
12272 #define DBL_MIN_10_EXP -37
12273 #define DBL_MIN_EXP
12274 #define FLT_DIG 6
12275 #define FLT_EPSILON 1E-5
12276 #define FLT_MANT_DIG
12277 #define FLT_MAX 1E+37
12278 #define FLT_MAX_10_EXP +37
12279 #define FLT_MAX_EXP
12280 #define FLT_MIN 1E-37
12281 #define FLT_MIN_10_EXP -37
12282 #define FLT_MIN_EXP
12283 #define FLT_RADIX 2
12284 #define FLT_ROUNDS
12285 #define LDBL_DIG 10
12286 #define LDBL_EPSILON 1E-9
12287 #define LDBL_MANT_DIG
12288 #define LDBL_MAX 1E+37
12289 #define LDBL_MAX_10_EXP +37
12290 #define LDBL_MAX_EXP
12291 #define LDBL_MIN 1E-37
12292 #define LDBL_MIN_10_EXP -37
12293 #define LDBL_MIN_EXP
12294
12295
12296A.5 COMMON WARNINGS
12297
12298 An implementation may generate warnings in many situations, none of
12299which is specified as part of the Standard. The following are a few
12300of the more common situations.
12301
12302 * A block with initialization of an object that has automatic storage
12303 duration is jumped into ($3.1.2.4).
12304
12305 * An integer character constant includes more than one character or a
12306 wide character constant includes more than one multibyte character
12307 ($3.1.3.4).
12308
12309 * The characters /* are found in a comment ($3.1.7).
12310
12311 * An implicit narrowing conversion is encountered, such as the
12312 assignment of a long int or a double to an int , or a pointer to void
12313 to a pointer to any type of object other than char ($3.2).
12314
12315 * An ``unordered'' binary operator (not comma, && or || ) contains a
12316 side-effect to an lvalue in one operand, and a side-effect to, or an
12317 access to the value of, the identical lvalue in the other operand
12318 ($3.3).
12319
12320 * A function is called but no prototype has been supplied ($3.3.2.2).
12321
12322 * The arguments in a function call do not agree in number and type
12323 with those of the parameters in a function definition that is not a
12324 prototype ($3.3.2.2).
12325
12326 * An object is defined but not used ($3.5).
12327
12328 * A value is given to an object of an enumeration type other than by
12329 assignment of an enumeration constant that is a member of that type,
12330 or an enumeration variable that has the same type, or the value of a
12331 function that returns the same enumeration type ($3.5.2.2).
12332
12333 * An aggregate has a partly bracketed initialization ($3.5.7).
12334
12335 * A statement cannot be reached ($3.6).
12336
12337 * A statement with no apparent effect is encountered ($3.6).
12338
12339 * A constant expression is used as the controlling expression of a
12340 selection statement ($3.6.4).
12341
12342 * A function has return statements with and without expressions ($3.6.6.4).
12343
12344 * An incorrectly formed preprocessing group is encountered while
12345 skipping a preprocessing group ($3.8.1).
12346
12347 * An unrecognized #pragma directive is encountered ($3.8.6).
12348
12349
12350A.6 PORTABILITY ISSUES
12351
12352 This appendix collects some information about portability that
12353appears in the Standard.
12354
12355
12356A.6.1 Unspecified behavior
12357
12358 The following are unspecified:
12359
12360 * The manner and timing of static initialization ($2.1.2).
12361
12362 * The behavior if a printable character is written when the active
12363 position is at the final position of a line ($2.2.2).
12364
12365 * The behavior if a backspace character is written when the active
12366 position is at the initial position of a line ($2.2.2).
12367
12368 * The behavior if a horizontal tab character is written when the
12369 active position is at or past the last defined horizontal tabulation
12370 position ($2.2.2).
12371
12372 * The behavior if a vertical tab character is written when the active
12373 position is at or past the last defined vertical tabulation position
12374 ($2.2.2).
12375
12376 * The representations of floating types ($3.1.2.5).
12377
12378 * The order in which expressions are evaluated --- in any order
12379 conforming to the precedence rules, even in the presence of
12380 parentheses ($3.3).
12381
12382 * The order in which side effects take place ($3.3).
12383
12384 * The order in which the function designator and the arguments in a
12385 function call are evaluated ($3.3.2.2).
12386
12387 * The alignment of the addressable storage unit allocated to hold a
12388 bit-field ($3.5.2.1).
12389
12390 * The layout of storage for parameters ($3.7.1).
12391
12392 * The order in which # and ## operations are evaluated during macro
12393 substitution ($3.8.3.3).
12394
12395 * Whether errno is a macro or an external identifier ($4.1.3).
12396
12397 * Whether setjmp is a macro or an external identifier ($4.6.1.1).
12398
12399 * Whether va_end is a macro or an external identifier ($4.8.1.3).
12400
12401 * The value of the file position indicator after a successful call to
12402 the ungetc function for a text stream, until all pushed-back
12403 characters are read or discarded ($4.9.7.11).
12404
12405 * The details of the value stored by the fgetpos function on success
12406 ($4.9.9.1).
12407
12408 * The details of the value returned by the ftell function for a text
12409 stream on success ($4.9.9.4).
12410
12411 * The order and contiguity of storage allocated by the calloc ,
12412 malloc , and realloc functions ($4.10.3).
12413
12414 * Which of two members that compare as equal is returned by the
12415 bsearch function ($4.10.5.1).
12416
12417 * The order in an array sorted by the qsort function of two members
12418 that compare as equal ($4.10.5.2).
12419
12420 * The encoding of the calendar time returned by the time function
12421 ($4.12.2.3).
12422
12423
12424A.6.2 Undefined behavior
12425
12426 The behavior in the following circumstances is undefined:
12427
12428 * A nonempty source file does not end in a new-line character, ends
12429 in new-line character immediately preceded by a backslash character,
12430 or ends in a partial preprocessing token or comment ($2.1.1.2).
12431
12432 * A character not in the required character set is encountered in a
12433 source file, except in a preprocessing token that is never converted
12434 to a token, a character constant, a string literal, or a comment
12435 ($2.2.1).
12436
12437 * A comment, string literal, character constant, or header name
12438 contains an invalid multibyte character or does not begin and end in
12439 the initial shift state ($2.2.1.2).
12440
12441 * An unmatched ' or character is encountered on a logical source line
12442 during tokenization ($3.1).
12443
12444 * The same identifier is used more than once as a label in the same
12445 function ($3.1.2.1).
12446
12447 * An identifier is used that is not visible in the current scope ($3.1.2.1).
12448
12449 * Identifiers that are intended to denote the same entity differ in a
12450 character beyond the minimal significant characters ($3.1.2).
12451
12452 * The same identifier has both internal and external linkage in the
12453 same translation unit ($3.1.2.2).
12454
12455 * An identifier with external linkage is used but there does not
12456 exist exactly one external definition in the program for the
12457 identifier ($3.1.2.2).
12458
12459 * The value stored in a pointer that referred to an object with
12460 automatic storage duration is used ($3.1.2.4).
12461
12462 * Two declarations of the same object or function specify types that
12463 are not compatible ($3.1.2.6).
12464
12465 * An unspecified escape sequence is encountered in a character
12466 constant or a string literal ($3.1.3.4).
12467
12468 * An attempt is made to modify a string literal of either form ($3.1.4).
12469
12470 * A character string literal token is adjacent to a wide string
12471 literal token ($3.1.4).
12472
12473 * The characters ', \ , , or /* are encountered between the < and >
12474 delimiters or the characters ', \ , or /* are encountered between the
12475 delimiters in the two forms of a header name preprocessing token
12476 ($3.1.7).
12477
12478 * An arithmetic conversion produces a result that cannot be
12479 represented in the space provided ($3.2.1).
12480
12481 * An lvalue with an incomplete type is used in a context that
12482 requires the value of the designated object ($3.2.2.1).
12483
12484 * The value of a void expression is used or an implicit conversion
12485 (except to void ) is applied to a void expression ($3.2.2.2).
12486
12487 * An object is modified more than once, or is modified and accessed
12488 other than to determine the new value, between two sequence points
12489 ($3.3).
12490
12491 * An arithmetic operation is invalid (such as division or modulus by 0)
12492 or produces a result that cannot be represented in the space
12493 provided (such as overflow or underflow) ($3.3).
12494
12495 * An object has its stored value accessed by an lvalue that does not
12496 have one of the following types: the declared type of the object, a
12497 qualified version of the declared type of the object, the signed or
12498 unsigned type corresponding to the declared type of the object, the
12499 signed or unsigned type corresponding to a qualified version of the
12500 declared type of the object, an aggregate or union type that
12501 (recursively) includes one of the aforementioned types among its
12502 members, or a character type ($3.3).
12503
12504 * An argument to a function is a void expression ($3.3.2.2).
12505
12506 * For a function call without a function prototype, the number of
12507 arguments does not agree with the number of parameters ($3.3.2.2).
12508
12509 * For a function call without a function prototype, if the function
12510 is defined without a function prototype, and the types of the
12511 arguments after promotion do not agree with those of the parameters
12512 after promotion ($3.3.2.2).
12513
12514 * If a function is called with a function prototype and the function
12515 is not defined with a compatible type ($3.3.2.2).
12516
12517 * A function that accepts a variable number of arguments is called
12518 without a function prototype that ends with an ellipsis ($3.3.2.2).
12519
12520 * An invalid array reference, null pointer reference, or reference to
12521 an object declared with automatic storage duration in a terminated
12522 block occurs ($3.3.3.2).
12523
12524 * A pointer to a function is converted to point to a function of a
12525 different type and used to call a function of a type not compatible
12526 with the original type ($3.3.4).
12527
12528 * A pointer to a function is converted to a pointer to an object or a
12529 pointer to an object is converted to a pointer to a function ($3.3.4).
12530
12531 * A pointer is converted to other than an integral or pointer type ($3.3.4).
12532
12533 * A pointer that is not to a member of an array object is added to or
12534 subtracted from ($3.3.6).
12535
12536 * Pointers that are not to the same array object are subtracted ($3.3.6).
12537
12538 * An expression is shifted by a negative number or by an amount
12539 greater than or equal to the width in bits of the expression being
12540 shifted ($3.3.7).
12541
12542 * Pointers are compared using a relational operator that do not point
12543 to the same aggregate or union ($3.3.8).
12544
12545 * An object is assigned to an overlapping object ($3.3.16.1).
12546
12547 * An identifier for an object is declared with no linkage and the
12548 type of the object is incomplete after its declarator, or after its
12549 init-declarator if it has an initializer ($3.5).
12550
12551 * A function is declared at block scope with a storage-class
12552 specifier other than extern ($3.5.1).
12553
12554 * A bit-field is declared with a type other than int , signed int ,
12555 or unsigned int ($3.5.2.1).
12556
12557 * An attempt is made to modify an object with const-qualified type by
12558 means of an lvalue with non-const-qualified type ($3.5.3).
12559
12560 * An attempt is made to refer to an object with volatile-qualified
12561 type by means of an lvalue with non-volatile-qualified type ($3.5.3).
12562
12563 * The value of an uninitialized object that has automatic storage
12564 duration is used before a value is assigned ($3.5.7).
12565
12566 * An object with aggregate or union type with static storage duration
12567 has a non-brace-enclosed initializer, or an object with aggregate or
12568 union type with automatic storage duration has either a single
12569 expression initializer with a type other than that of the object or a
12570 non-brace-enclosed initializer ($3.5.7).
12571
12572 * The value of a function is used, but no value was returned ($3.6.6.4).
12573
12574 * A function that accepts a variable number of arguments is defined
12575 without a parameter type list that ends with the ellipsis notation
12576 ($3.7.1).
12577
12578 * An identifier for an object with internal linkage and an incomplete
12579 type is declared with a tentative definition ($3.7.2).
12580
12581 * The token defined is generated during the expansion of a #if or
12582 #elif preprocessing directive ($3.8.1).
12583
12584 * The #include preprocessing directive that results after expansion
12585 does not match one of the two header name forms ($3.8.2).
12586
12587 * A macro argument consists of no preprocessing tokens ($3.8.3).
12588
12589 * There are sequences of preprocessing tokens within the list of
12590 macro arguments that would otherwise act as preprocessing directive
12591 lines ($3.8.3).
12592
12593 * The result of the preprocessing concatenation operator ## is not a
12594 valid preprocessing token ($3.8.3).
12595
12596 * The #line preprocessing directive that results after expansion does
12597 not match one of the two well-defined forms ($3.8.4).
12598
12599 * One of the following identifiers is the subject of a #define or
12600 #undef preprocessing directive: defined , __LINE__ , __FILE__ ,
12601 __DATE__ , __TIME__ , or __STDC__ ($3.8.8).
12602
12603 * An attempt is made to copy an object to an overlapping object by
12604 use of a library function other than memmove ($4.).
12605
12606 * The effect if the program redefines a reserved external identifier
12607 ($4.1.2).
12608
12609 * The effect if a standard header is included within an external
12610 definition; is included for the first time after the first reference
12611 to any of the functions or objects it declares, or to any of the types
12612 or macros it defines; or is included while a macro is defined with a
12613 name the same as a keyword ($4.1.2).
12614
12615 * A macro definition of errno is suppressed to obtain access to an
12616 actual object ($4.1.3).
12617
12618 * The parameter member-designator of an offsetof macro is an invalid
12619 right operand of the . operator for the type parameter or designates
12620 bit-field member of a structure ($4.1.5).
12621
12622 * A library function argument has an invalid value, unless the
12623 behavior is specified explicitly ($4.1.6).
12624
12625 * A library function that accepts a variable number of arguments is
12626 not declared ($4.1.6).
12627
12628 * The macro definition of assert is suppressed to obtain access to an
12629 actual function ($4.2).
12630
12631 * The argument to a character handling function is out of the domain ($4.3).
12632
12633 * A macro definition of setjmp is suppressed to obtain access to an
12634 actual function ($4.6).
12635
12636 * An invocation of the setjmp macro occurs in a context other than as
12637 the controlling expression in a selection or iteration statement, or
12638 in a comparison with an integral constant expression (possibly as
12639 implied by the unary ! operator) as the controlling expression of a
12640 selection or iteration statement, or as an expression statement
12641 (possibly cast to void ) ($4.6.1.1).
12642
12643 * An object of automatic storage class that does not have
12644 volatile-qualified type has been changed between a setjmp invocation
12645 and a longjmp call and then has its value accessed ($4.6.2.1).
12646
12647 * The longjmp function is invoked from a nested signal routine ($4.6.2.1).
12648
12649 * A signal occurs other than as the result of calling the abort or
12650 raise function, and the signal handler calls any function in the
12651 standard library other than the signal function itself or refers to
12652 any object with static storage duration other than by assigning a
12653 value to a static storage duration variable of type volatile
12654 sig_atomic_t ($4.7.1.1).
12655
12656 * The value of errno is referred to after a signal occurs other than
12657 as the result of calling the abort or raise function and the
12658 corresponding signal handler calls the signal function such that it
12659 returns the value SIG_ERR ($4.7.1.1).
12660
12661 * The macro va_arg is invoked with the parameter ap that was passed
12662 to a function that invoked the macro va_arg with the same parameter
12663 ($4.8).
12664
12665 * A macro definition of va_start , va_arg , or va_end or a
12666 combination thereof is suppressed to obtain access to an actual
12667 function ($4.8.1).
12668
12669 * The parameter parmN of a va_start macro is declared with the
12670 register storage class, or with a function or array type, or with a
12671 type that is not compatible with the type that results after
12672 application of the default argument promotions ($4.8.1.1).
12673
12674 * There is no actual next argument for a va_arg macro invocation
12675 ($4.8.1.2).
12676
12677 * The type of the actual next argument in a variable argument list
12678 disagrees with the type specified by the va_arg macro ($4.8.1.2).
12679
12680 * The va_end macro is invoked without a corresponding invocation of
12681 the va_start macro ($4.8.1.3).
12682
12683 * A return occurs from a function with a variable argument list
12684 initialized by the va_start macro before the va_end macro is invoked
12685 ($4.8.1.3).
12686
12687 * The stream for the fflush function points to an input stream or to
12688 an update stream in which the most recent operation was input
12689 ($4.9.5.2).
12690
12691 * An output operation on an update stream is followed by an input
12692 operation without an intervening call to the fflush function or a file
12693 positioning function, or an input operation on an update stream is
12694 followed by an output operation without an intervening call to a file
12695 positioning function ($4.9.5.3).
12696
12697 * The format for the fprintf or fscanf function does not match the
12698 argument list ($4.9.6).
12699
12700 * An invalid conversion specification is found in the format for the
12701 fprintf or fscanf function ($4.9.6).
12702
12703 * A %% conversion specification for the fprintf or fscanf function
12704 contains characters between the pair of % characters ($4.9.6).
12705
12706 * A conversion specification for the fprintf function contains an h
12707 or l with a conversion specifier other than d , i , n , o , u , x , or
12708 X , or an L with a conversion specifier other than e , E , f , g , or
12709 G ($4.9.6.1).
12710
12711 * A conversion specification for the fprintf function contains a #
12712 flag with a conversion specifier other than o , x , X , e , E , f , g,
12713 or G ($4.9.6.1).
12714
12715 * A conversion specification for the fprintf function contains a 0
12716 flag with a conversion specifier other than d , i , o , u , x , X , e,
12717 E , f , g , or G ($4.9.6.1).
12718
12719 * An aggregate or union, or a pointer to an aggregate or union is an
12720 argument to the fprintf function, except for the conversion specifiers
12721 %s (for an array of character type) or %p (for a pointer to void )
12722 ($4.9.6.1).
12723
12724 * A single conversion by the fprintf function produces more than 509
12725 characters of output ($4.9.6.1).
12726
12727 * A conversion specification for the fscanf function contains an h or
12728 l with a conversion specifier other than d , i , n , o , u , or x , or
12729 an L with a conversion specifier other than e , f , or g ($4.9.6.2).
12730
12731 * A pointer value printed by %p conversion by the fprintf function
12732 during a previous program execution is the argument for %p conversion
12733 by the fscanf function ($4.9.6.2).
12734
12735 * The result of a conversion by the fscanf function cannot be
12736 represented in the space provided, or the receiving object does not
12737 have an appropriate type ($4.9.6.2).
12738
12739 * The result of converting a string to a number by the atof , atoi ,
12740 or atol function cannot be represented ($4.10.1).
12741
12742 * The value of a pointer that refers to space deallocated by a call
12743 to the free or realloc function is referred to ($4.10.3).
12744
12745 * The pointer argument to the free or realloc function does not match
12746 a pointer earlier returned by calloc , malloc , or realloc , or the
12747 object pointed to has been deallocated by a call to free or realloc
12748 ($4.10.3).
12749
12750 * A program executes more than one call to the exit function ($4.10.4.3).
12751
12752 * The result of an integer arithmetic function ( abs , div , labs ,
12753 or ldiv ) cannot be represented ($4.10.6).
12754
12755 * The shift states for the mblen , mbtowc , and wctomb functions are
12756 not explicitly reset to the initial state when the LC_CTYPE category
12757 of the current locale is changed ($4.10.7).
12758
12759 * An array written to by a copying or concatenation function is too
12760 small ($4.11.2, $4.11.3).
12761
12762 * An invalid conversion specification is found in the format for the
12763 strftime function ($4.12.3.5).
12764
12765
12766A.6.3 Implementation-defined behavior
12767
12768 Each implementation shall document its behavior in each of the
12769areas listed in this section. The following are
12770implementation-defined:
12771
12772
12773A.6.3.1 Environment
12774
12775 * The semantics of the arguments to main ($2.1.2.2).
12776
12777 * What constitutes an interactive device ($2.1.2.3).
12778
12779
12780A.6.3.2 Identifiers
12781
12782 * The number of significant initial characters (beyond 31) in an
12783 identifier without external linkage ($3.1.2).
12784
12785 * The number of significant initial characters (beyond 6) in an
12786 identifier with external linkage ($3.1.2).
12787
12788 * Whether case distinctions are significant in an identifier with
12789 external linkage ($3.1.2).
12790
12791
12792A.6.3.3 Characters
12793
12794 * The members of the source and execution character sets, except as
12795 explicitly specified in the Standard ($2.2.1).
12796
12797 * The shift states used for the encoding of multibyte characters $2.2.1.2).
12798
12799 * The number of bits in a character in the execution character set
12800 ($2.2.4.2).
12801
12802 * The mapping of members of the source character set (in character
12803 constants and string literals) to members of the execution character
12804 set ($3.1.3.4).
12805
12806 * The value of an integer character constant that contains a
12807 character or escape sequence not represented in the basic execution
12808 character set or the extended character set for a wide character
12809 constant ($3.1.3.4).
12810
12811 * The value of an integer character constant that contains more than
12812 one character or a wide character constant that contains more than one
12813 multibyte character ($3.1.3.4).
12814
12815 * The current locale used to convert multibyte characters into
12816 corresponding wide characters (codes) for a wide character constant
12817 ($3.1.3.4).
12818
12819 * Whether a ``plain'' char has the same range of values as signed
12820 char or unsigned char ($3.2.1.1).
12821
12822
12823A.6.3.4 Integers
12824
12825 * The representations and sets of values of the various types of
12826 integers ($3.1.2.5).
12827
12828 * The result of converting an integer to a shorter signed integer, or
12829 the result of converting an unsigned integer to a signed integer of
12830 equal length, if the value cannot be represented ($3.2.1.2).
12831
12832 * The results of bitwise operations on signed integers ($3.3).
12833
12834 * The sign of the remainder on integer division ($3.3.5).
12835
12836 * The result of a right shift of a negative-valued signed integral
12837 type ($3.3.7).
12838
12839
12840A.6.3.5 Floating point
12841
12842 * The representations and sets of values of the various types of
12843 floating-point numbers ($3.1.2.5).
12844
12845 * The direction of truncation when an integral number is converted to
12846 a floating-point number that cannot exactly represent the original
12847 value ($3.2.1.3).
12848
12849 * The direction of truncation or rounding when a floating-point
12850 number is converted to a narrower floating-point number ($3.2.1.4).
12851
12852
12853A.6.3.6 Arrays and pointers
12854
12855 * The type of integer required to hold the maximum size of an array
12856 --- that is, the type of the sizeof operator, size_t ($3.3.3.4,
12857 $4.1.1).
12858
12859 * The result of casting a pointer to an integer or vice versa ($3.3.4).
12860
12861 * The type of integer required to hold the difference between two
12862 pointers to members of the same array, ptrdiff_t ($3.3.6, $4.1.1).
12863
12864
12865A.6.3.7 Registers
12866
12867 * The extent to which objects can actually be placed in registers by
12868 use of the register storage-class specifier ($3.5.1).
12869
12870
12871A.6.3.8 Structures, unions, enumerations, and bit-fields
12872
12873 * A member of a union object is accessed using a member of a
12874 different type ($3.3.2.3).
12875
12876 * The padding and alignment of members of structures ($3.5.2.1).
12877 This should present no problem unless binary data written by one
12878 implementation are read by another.
12879
12880 * Whether a ``plain'' int bit-field is treated as a signed int
12881 bit-field or as an unsigned int bit-field ($3.5.2.1).
12882
12883 * The order of allocation of bit-fields within an int ($3.5.2.1).
12884
12885 * Whether a bit-field can straddle a storage-unit boundary ($3.5.2.1).
12886
12887 * The integer type chosen to represent the values of an enumeration
12888 type ($3.5.2.2).
12889
12890
12891A.6.3.9 Qualifiers
12892
12893 * What constitutes an access to an object that has volatile-qualified
12894 type ($3.5.5.3).
12895
12896
12897A.6.3.10 Declarators
12898
12899 * The maximum number of declarators that may modify an arithmetic,
12900 structure, or union type ($3.5.4).
12901
12902
12903A.6.3.11 Statements
12904
12905 * The maximum number of case values in a switch statement ($3.6.4.2).
12906
12907
12908A.6.3.12 Preprocessing directives
12909
12910 * Whether the value of a single-character character constant in a
12911 constant expression that controls conditional inclusion matches the
12912 value of the same character constant in the execution character set.
12913 Whether such a character constant may have a negative value ($3.8.1).
12914
12915 * The method for locating includable source files ($3.8.2).
12916
12917 * The support of quoted names for includable source files ($3.8.2).
12918
12919 * The mapping of source file character sequences ($3.8.2).
12920
12921 * The behavior on each recognized #pragma directive ($3.8.6).
12922
12923 * The definitions for __DATE__ and __TIME__ when respectively, the
12924 date and time of translation are not available ($3.8.8).
12925
12926
12927A.6.3.13 Library functions
12928
12929 * The null pointer constant to which the macro NULL expands ($4.1.5).
12930
12931 * The diagnostic printed by and the termination behavior of the
12932 assert function ($4.2).
12933
12934 * The sets of characters tested for by the isalnum , isalpha ,
12935 iscntrl , islower , isprint , and isupper functions ($4.3.1).
12936
12937 * The values returned by the mathematics functions on domain errors
12938 ($4.5.1).
12939
12940 * Whether the mathematics functions set the integer expression errno
12941 to the value of the macro ERANGE on underflow range errors ($4.5.1).
12942
12943 * Whether a domain error occurs or zero is returned when the fmod
12944 function has a second argument of zero ($4.5.6.4).
12945
12946 * The set of signals for the signal function ($4.7.1.1).
12947
12948 * The semantics for each signal recognized by the signal function
12949 ($4.7.1.1).
12950
12951 * The default handling and the handling at program startup for each
12952 signal recognized by the signal function ($4.7.1.1).
12953
12954 * If the equivalent of signal(sig, SIG_DFL); is not executed prior to
12955 the call of a signal handler, the blocking of the signal that is
12956 performed ($4.7.1.1).
12957
12958 * Whether the default handling is reset if the SIGILL signal is
12959 received by a handler specified to the signal function ($4.7.1.1).
12960
12961 * Whether the last line of a text stream requires a terminating
12962 new-line character ($4.9.2).
12963
12964 * Whether space characters that are written out to a text stream
12965 immediately before a new-line character appear when read in ($4.9.2).
12966
12967 * The number of null characters that may be appended to data written
12968 to a binary stream ($4.9.2).
12969
12970 * Whether the file position indicator of an append mode stream is
12971 initially positioned at the beginning or end of the file ($4.9.3).
12972
12973 * Whether a write on a text stream causes the associated file to be
12974 truncated beyond that point ($4.9.3).
12975
12976 * The characteristics of file buffering ($4.9.3).
12977
12978 * Whether a zero-length file actually exists ($4.9.3).
12979
12980 * The rules for composing valid file names ($4.9.3).
12981
12982 * Whether the same file can be open multiple times ($4.9.3).
12983
12984 * The effect of the remove function on an open file ($4.9.4.1).
12985
12986 * The effect if a file with the new name exists prior to a call to
12987 the rename function ($4.9.4.2).
12988
12989 * The output for %p conversion in the fprintf function ($4.9.6.1).
12990
12991 * The input for %p conversion in the fscanf function ($4.9.6.2).
12992
12993 * The interpretation of a - character that is neither the first nor
12994 the last character in the scanlist for %[ conversion in the fscanf
12995 function ($4.9.6.2).
12996
12997 * The value to which the macro errno is set by the fgetpos or ftell
12998 function on failure ($4.9.9.1, $4.9.9.4).
12999
13000 * The messages generated by the perror function ($4.9.10.4).
13001
13002 * The behavior of the calloc , malloc , or realloc function if the
13003 size requested is zero ($4.10.3).
13004
13005 * The behavior of the abort function with regard to open and
13006 temporary files ($4.10.4.1).
13007
13008 * The status returned by the exit function if the value of the
13009 argument is other than zero, EXIT_SUCCESS , or EXIT_FAILURE
13010 ($4.10.4.3).
13011
13012 * The set of environment names and the method for altering the
13013 environment list used by the getenv function ($4.10.4.4).
13014
13015 * The contents and mode of execution of the string by the system
13016 function ($4.10.4.5).
13017
13018 * The contents of the error message strings returned by the strerror
13019 function ($4.11.6.2).
13020
13021 * The local time zone and Daylight Saving Time ($4.12.1).
13022
13023 * The era for the clock function ($4.12.2.1).
13024
13025
13026A.6.4 Locale-specific Behavior
13027
13028 The following characteristics of a hosted environment are locale-specific:
13029
13030 * The content of the execution character set, in addition to the
13031 required members ($2.2.1).
13032
13033 * The direction of printing ($2.2.2).
13034
13035 * The decimal-point character ($4.1.1).
13036
13037 * The implementation-defined aspects of character testing and case
13038 mapping functions ($4.3).
13039
13040 * The collation sequence of the execution character set ($4.11.4.4).
13041
13042 * The formats for time and date ($4.12.3.5).
13043
13044
13045A.6.5 Common extensions
13046
13047 The following extensions are widely used in many systems, but are
13048not portable to all implementations. The inclusion of any extension
13049that may cause a strictly conforming program to become invalid renders
13050an implementation nonconforming. Examples of such extensions are new
13051keywords, or library functions declared in standard headers or
13052predefined macros with names that do not begin with an underscore.
13053
13054
13055A.6.5.1 Environment arguments
13056
13057 In a hosted environment, the main function receives a third
13058argument, char *envp[] , that points to a null-terminated array of
13059pointers to char , each of which points to a string that provides
13060information about the environment for this execution of the process
13061($2.1.2.2).
13062
13063
13064A.6.5.2 Specialized identifiers
13065
13066 Characters other than the underscore _ , letters, and digits, that
13067are not defined in the required source character set (such as the
13068dollar sign $ , or characters in national character sets) may appear
13069in an identifier ($3.1.2).
13070
13071
13072A.6.5.3 Lengths and cases of identifiers
13073
13074 All characters in identifiers (with or without external linkage)
13075are significant and case distinctions are observed ($3.1.2).
13076
13077
13078A.6.5.4 Scopes of identifiers
13079
13080 A function identifier, or the identifier of an object the
13081declaration of which contains the keyword extern , has file scope
13082($3.1.2.1).
13083
13084
13085A.6.5.5 Writable string literals
13086
13087 String literals are modifiable. Identical string literals shall be
13088distinct ($3.1.4).
13089
13090
13091A.6.5.6 Other arithmetic types
13092
13093 Other arithmetic types, such as long long int , and their
13094appropriate conversions are defined ($3.2.2.1).
13095
13096
13097A.6.5.7 Function pointer casts
13098
13099 A pointer to an object or to void may be cast to a pointer to a
13100function, allowing data to be invoked as a function ($3.3.4). A
13101pointer to a function may be cast to a pointer to an object or to void
13102, allowing a function to be inspected or modified (for example, by a
13103debugger) ($3.3.4).
13104
13105
13106A.6.5.8 Non-int bit-field types
13107
13108 Types other than int , unsigned int , or signed int can be declared
13109as bit-fields, with appropriate maximum widths ($3.5.2.1).
13110
13111
13112A.6.5.9 The fortran keyword
13113
13114 The fortran type specifier may be used in a function declaration to
13115indicate that function linkage suitable for FORTRAN is to be
13116generated, or that different representations for external names are to
13117be generated ($3.5.4.3).
13118
13119
13120A.6.5.10 The asm keyword
13121
13122 The asm keyword may be used to insert assembly-language code
13123directly into the translator output. The most common implementation
13124is via a statement of the form
13125
13126 asm ( character-string-literal );
13127
13128($3.6).
13129
13130
13131A.6.5.11 Multiple external definitions
13132
13133 There may be more than one external definition for the identifier
13134of an object, with or without the explicit use of the keyword extern ,
13135If the definitions disagree, or more than one is initialized, the
13136behavior is undefined ($3.7.2).
13137
13138
13139A.6.5.12 Empty macro arguments
13140
13141 A macro argument may consist of no preprocessing tokens ($3.8.3).
13142
13143
13144A.6.5.13 Predefined macro names
13145
13146 Macro names that do not begin with an underscore, describing the
13147translation and execution environments, may be defined by the
13148implementation before translation begins ($3.8.8).
13149
13150
13151A.6.5.14 Extra arguments for signal handlers
13152
13153 Handlers for specific signals may be called with extra arguments in
13154addition to the signal number ($4.7.1.1).
13155
13156
13157A.6.5.15 Additional stream types and file-opening modes
13158
13159 Additional mappings from files to streams may be supported
13160($4.9.2), and additional file-opening modes may be specified by
13161characters appended to the mode argument of the fopen function
13162($4.9.5.3).
13163
13164
13165A.6.5.16 Defined file position indicator
13166
13167 The file position indicator is decremented by each successful call
13168to the ungetc function for a text stream, except if its value was zero
13169before a call ($4.9.7.11).
13170
13171A.7 INDEX
13172
13173 Only major references are listed.
13174
13175absolute-value functions, 4.5.6.2, 4.10.6.1
13176abstract declarator, type name, 3.5.5
13177abstract machine, 2.1.2.3
13178abstract semantics, 2.1.2.3
13179active position, 2.2.2
13180addition assignment operator, +=, 3.3.16.2
13181addition operator, +, 3.3.6
13182additive expressions, 3.3.6
13183address operator, &, 3.3.3.2
13184aggregate type, 3.1.2.5
13185alert escape sequence, \a, 2.2.2, 3.1.3.4
13186alignment, definition of, 1.6
13187alignment of structure members, 3.5.2.1
13188AND operator, bitwise, &, 3.3.10
13189AND operator, logical, &&, 3.3.13
13190argument, function, 3.3.2.2
13191argument, 1.6
13192argument promotion, default, 3.3.2.2
13193arithmetic conversions, usual, 3.2.1.5
13194arithmetic operators, unary, 3.3.3.3
13195arithmetic type, 3.1.2.5
13196array declarator, 3.5.4.2
13197array parameter, 3.7.1
13198array subscript operator, [ ], 3.3.2.1
13199array type, 3.1.2.5
13200array type conversion, 3.2.2.1
13201arrow operator, ->, 3.3.2.3
13202ASCII character set, 2.2.1.1
13203assignment operators, 3.3.16
13204asterisk punctuator, *, 3.1.6, 3.5.4.1
13205automatic storage, reentrancy, 2.1.2.3, 2.2.3
13206automatic storage duration, 3.1.2.4
13207
13208backslash character, \, 2.1.1.2, 2.2.1
13209backspace escape sequence, \b, 2.2.2, 3.1.3.4
13210base documents, 1.5
13211basic character set, 1.6, 2.2.1
13212basic type, 3.1.2.5
13213binary stream, 4.9.2
13214bit, definition of, 1.6
13215bit, high-order, 1.6
13216bit, low-order, 1.6
13217bit-field structure member, 3.5.2.1
13218bitwise operators, 3.3, 3.3.7, 3.3.10, 3.3.11, 3.3.12
13219block, 3.6.2
13220block identifier scope, 3.1.2.1
13221braces punctuator, { }, 3.1.6, 3.5.7, 3.6.2
13222brackets punctuator, [ ], 3.1.6, 3.3.2.1, 3.5.4.2
13223broken-down-time type, 4.12.1
13224byte, definition of, 1.6
13225
13226C program, 2.1.1.1
13227C Standard, definition of terms, 1.6
13228C Standard, organization of document, 1.4
13229C Standard, purpose of, 1.1
13230C Standard, references, 1.3
13231C Standard, scope, restrictions and limits, 1.2
13232carriage-return escape sequence, \r, 2.2.2, 3.1.3.4
13233case mapping functions, 4.3.2
13234cast expressions, 3.3.4
13235cast operator, ( ), 3.3.4
13236character, 1.6
13237character case mapping functions, 4.3.2
13238character constant, 2.1.1.2, 2.2.1, 3.1.3.4
13239character display semantics, 2.2.2
13240character handling header, 4.3
13241character input/output functions, 4.9.7
13242character sets, 2.2.1
13243character string literal, 2.1.1.2, 3.1.4
13244character testing functions, 4.3.1
13245character type, 3.1.2.5, 3.2.2.1, 3.5.7
13246character type conversion, 3.2.1.1
13247collating sequence, character set, 2.2.1
13248colon punctuator, :, 3.1.6, 3.5.2.1
13249comma operator, ,, 3.3.17
13250command processor, 4.10.4.5
13251comment delimiters, /* */, 3.1.9
13252comments, 2.1.1.2, 3.1, 3.1.9
13253common initial sequence, 3.3.2.3
13254comparison functions, 4.11.4
13255compatible type, 3.1.2.6, 3.5.2, 3.5.3, 3.5.4
13256complement operator, ~, 3.3.3.3
13257compliance, 1.7
13258composite type, 3.1.2.6
13259compound assignment operators, 3.3.16.2
13260compound statement, 3.6.2
13261concatenation functions, 4.11.3
13262conceptual models, 2.1
13263conditional inclusion, 3.8.1
13264conditional operator, ? :, 3.3.15
13265conforming freestanding implementation, 1.7
13266conforming hosted implementation, 1.7
13267conforming implementation, 1.7
13268conforming program, 1.7
13269const-qualified type, 3.1.2.5, 3.2.2.1, 3.5.3
13270constant, character, 3.1.3.4
13271constant, enumeration, 3.1.2, 3.1.3.3
13272constant, floating, 3.1.3.1
13273constant, integer, 3.1.3.2
13274constant, primary expression, 3.3.1
13275constant expressions, 3.4
13276constants, 3.1.3
13277constraints, definition of, 1.6
13278content, structure/union/enumeration, 3.5.2.3
13279contiguity, memory allocation, 4.10.3
13280control characters, 2.2.1, 4.3.1, 4.3.1.3
13281conversion, arithmetic operands, 3.2.1
13282conversion, array, 3.2.2.1
13283conversion, characters and integers, 3.2.1.1
13284conversion, explicit, 3.2
13285conversion, floating and integral, 3.2.1.3
13286conversion, floating types, 3.2.1.4, 3.2.1.5
13287conversion, function, 3.2.2.1
13288conversion, function arguments, 3.3.2.2, 3.7.1
13289conversion, implicit, 3.2
13290conversion, pointer, 3.2.2.1, 3.2.2.3
13291conversion, signed and unsigned integers, 3.2.1.2
13292conversion, void type, 3.2.2.2
13293conversions, 3.2
13294conversions, usual arithmetic, 3.2.1.5
13295copying functions, 4.11.2
13296
13297data streams, 4.9.2
13298date and time header, 4.12
13299decimal constant, 3.1.3.2
13300decimal digits, 2.2.1
13301decimal-point character, 4.1.1
13302declaration specifiers, 3.5
13303declarations, 3.5
13304declarators, 3.5.4
13305declarator type derivation, 3.1.2.5, 3.5.4
13306decrement operator, postfix, --, 3.3.2.4
13307decrement operator, prefix, --, 3.3.3.1
13308default argument promotions, 3.3.2.2
13309definition, 3.5
13310derived declarator types, 3.1.2.5
13311derived types, 3.1.2.5
13312device input/output, 2.1.2.3
13313diagnostics, 2.1.1.3
13314diagnostics, assert.h, 4.2
13315direct input/output functions, 4.9.8
13316display device, 2.2.2
13317division assignment operator, /=, 3.3.16.2
13318division operator, /, 3.3.5
13319documentation of implementation, 1.7
13320domain error, 4.5.1
13321dot operator, ., 3.3.2.3
13322double-precision arithmetic, 2.1.2.3
13323
13324element type, 3.1.2.5
13325ellipsis, unspecified parameters, , ..., 3.5.4.3
13326end-of-file macro, EOF, 4.3, 4.9.1
13327end-of-file indicator, 4.9.1, 4.9.7.1
13328end-of-line indicator, 2.2.1
13329enumerated types, 3.1.2.5
13330enumeration constant, 3.1.2, 3.1.3.3
13331enumeration content, 3.5.2.3
13332enumeration members, 3.5.2.2
13333enumeration specifiers, 3.5.2.2
13334enumeration tag, 3.5.2.3
13335enumerator, 3.5.2.2
13336environment, 2
13337environment functions, 4.10.4
13338environment list, 4.10.4.4
13339environmental considerations, 2.2
13340environmental limits, 2.2.4
13341equal-sign punctuator, =, 3.1.6, 3.5, 3.5.7
13342equal-to operator, ==, 3.3.9
13343equality expressions, 3.3.9
13344error, domain, 4.5.1
13345error, range, 4.5.1
13346error conditions, 4.5.1
13347error handling functions, 4.9.10, 4.11.6.2
13348error indicator, 4.9.1, 4.9.7.1, 4.9.7.3
13349escape sequences, 2.2.1, 2.2.2, 3.1.3.4
13350evaluation, 3.1.5, 3.3
13351exception, 3.3
13352exclusive OR assignment operator, ^=, 3.3.16.2
13353exclusive OR operator, ^, 3.3.11
13354executable program, 2.1.1.1
13355execution environment, character sets, 2.2.1
13356execution environment limits, 2.2.4.2
13357execution environments, 2.1.2
13358execution sequence, 2.1.2.3, 3.6
13359explicit conversion, 3.2
13360exponent part, floating constant, 3.1.3.1
13361exponential functions, 4.5.4
13362expression, 3.3
13363expression, full, 3.6
13364expression, primary, 3.3.1
13365expression, unary, 3.3.3
13366expression statement, 3.6.3
13367extended character set, 1.6, 2.2.1.2
13368external definitions, 3.7
13369external identifiers, underscore, 4.1.2
13370external linkage, 3.1.2.2
13371external name, 3.1.2
13372external object definitions, 3.7.2
13373
13374file, closing, 4.9.3
13375file, creating, 4.9.3
13376file, opening, 4.9.3
13377file access functions, 4.9.5
13378file identifier scope, 3.1.2.1, 3.7
13379file name, 4.9.3
13380file operations, 4.9.4
13381file position indicator, 4.9.3
13382file positioning functions, 4.9.9
13383files, 4.9.3
13384floating arithmetic functions, 4.5.6
13385floating constants, 3.1.3.1
13386floating suffix, f or F, 3.1.3.1
13387floating types, 3.1.2.5
13388floating-point numbers, 3.1.2.5
13389form-feed character, 2.2.1, 3.1
13390form-feed escape sequence, \f, 2.2.2, 3.1.3.4
13391formatted input/output functions, 4.9.6
13392forward references, definition of, 1.6
13393freestanding execution environment, 2.1.2, 2.1.2.1
13394full expression, 3.6
13395fully buffered stream, 4.9.3
13396function, definition of, 1.6, 3.5.4.3
13397function, recursive call, 3.3.2.2
13398function argument, 3.3.2.2
13399function body, 3.7, 3.7.1
13400function call, 3.3.2.2
13401function call, library, 4.1.6
13402function declarator, 3.5.4.3
13403function definition, 3.5.4.3, 3.7.1
13404function designator, 3.2.2.1
13405function identifier scope, 3.1.2.1
13406function image, 2.2.3
13407function library, 2.1.1.1, 4.1.6
13408function parameter, 2.1.2.2, 3.3.2.2
13409function prototype, 3.1.2.1, 3.3.2.2, 3.5.4.3, 3.7.1
13410function prototype identifier scope, 3.1.2.1
13411function return, 3.6.6.4
13412function type, 3.1.2.5
13413function type conversion, 3.2.2.1
13414function-call operator, ( ), 3.3.2.2
13415future directions, 1.8, 3.9, 4.13
13416future language directions, 3.9
13417future library directions, 4.13
13418
13419general utility library, 4.10
13420graphic characters, 2.2.1
13421greater-than operator, >, 3.3.8
13422greater-than-or-equal-to operator, >=, 3.3.8
13423
13424header names, 3.1, 3.1.7, 3.8.2
13425headers, 4.1.2
13426hexadecimal constant, 3.1.3.2
13427hexadecimal digit, 3.1.3.2, 3.1.3.4
13428hexadecimal escape sequence, 3.1.3.4
13429high-order bit, 1.6
13430horizontal-tab character, 2.2.1, 3.1
13431horizontal-tab escape sequence, \t, 2.2.2, 3.1.3.4
13432hosted execution environment, 2.1.2, 2.1.2.2
13433hyperbolic functions, 4.5.3
13434
13435identifier, 3.1.2, 3.3.1
13436identifier, maximum length, 3.1.2
13437identifier, reserved, 4.1.2
13438identifier linkage, 3.1.2.2
13439identifier list, 3.5.4
13440identifier name space, 3.1.2.3
13441identifier scope, 3.1.2.1
13442identifier type, 3.1.2.5
13443IEEE floating-point arithmetic standard, 2.2.4.2
13444implementation, definition of, 1.6
13445implementation limits, 1.6, 2.2.4
13446implementation-defined behavior, 1.6
13447implicit conversion, 3.2
13448implicit function declaration, 3.3.2.2
13449inclusive OR assignment operator, |=, 3.3.16.2
13450inclusive OR operator, |, 3.3.12
13451incomplete type, 3.1.2.5
13452increment operator, postfix, ++, 3.3.2.4
13453increment operator, prefix, ++, 3.3.3.1
13454indirection operator, *, 3.3.3.2
13455inequality operator, !=, 3.3.9
13456initialization, 2.1.2, 3.1.2.4, 3.2.2.1, 3.5.7, 3.6.2
13457initializer, string literal, 3.2.2.1, 3.5.7
13458initializer braces, 3.5.7
13459initial shift state, 2.2.1.2, 4.10.7
13460input/output, device, 2.1.2.3
13461input/output header, 4.9
13462integer arithmetic functions, 4.10.6
13463integer character constant, 3.1.3.4
13464integer constants, 3.1.3.2
13465integer suffix, 3.1.3.2
13466integer type, 3.1.2.5
13467integer type conversion, 3.2.1.1, 3.2.1.2
13468integral constant expression, 3.4
13469integral promotions, 2.1.2.3, 3.2.1.1
13470integral type, 3.1.2.5
13471integral type conversion, 3.2.1.3
13472interactive device, 2.1.2.3, 4.9.3, 4.9.5.3
13473internal linkage, 3.1.2.2
13474internal name, 3.1.2
13475interrupt handler, 2.1.2.3, 2.2.3, 4.7
13476ISO 4217 Currency and Funds Representation, 1.3, 4.4.2.1
13477ISO 646 Invariant Code Set, 1.3, 2.2.1.1
13478iteration statements, 3.6.5
13479
13480jump statements, 3.6.6
13481
13482keywords, 3.1.1
13483
13484label name, 3.1.2.1, 3.1.2.3
13485labeled statements, 3.6.1
13486language, 3 language, future directions, 3.9
13487leading underscore in identifiers, 4.1.2
13488left-shift assignment operator, <<=, 3.3.16.2
13489left-shift operator, <<, 3.3.7
13490length function, 4.11.6.3
13491less-than operator, <, 3.3.8
13492less-than-or-equal-to operator, <=, 3.3.8
13493letter, 4.1.1
13494lexical elements, 2.1.1.2, 3.1
13495library, 2.1.1.1, 4
13496library, future directions, 4.13
13497library functions, use of, 4.1.6
13498library terms, 4.1.1
13499limits, environmental, 2.2.4
13500limits, numerical, 2.2.4.2
13501limits, translation, 2.2.4.1
13502line buffered stream, 4.9.3
13503line number, 3.8.4
13504lines, 2.1.1.2, 3.8, 4.9.2
13505linkages of identifiers, 3.1.2.2
13506locale, definition of, 1.6
13507localization, 4.4
13508logarithmic functions, 4.5.4
13509logical AND operator, &&, 3.3.13
13510logical negation operator, !, 3.3.3.3
13511logical OR operator, ||, 3.3.14
13512logical source lines, 2.1.1.2
13513long double suffix, l or L, 3.1.3.1
13514long integer suffix, l or L, 3.1.3.2
13515low-order bit, 1.6 lvalue, 3.2.2.1, 3.3.1, 3.3.2.4, 3.3.3.1, 3.3.16
13516
13517macro function vs. definition, 4.1.6
13518macro name definition, 2.2.4.1
13519macro names, predefined, 3.8.8
13520macro, redefinition of, 3.8.3
13521macro replacement, 3.8.3
13522member-access operators, . and ->, 3.3.2.3
13523memory management functions, 4.10.3
13524minus operator, unary, -, 3.3.3.3
13525modifiable lvalue, 3.2.2.1
13526modulus function, 4.5.4.6
13527multibyte characters, 2.2.1.2, 3.1.3.4, 4.10.7, 4.10.8
13528multibyte functions, 4.10.7, 4.10.8
13529multiplication assignment operator, *=, 3.3.16.2
13530multiplication operator, *, 3.3.5
13531multiplicative expressions, 3.3.5
13532
13533name, file, 4.9.3
13534name spaces of identifiers, 3.1.2.3
13535nearest-integer functions, 4.5.6
13536new-line character, 2.1.1.2, 2.2.1, 3.1, 3.8, 3.8.4
13537new-line escape sequence, \n, 2.2.2, 3.1.3.4
13538nongraphic characters, 2.2.2, 3.1.3.4
13539nonlocal jumps header, 4.6
13540not-equal-to operator, !=, 3.3.9
13541null character padding of binary streams, 4.9.2
13542null character, \0, 2.2.1, 3.1.3.4, 3.1.4
13543null pointer, 3.2.2.3
13544null pointer constant, 3.2.2.3
13545null preprocessing directive, 3.8.7
13546null statement, 3.6.3
13547number, floating-point, 3.1.2.5
13548numerical limits, 2.2.4.2
13549
13550object, definition of, 1.6
13551object type, 3.1.2.5
13552obsolescence, 1.8, 3.9, 4.13
13553octal constant, 3.1.3.2
13554octal digit, 3.1.3.2, 3.1.3.4
13555octal escape sequence, 3.1.3.4
13556operand, 3.1.5, 3.3
13557operating system, 2.1.2.1, 4.10.4.5
13558operator, unary, 3.3.3
13559operators, 3.1.5, 3.3
13560OR assignment operator, exclusive, ^=, 3.3.16.2
13561OR assignment operator, inclusive, |=, 3.3.16.2
13562OR operator, exclusive, ^, 3.3.11
13563OR operator, inclusive, |, 3.3.12
13564OR operator, logical, ||, 3.3.14
13565order of memory allocation, 4.10.3
13566order of evaluation of expression, 3.3
13567ordinary identifier name space, 3.1.2.3
13568
13569padding, null character, 4.9.2
13570parameter, ellipsis, , ..., 3.5.4.3
13571parameter, function, 3.3.2.2
13572parameter, main function, 2.1.2.2
13573parameter, 1.6
13574parameter type list, 3.5.4.3
13575parameters, program, 2.1.2.2
13576parentheses punctuator, ( ), 3.1.6, 3.5.4.3
13577parenthesized expression, 3.3.1
13578physical source lines, 2.1.1.2
13579plus operator, unary, +, 3.3.3.3
13580pointer, null, 3.2.2.3
13581pointer declarator, 3.5.4.1
13582pointer operator, ->, 3.3.2.3
13583pointer to function returning type, 3.3.2.2
13584pointer type, 3.1.2.5
13585pointer type conversion, 3.2.2.1, 3.2.2.3
13586portability of implementations, 1.7
13587position indicator, file, 4.9.3
13588postfix decrement operator, --, 3.3.2.4
13589postfix expressions, 3.3.2
13590postfix increment operator, ++, 3.3.2.4
13591power functions, 4.5.5
13592precedence of expression operators, 3.3
13593precedence of syntax rules, 2.1.1.2
13594predefined macro names, 3.8.8
13595prefix decrement operator, --, 3.3.3.1
13596prefix increment operator, ++, 3.3.3.1
13597preprocessing concatenation, 2.1.1.2, 3.8.3
13598preprocessing directives, 2.1.1.2, 3.8
13599preprocessing numbers, 3.1, 3.1.8
13600preprocessing tokens, 2.1.1.2, 3.1, 3.8
13601primary expressions, 3.3.1
13602printing characters, 2.2.2, 4.3.1, 4.3.1.7
13603program, conforming, 1.7
13604program, strictly conforming, 1.7
13605program diagnostics, 4.2.1
13606program execution, 2.1.2.3
13607program file, 2.1.1.1
13608program image, 2.1.1.2
13609program name, argv[0], 2.1.2.2
13610program parameters, 2.1.2.2
13611program startup, 2.1.2, 2.1.2.1, 2.1.2.2
13612program structure, 2.1.1.1
13613program termination, 2.1.2, 2.1.2.1, 2.1.2.2, 2.1.2.3
13614promotions, default argument, 3.3.2.2
13615promotions, integral, 2.1.2.3, 3.2.1.1
13616prototype, function, 3.1.2.1, 3.3.2.2, 3.5.4.3, 3.7.1
13617pseudo-random sequence functions, 4.10.2
13618punctuators, 3.1.6
13619
13620qualified types, 3.1.2.5
13621
13622range error, 4.5.1
13623recursive function call, 3.3.2.2
13624redefinition of macro, 3.8.3
13625reentrancy, 2.1.2.3, 2.2.3
13626referenced type, 3.1.2.5
13627relational expressions, 3.3.8
13628reliability of data, interrupted, 2.1.2.3
13629remainder assignment operator, %=, 3.3.16.2
13630remainder operator, %, 3.3.5
13631restore calling environment function, 4.6.2.1
13632reserved identifiers, 4.1.2
13633right-shift assignment operator, >>=, 3.3.16.2
13634right-shift operator, >>, 3.3.7
13635rvalue, 3.2.2.1
13636
13637save calling environment function, 4.6.1.1
13638scalar type, 3.1.2.5
13639scope of identifiers, 3.1.2.1
13640search functions, 4.10.5.1, 4.11.5
13641selection statements, 3.6.4
13642semicolon punctuator, ;, 3.1.6, 3.5, 3.6.3
13643sequence points, 2.1.2.3, 3.3, 3.6
13644shift expressions, 3.3.7
13645shift states, 2.2.1.2, 4.10.7
13646side effects, 2.1.2.3, 3.3
13647signal handler, 2.2.3, 4.7.1.1
13648signals, 2.1.2.3, 2.2.3, 4.7
13649signed integer types, 3.1.2.5, 3.1.3.2, 3.2.1.2
13650simple assignment operator, =, 3.3.16.1
13651single-precision arithmetic, 2.1.2.3
13652sort function, 4.10.5.2
13653source character set, 2.2.1
13654source file inclusion, 3.8.2
13655source files, 2.1.1.1
13656source text, 2.1.1.2
13657space character, 2.1.1.2, 2.2.1, 3.1
13658standard streams, 4.9.1, 4.9.3
13659standard header, float.h, 1.7, 2.2.4.2, 4.1.4
13660standard header, limits.h, 1.7, 2.2.4.2, 4.1.4
13661standard header, stdarg.h, 1.7, 4.8
13662standard header, stddef.h, 1.7, 4.1.5
13663standard headers, 4.1.2
13664state-dependent encoding, 2.2.1.2, 4.10.7
13665statements, 3.6
13666static storage duration, 3.1.2.4
13667storage duration, 3.1.2.4
13668storage-class specifier, 3.5.1
13669stream, fully buffered, 4.9.3
13670stream, line buffered, 4.9.3
13671stream, standard error, stderr, 4.9.1, 4.9.3
13672stream, standard input, stdin, 4.9.1, 4.9.3
13673stream, standard output, stdout, 4.9.1, 4.9.3
13674stream, unbuffered, 4.9.3
13675streams, 4.9.2
13676strictly conforming program, 1.7
13677string, 4.1.1
13678string conversion functions, 4.10.1
13679string handling header, 4.11
13680string length, 4.1.1, 4.11.6.3
13681string literal, 2.1.1.2, 2.2.1, 3.1.4, 3.3.1, 3.5.7
13682structure/union arrow operator, ->, 3.3.2.3
13683structure/union content, 3.5.2.3
13684structure/union dot operator, ., 3.3.2.3
13685structure/union member name space, 3.1.2.3
13686structure/union specifiers, 3.5.2.1
13687structure/union tag, 3.5.2.3
13688structure/union type, 3.1.2.5, 3.5.2.1
13689subtraction assignment operator, -=, 3.3.16.2
13690subtraction operator, -, 3.3.6
13691suffix, floating constant, 3.1.3.1
13692suffix, integer constant, 3.1.3.2
13693switch body, 3.6.4.2
13694switch case label, 3.6.1, 3.6.4.2
13695switch default label, 3.6.1, 3.6.4.2
13696syntactic categories, 3
13697syntax notation, 3
13698syntax rules, precedence of, 2.1.1.2
13699
13700tab characters, 2.2.1
13701tabs, white space, 3.1
13702tag, enumeration, 3.5.2.3
13703tag, structure/union, 3.5.2.3
13704tag name space, 3.1.2.3
13705tentative definitions, 3.7.2
13706text stream, 4.9.2
13707time components, 4.12.1
13708time conversion functions, 4.12.3
13709time manipulation functions, 4.12.2
13710tokens, 2.1.1.2, 3.1, 3.8
13711top type, 3.1.2.5
13712translation environment, 2.1.1
13713translation limits, 2.2.4.2
13714translation phases, 2.1.1.2
13715translation unit, 2.1.1.1, 3.7
13716trigonometric functions, 4.5.2
13717trigraph sequences, 2.1.1.2, 2.2.1.1
13718type, character, 3.1.2.5, 3.2.2.1, 3.5.7
13719type, compatible, 3.1.2.6, 3.5.2, 3.5.3, 3.5.4
13720type, composite, 3.1.2.6
13721type, const-qualified, 3.1.2.5, 3.5.3
13722type, function, 3.1.2.5
13723type, incomplete, 3.1.2.5
13724type, object, 3.1.2.5
13725type, qualified, 3.1.2.5
13726type, unqualified, 3.1.2.5
13727type, volatile-qualified, 3.1.2.5, 3.5.3
13728type conversions, 3.2
13729type definitions, 3.5.6
13730type names, 3.5.5
13731type specifiers, 3.5.2
13732type qualifiers, 3.5.3
13733types, 3.1.2.5
13734
13735unary arithmetic operators, 3.3.3.3
13736unary expressions, 3.3.3
13737unary minus operator, -, 3.3.3.3
13738unary operators, 3.3.3
13739unary plus operator, +, 3.3.3.3
13740unbuffered stream, 4.9.3
13741undefined behavior, 1.6
13742underscore, leading, in identifiers, 4.1.2
13743union tag, 3.5.2.3
13744union type specifier, 3.1.2.5, 3.5.2, 3.5.2.1
13745unqualified type, 3.1.2.5
13746unsigned integer suffix, u or U, 3.1.3.2
13747unsigned integer types, 3.1.2.5, 3.1.3.2
13748unspecified behavior, 1.6
13749usual arithmetic conversions, 3.2.1.5
13750
13751value part, floating constant, 3.1.3.1
13752variable arguments header, 4.8
13753vertical-tab character, 2.2.1, 3.1
13754vertical-tab escape sequence, \v, 2.2.2, 3.1.3.4
13755visibility of identifiers, 3.1.2.1
13756void expression, 3.2.2.2
13757volatile storage, 2.1.2.3
13758volatile-qualified type, 3.1.2.5, 3.5.3
13759
13760white space, 2.1.1.2, 3.1, 3.8, 4.3.1.9
13761wide character, 3.1.3.4
13762wide character constant, 3.1.3.4
13763wide string literal, 2.1.1.2, 3.1.4
13764
13765
13766
137671. This Standard is designed to promote the portability of C programs
13768among a variety of data-processing systems. It is intended for use by
13769implementors and knowledgeable programmers, and is not a tutorial. It
13770is accompanied by a Rationale document that explains many of the
13771decisions of the Technical Committee that produced it.
13772
137732. Strictly conforming programs are intended to be maximally portable
13774among conforming implementations. Conforming programs may depend upon
13775nonportable features of a conforming implementation.
13776
137773. Implementations must behave as if these separate phases occur, even
13778though many are typically folded together in practice.
13779
137804. As described in $3.1, the process of dividing a source file's
13781characters into preprocessing tokens is context-dependent. For
13782example, see the handling of < within a #include preprocessing
13783directive.
13784
137855. The trigraph sequences enable the input of characters that are not
13786defined in the "ISO 646-1983" Invariant Code Set, which is a subset of
13787the seven-bit ASCII code set.
13788
137896. Implementations should avoid imposing fixed translation limits
13790whenever possible.
13791
137927. See $3.1.2.5.
13793
137948. This model precludes floating-point representations other than
13795sign-magnitude.
13796
137979. The floating-point model in that standard sums powers of from zero,
13798so the values of the exponent limits are one less than shown here.
13799
1380010. See ``future language directions'' ($3.9.1).
13801
1380211. There is only one name space for tags even though three are
13803possible.
13804
1380512. In the case of a volatile object, the last store may not be
13806explicit in the program.
13807
1380813. A positional representation for integers that uses the binary
13809digits 0 and 1, in which the values represented by successive bits are
13810additive, begin with 1, and are multiplied by successive integral
13811powers of 2, except perhaps the bit with the highest position.
13812
1381314. Note that aggregate type does not include union type because an
13814object with union type can only contain one member at a time.
13815
1381615. There are three distinct combinations of qualified types.
13817
1381816. Two types need not be identical to be compatible.
13819
1382017. The semantics of these characters were discussed in $2.2.2.
13821
1382218. See ``future language directions'' ($3.9.2).
13823
1382419. A character string literal need not be a string (see $4.1.1),
13825because a null character may be embedded in it by a \0 escape
13826sequence.
13827
1382820. Thus, sequences of characters that resemble escape sequences cause
13829undefined behavior.
13830
1383121. Thus comments do not nest.
13832
1383322. In a two's-complement representation, there is no actual change in
13834the bit pattern except filling the high-order bits with copies of the
13835sign bit if the unsigned integer has greater size.
13836
1383723. The remaindering operation done when a value of integral type is
13838converted to unsigned type need not be done when a value of floating
13839type is converted to unsigned type. Thus the range of portable values
13840is [0, U type _MAX +1).
13841
1384224. The name ``lvalue'' comes originally from the assignment
13843expression E1 = E2 , in which the left operand E1 must be a
13844(modifiable) lvalue. It is perhaps better considered as representing
13845an object ``locator value.'' What is sometimes called ``rvalue'' is in
13846this Standard described as the ``value of an expression.'' An obvious
13847example of an lvalue is an identifier of an object. As a further
13848example, if E is a unary expression that is a pointer to an object, *E
13849is an lvalue that designates the object to which E points.
13850
1385125. Because this conversion does not occur, the operand of the sizeof
13852operator remains a function designator and violates the constraint in
13853$3.3.3.4.
13854
1385526. This paragraph renders undefined statement expressions such as
13856i = ++i + 1; while allowing i = i + 1;
13857
1385827. The syntax specifies the precedence of operators in the evaluation
13859of an expression, which is the same as the order of the major
13860subsections of this section, highest precedence first. Thus, for
13861example, the expressions allowed as the operands of the binary +
13862operator ($3.3.6) shall be those expressions defined in $3.3.1 through
13863$3.3.6. The exceptions are cast expressions ($3.3.4) as operands of
13864unary operators ($3.3.3), and an operand contained between any of the
13865following pairs of operators: grouping parentheses () ($3.3.1),
13866subscripting brackets [] ($3.3.2.1), function-call parentheses ()
13867($3.3.2.2), and the conditional operator ?: ($3.3.15). Within each
13868major subsection, the operators have the same precedence. Left- or
13869right-associativity is indicated in each subsection by the syntax for
13870the expressions discussed therein.
13871
1387228. The intent of this list is to specify those circumstances in which
13873an object may or may not be aliased.
13874
1387529. Most often, this is the result of converting an identifier that is
13876a function designator.
13877
1387830. That is, a function with external linkage and no information about
13879its parameters that returns an int . If in fact it is not defined as
13880having type ``function returning int ,'' the behavior is undefined.
13881
1388231. A function may change the values of its parameters, but these
13883changes cannot affect the values of the arguments. On the other hand,
13884it is possible to pass a pointer to an object, and the function may
13885change the value of the object pointed to. A parameter declared to
13886have array or function type is converted to a parameter with a pointer
13887type as described in
13888
1388932. If &E is a valid pointer expression (where & is the ``address-of''
13890operator, which generates a pointer to its operand) the expression
13891(&E)->MOS is the same as E.MOS .
13892
1389333. The ``byte orders'' for scalar types are invisible to isolated
13894programs that do not indulge in type punning (for example, by
13895assigning to one member of a union and inspecting the storage by
13896accessing another member that is an appropriately sized array of
13897character type), but must be accounted for when conforming to
13898externally-imposed storage layouts.
13899
1390034. It is always true that if E is a function designator or an lvalue
13901that is a valid operand of the unary & operator, *&E is a function
13902designator or an lvalue equal to E . If *P is an lvalue and T is the
13903name of an object pointer type, the cast expression *(T)P is an lvalue
13904that has a type compatible with that to which T points. Among the
13905invalid values for dereferencing a pointer by the unary * operator are
13906a null pointer, an address inappropriately aligned for the type of
13907object pointed to, or the address of an object that has automatic
13908storage duration when execution of the block in which the object is
13909declared and of all enclosed blocks has terminated.
13910
1391135. When applied to a parameter declared to have array or function
13912type, the sizeof operator yields the size of the pointer obtained by
13913converting as in $3.2.2.1; see $3.7.1.
13914
1391536. A cast does not yield an lvalue.
13916
1391737. The mapping functions for converting a pointer to an integer or an
13918integer to a pointer are intended to be consistent with the addressing
13919structure of the execution environment.
13920
1392138. The expression a<b<c is not interpreted as in ordinary
13922mathematics. As the syntax indicates, it means (a<b)<c ; in other
13923words, ``if a is less than b compare 1 to c ; otherwise compare 0 to c
13924.''
13925
1392639. Because of the precedences, a<b == c<d is 1 whenever a<b and c<d
13927have the same truth-value.
13928
1392940. If invalid prior pointer operations, such as accesses outside
13930array bounds, produced undefined behavior, the effect of subsequent
13931comparisons is undefined.
13932
1393341. A conditional expression does not yield an lvalue.
13934
1393542. The asymmetric appearance of these constraints with respect to
13936type qualifiers is due to the conversion (specified in $3.2.2.1) that
13937changes lvalues to ``the value of the expression'' which removes any
13938type qualifiers from the top type of the expression.
13939
1394043. A comma operator does not yield an lvalue.
13941
1394244. The operand of a sizeof operator is not evaluated ($3.3.3.4), and
13943thus any operator in $3.3 may be used.
13944
1394545. An integral constant expression must be used to specify the size
13946of a bit-field member of a structure, the value of an enumeration
13947constant, the size of an array, or the value of a case constant.
13948Further constraints that apply to the integral constant expressions
13949used in conditional-inclusion preprocessing directives are discussed
13950in $3.8.1.
13951
1395246. Thus in the following initialization, static int i = 2 || 1 / 0;
13953the expression is a valid integral constant expression with value one.
13954
1395547. Function definitions have a different syntax, described in $3.7.1.
13956
1395748. See ``future language directions'' ($3.9.3).
13958
1395949. The implementation may treat any register declaration simply as an
13960auto declaration. However, whether or not addressable storage is
13961actually used, the address of any part of an object declared with
13962storage-class specifier register may not be computed, either
13963explicitly (by use of the unary & operator as discussed in $3.3.3.2)
13964or implicitly (by converting an array name to a pointer as discussed
13965in $3.2.2.1). Thus the only operator that can be applied to an array
13966declared with storage-class specifier register is sizeof .
13967
1396850. The unary & (address-of) operator may not be applied to a
13969bit-field object; thus there are no pointers to or arrays of bit-field
13970objects.
13971
1397251. An unnamed bit-field is useful for padding to conform to
13973externally-imposed layouts.
13974
1397552. Thus, the identifiers of enumeration constants in the same scope
13976shall all be distinct from each other and from other identifiers
13977declared in ordinary declarators.
13978
1397953. A similar construction with enum does not exist and is not
13980necessary as there can be no mutual dependencies between the
13981declaration of an enumerated type and any other type.
13982
1398354. It is not needed, for example, when a typedef name is declared to
13984be a specifier for a structure or union, or when a pointer to or a
13985function returning a structure or union is being declared. (See
13986incomplete types in $3.1.2.5.) The specification shall be complete
13987before such a function is called or defined.
13988
1398955. Of course, when the declaration is of a typedef name, subsequent
13990declarations can make use of the typedef name to declare objects
13991having the specified structure, union, or enumerated type.
13992
1399356. The implementation may place a const object that is not volatile
13994in a read-only region of storage. Moreover, the implementation need
13995not allocate storage for such an object if its address is never used.
13996
1399757. This applies to those objects that behave as if they were defined
13998with qualified types, even if they are never actually defined as
13999objects in the program (such as an object at a memory-mapped
14000input/output address).
14001
1400258. A volatile declaration may be used to describe an object
14003corresponding to a memory-mapped input/output port or an object
14004accessed by an asynchronously interrupting function. Actions on
14005objects so declared shall not be ``optimized out'' by an
14006implementation or reordered except as permitted by the rules for
14007evaluating expressions.
14008
1400959. Both of these can only occur through the use of typedef s.
14010
1401160. When several ``array of'' specifications are adjacent, a
14012multi-dimensional array is declared.
14013
1401461. The macros defined in the <stdarg.h> header ($4.8) may be used to
14015access arguments that follow an ellipsis.
14016
1401762. See ``future language directions'' ($3.9.4).
14018
1401963. If both function types are ``old style,'' parameter types are not
14020compared.
14021
1402264. As indicated by the syntax, empty parentheses in a type name are
14023interpreted as ``function with no parameter specification,'' rather
14024than redundant parentheses around the omitted identifier.
14025
1402665. Unlike in the base document, any automatic duration object may be
14027initialized.
14028
1402966. Such as assignments, and function calls which have side effects.
14030
1403167. Thus specifies initialization for the loop; the controlling
14032expression, specifies an evaluation made before each iteration, such
14033that execution of the loop continues until the expression compares
14034equal to 0; specifies an operation (such as incrementing) that is
14035performed after each iteration.
14036
1403768. Following the contin: label is a null statement.
14038
1403969. Thus, if an identifier declared with external linkage is not used
14040in an expression, there need be no external definition for it.
14041
1404270. The intent is that the top type in a function definition cannot be
14043inherited from a typedef: typedef int F(void); /* type F is ``function
14044of no arguments returning int '' */ F f, g; /* f and g both have type
14045compatible with F */ F f { /*...*/ } /* WRONG: syntax/constraint error
14046*/ F g() { /*...*/ } /* WRONG: declares that g returns a function */
14047int f(void) { /*...*/ } /* RIGHT: f has type compatible with F */ int
14048g() { /*...*/ } /* RIGHT: g has type compatible with F */ F *e(void) {
14049/*...*/ } /* e returns a pointer to a function */ F *((e))(void) {
14050/*...*/ } /* same: parentheses irrelevant */ int (*fp)(void); /* fp
14051points to a function that has type F */ F *Fp; /* Fp points to a
14052function that has type F */
14053
1405471. See ``future language directions'' ($3.9.5).
14055
1405672. A parameter is in effect declared at the head of the compound
14057statement that constitutes the function body, and therefore may not be
14058redeclared in the function body (except in an enclosed block).
14059
1406073. Thus preprocessing directives are commonly called ``lines.'' These
14061``lines'' have no other syntactic significance, as all white space is
14062equivalent except in certain situations during preprocessing (see the
14063# character string literal creation operator in $3.8.3.2, for
14064example).
14065
1406674. Because the controlling constant expression is evaluated during
14067translation phase 4, all identifiers either are or are not macro names
14068--- there simply are no keywords, enumeration constants, and so on.
14069
1407075. Thus the constant expression in the following #if directive and if
14071statement is not guaranteed to evaluate to the same value in these two
14072contexts. #if 'z' - 'a' == 25 if ('z' - 'a' == 25)
14073
1407476. As indicated by the syntax, a preprocessing token shall not follow
14075a #else or #endif directive before the terminating new-line character.
14076However, comments may appear anywhere in a source file, including
14077within a preprocessing directive.
14078
1407977. Note that adjacent string literals are not concatenated into a
14080single string literal (see the translation phases in $2.1.1.2); thus
14081an expansion that results in two string literals is an invalid
14082directive.
14083
1408478. Since, by macro-replacement time, all character constants and
14085string literals are preprocessing tokens, not sequences possibly
14086containing identifier-like subsequences (see $2.1.1.2, translation
14087phases), they are never scanned for macro names or parameters.
14088
1408979. Thus indicating a Standard-conforming implementation.
14090
1409180. The functions that make use of the decimal-point character are
14092localeconv , fprintf , fscanf , printf , scanf , sprintf , sscanf ,
14093vfprintf , vprintf , vsprintf , atof , and strtod .
14094
1409581. A header is not necessarily a source file, nor are the < and >
14096delimited sequences in header names necessarily valid source file
14097names.
14098
1409982. The list of reserved external identifiers includes errno , setjmp ,
14100and va_end .
14101
1410283. The macro errno need not be the identifier of an object. It might
14103be a modifiable lvalue resulting from a function call (for example,
14104*errno() ).
14105
1410684. Thus, a program that uses errno for error checking should set it
14107to zero before a library function call, then inspect it before a
14108subsequent library function call.
14109
1411085. See ``future library directions'' ($4.13.1).
14111
1411286. This means that an implementation must provide an actual function
14113for each library function, even if it also provides a macro for that
14114function.
14115
1411687. Because external identifiers and some macro names beginning with
14117an underscore are reserved, implementations may provide special
14118semantics for such names. For example, the identifier _BUILTIN_abs
14119could be used to indicate generation of in-line code for the abs
14120function. Thus, the appropriate header could specify #define abs(x)
14121_BUILTIN_abs(x) for a compiler whose code generator will accept it.
14122In this manner, a user desiring to guarantee that a given library
14123function such as abs will be a genuine function may write #undef abs
14124whether the implementation's header provides a macro implementation of
14125abs or a builtin implementation. The prototype for the function,
14126which precedes and is hidden by any macro definition, is thereby
14127revealed also.
14128
1412988. The message written might be of the form Assertion failed: file
14130line
14131
1413289. See ``future library directions'' ($4.13.2).
14133
1413490. In an implementation that uses the seven-bit ASCII character set,
14135the printing characters are those whose values lie from 0x20 (space)
14136through 0x7E (tilde); the control characters are those whose values
14137lie from 0 (NUL) through 0x1F (US), and the character 0x7F (DEL).
14138
1413991. See ``future library directions'' ($4.13.3).
14140
1414192. The only functions in $4.3 whose behavior is not affected by the
14142current locale are isdigit and isxdigit .
14143
1414493. See ``future library directions'' ($4.13.4).
14145
1414694. In an implementation that supports infinities, this allows
14147infinity as an argument to be a domain error if the mathematical
14148domain of the function does not include infinity.
14149
1415095. These functions are useful for dealing with unusual conditions
14151encountered in a low-level function of a program.
14152
1415396. For example, by executing a return statement or because another
14154longjmp call has caused a transfer to a setjmp invocation in a
14155function earlier in the set of nested calls.
14156
1415797. See ``future library directions'' ($4.13.5). The names of the
14158signal numbers reflect the following terms (respectively): abort,
14159floating-point exception, illegal instruction, interrupt, segmentation
14160violation, and termination.
14161
1416298. Of course, the contents of the file name strings are subject to
14163other system-specific constraints.
14164
1416599. An implementation need not distinguish between text streams and
14166binary streams. In such an implementation, there need be no new-line
14167characters in a text stream nor any limit to the length of a line.
14168
14169100. This is described in the Base Document as a That term is not used
14170in this Standard to avoid confusion with a pointer to an object that
14171has type FILE .
14172
14173101. Among the reasons the implementation may cause the rename
14174function to fail are that the file is open or that it is necessary to
14175copy its contents to effectuate its renaming.
14176
14177102. Files created using strings generated by the tmpnam function are
14178temporary only in the sense that their names should not collide with
14179those generated by conventional naming rules for the implementation.
14180It is still necessary to use the remove function to remove such files
14181when their use is ended, and before program termination.
14182
14183103. Additional characters may follow these sequences.
14184
14185104. The primary use of the freopen function is to change the file
14186associated with a standard text stream ( stderr , stdin , or stdout ),
14187as those identifiers need not be modifiable lvalues to which the value
14188returned by the fopen function may be assigned.
14189
14190105. The buffer must have a lifetime at least as great as the open
14191stream, so the stream should be closed before a buffer that has
14192automatic storage duration is deallocated upon block exit.
14193
14194106. Note that 0 is taken as a flag, not as the beginning of a field
14195width.
14196
14197107. No special provisions are made for multibyte characters.
14198
14199108. See ``future library directions'' ($4.13.6).
14200
14201109. No special provisions are made for multibyte characters.
14202
14203110. See ``future library directions'' ($4.13.6).
14204
14205111. As vfprintf , vsprintf , and vprintf invoke the va_arg macro, the
14206value of arg after the return is indeterminate.
14207
14208112. An end-of-file and a read error can be distinguished by use of
14209the feof and ferror functions.
14210
14211113. See ``future library directions'' ($4.13.7).
14212
14213114. Note that this need not be the same as the representation of
14214floating-point zero or a null pointer constant.
14215
14216115. Each function is called as many times as it was registered.
14217
14218116. Notice that the key-to-member comparison an ordering on the
14219array.
14220
14221117. In a two's complement representation, the absolute value of the
14222most negative number cannot be represented.
14223
14224118. The array will not be null- or zero-terminated if the value
14225returned is n .
14226
14227119. See ``future library directions'' ($4.13.8).
14228
14229120. Thus, if there is no null character in the first n characters of
14230the array pointed to by s2 , the result will not be null-terminated.
14231
14232121. Thus the maximum number of characters that end up in the array
14233pointed to by s1 is strlen(s1)+n+1 .
14234
14235122. The contents of ``holes'' used as padding for purposes of
14236alignment within structure objects are indeterminate, unless the
14237contents of the entire object have been set explicitly, as by the
14238calloc or memset function. Strings shorter than their allocated space
14239and unions may also cause problems in comparison.
14240
14241123. The range [0, 60] for tm_sec allows for the occasional leap
14242second.
14243
14244124. Thus, a positive or zero value for tm_isdst causes the mktime
14245function initially to presume that Daylight Saving Time, respectively,
14246is or is not in effect for the specified time. A negative value for
14247tm_isdst causes the mktime function to attempt to determine whether
14248Daylight Saving Time is in effect for the specified time.