xref: /freebsd/share/man/man7/c.7 (revision 18054d0220cfc8df9c9568c437bd6fbb59d53c3c)
1.\" Copyright (C) 2007, 2010 Gabor Kovesdan. All rights reserved.
2.\" Copyright (C) 2021 Faraz Vahedi <kfv@kfv.io>
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd April 20, 2021
28.Dt C 7
29.Os
30.Sh NAME
31.Nm c ,
32.Nm c78 ,
33.Nm c89 ,
34.Nm c90 ,
35.Nm c95 ,
36.Nm c99 ,
37.Nm c11 ,
38.Nm c17 ,
39.Nm c2x
40.Nd The C programming language
41.Sh DESCRIPTION
42C is a general purpose programming language, which has a strong connection
43with the UNIX operating system and its derivatives, since the vast
44majority of those systems were written in the C language.
45The C language contains some basic ideas from the BCPL language through
46the B language written by Ken Thompson in 1970 for the DEC PDP-7 machines.
47The development of the UNIX operating system was started on a PDP-7
48machine in assembly language, but it made very difficult to port the existing
49code to other systems.
50.Pp
51In 1972 Dennis M. Ritchie worked out the C programming language for
52further development of the UNIX operating system.
53The idea was to implement only the C compiler for different
54platforms, and implement most part of the operating system
55in the new programming language to simplify the portability between
56different architectures.
57It follows that C is very eligible for (but not limited to) writing
58operating systems and low-level applications.
59.Pp
60The C language did not have a specification or standardized version for
61a long time.
62It went through a lot of changes and improvements for ages.
63In 1978, Brian W. Kernighan and Dennis M. Ritchie published the
64first book about C under the title "The C Programming Language".
65We can think of this book as the first specification of the language.
66This version is often referred as K&R C after the names of the authors.
67Sometimes it is referred as C78, as well, after the publishing year of
68the first edition of the book.
69.Pp
70It is important to notice, that the instruction set of the language is
71limited to the most fundamental elements for simplicity.
72Handling of the standard I/O and such common functions are implemented in
73the libraries shipped with the compiler.
74As these functions are also widely used, it was demanded to include into
75the description what requisites the library should conform to, not just
76strictly the language itself.
77Accordingly, the aforementioned standards cover the library elements, as well.
78The elements of this standard library is still not enough for more
79complicated tasks.
80In this case the provided system calls of the given operating system can be
81used.
82To not lose the portability by using these system calls, the POSIX
83(Portable Operating System Interface) standard evolved.
84It describes what functions should be available to keep portability.
85Note, that POSIX is not a C standard, but an operating system standard
86and thus is beyond the scope of this manual.
87The standards discussed below are all C standards and only cover
88the C programming language and the accompanying library.
89All listed improvements for each standard edition are taken from the official
90standard drafts.
91For further details, check the publicly available drafts or
92purchase the published standards \(em from either ISO or IEC resources.
93.Pp
94After the publication of the book mentioned before,
95the American National Standards Institute (ANSI) started to work on
96standardizing the language, and they announced ANSI X3.159-1989
97in 1989.
98It is usually referred to as ANSI C or C89.
99The main difference in this standard were the function prototypes,
100which is a new way of declaring functions.
101With the old-style function declarations, the compiler was unable to
102check the sanity of the actual parameters at a function call.
103The old syntax was highly error-prone because incompatible parameters
104were hard to detect in the program code and the problem only showed up
105at run-time.
106.Pp
107In 1990, the International Organization for Standardization (ISO) adopted
108the ANSI standard as ISO/IEC 9899:1990 in 1990.
109This is also referred to as ISO C or C90.
110It only contains negligible minor modifications against ANSI C,
111so the two standards often considered to be fully equivalent.
112This was a very important milestone in the history of the C language, but the
113development of the language did not stop.
114.Pp
115The ISO C standard was later extended with an amendment as
116ISO/IEC 9899/AMD1 in 1995.
117This contained, for example, the wide-character support in <wchar.h> and
118<wctype.h>, and also restricted character set support via diagraphs and
119<iso646.h>.
120This amendment is usually referred to as C95.
121Two technical corrigenda were also published: Technical Corrigendum 1 as
122ISO/IEC 9899/COR1 in 1994 and Technical Corrigendum 2 as ISO/IEC 9899/COR2
123in 1996.
124The continuous development and growth made it necessary to work out a new
125standard, which contains the new features and fixes the known defects and
126deficiencies of the language.
127As a result, ISO/IEC 9899:1999 was born in 1999 as the second edition of the
128standard.
129Similarly to the other standards, this is informally named after the
130publication year as C99.
131The improvements include (but are not limited to) the following:
132.Bl -bullet -offset indent
133.It
134digraphs, trigraphs, and alternative spellings for the operators that
135use non-ISO646 characters in <iso646.h>
136.It
137extended multibyte and wide character library support in <wchar.h> and
138<wctype.h>
139.It
140variable length arrays
141.It
142flexible array members
143.It
144complex (and imaginary) number arithmetic support in <complex.h>
145.It
146type-generic math macros in <tgmath.h>
147.It
148the long long int type and library functions
149.It
150remove implicit int type
151.It
152universal character names (\eu and \eU)
153.It
154compound literals
155.It
156remove implicit function declaration
157.It
158BCPL style single-line comments
159.It
160allow mixed declarations and code
161.It
162the vscanf family of functions in <stdio.h> and <wchar.h>
163.It
164allow trailing comma in enum declaration
165.It
166inline functions
167.It
168the snprintf family of functions in <stdio.h>
169.It
170boolean type and macros in <stdbool.h>
171.It
172empty macro arguments
173.It
174_Pragma preprocessing operator
175.It
176__func__ predefined identifier
177.It
178va_copy macro in <stdarg.h>
179.It
180additional strftime conversion specifiers
181.El
182.Pp
183Later in 2011, the third edition of the standard, ISO/IEC 1989:2011,
184commonly referred to as C11 (formerly C1x), came out and replaced the
185second edition by ISO/IEC 9899:1999/COR1:2001, ISO/IEC 9899:1999/COR2:2004,
186and ISO/IEC 9899:1999/COR3:2007.
187The improvements include (but are not limited to) the following:
188.Bl -bullet -offset indent
189.It
190support for multiple threads of execution and atomic operations in <threads.h>
191and <stdatomic.h>
192.It
193additional floating-point characteristic macros in <float.h>
194.It
195querying and specifying alignment of objects in <stdalign.h> and <stdlib.h>
196.It
197Unicode character types and functions in <uchar.h>
198.It
199type-generic expressions
200.It
201static assertions in <assert.h>
202.It
203anonymous structures and unions
204.It
205remove the gets function from <stdio.h>
206.It
207add the aligned_alloc, at_quick_exit, and quick_exit functions in <stdlib.h>
208.El
209.Pp
210C11 was later superseded by ISO/IEC 9899:2018, also known as C17 which was
211prepared in 2017 and published in June 2018 as the fourth edition.
212It incorporates the Technical Corrigendum 1 (ISO/IEC 9899:2011/COR1:2012)
213which was published in 2012.
214It addressed defects and deficiencies in C11 without introducing new features,
215only corrections and clarifications.
216Since there were no major changes in C17, the current standard for
217Programming Language C, is still considered C11 \(em ISO/IEC 9899:2011, published
2182011-12-08.
219.Pp
220The next standard, the fifth, is currently referred to as C2x and is scheduled
221to be adopted by the end of 2021, with a publication date of 2022.
222When published, it will cancel and replace the fourth edition, ISO/IEC
2239899:2018.
224.Pp
225Some useful features have been provided as extensions by some compilers, but
226they cannot be considered as standard features.
227.Pp
228ISO/IEC JTC1/SC22/WG14 committee is responsible for the ISO/IEC 9899,
229C Standard.
230.Sh SEE ALSO
231.Xr c89 1 ,
232.Xr c99 1 ,
233.Xr cc 1
234.Sh STANDARDS
235.Rs
236.%A ANSI
237.%T X3.159-1989 (aka C89 or ANSI C)
238.Re
239.Pp
240.Rs
241.%A ISO/IEC
242.%T 9899:1990 (aka C90)
243.Re
244.Pp
245.Rs
246.%A ISO/IEC
247.%T 9899:1990/AMD 1:1995, Amendment 1: C Integrity (aka C95)
248.Re
249.Pp
250.Rs
251.%A ISO/IEC
252.%T 9899:1990/COR 1:1994, Technical Corrigendum 1
253.Re
254.Pp
255.Rs
256.%A ISO/IEC
257.%T 9899:1990/COR 2:1996, Technical Corrigendum 2
258.Re
259.Pp
260.Rs
261.%A ISO/IEC
262.%T 9899:1999 (aka C99)
263.Re
264.Pp
265.Rs
266.%A ISO/IEC
267.%T 9899:1999/COR 1:2001, Technical Corrigendum 1
268.Re
269.Pp
270.Rs
271.%A ISO/IEC
272.%T 9899:1999/COR 2:2004, Technical Corrigendum 2
273.Re
274.Pp
275.Rs
276.%A ISO/IEC
277.%T 9899:1999/COR 3:2007, Technical Corrigendum 3
278.Re
279.Pp
280.Rs
281.%A ISO/IEC
282.%T TR 24731-1:2007 (aka bounds-checking interfaces)
283.Re
284.Pp
285.Rs
286.%A ISO/IEC
287.%T TS 18037:2008 (aka, embedded C)
288.Re
289.Pp
290.Rs
291.%A ISO/IEC
292.%T TR 24747:2009 (aka mathematical special functions)
293.Re
294.Pp
295.Rs
296.%A ISO/IEC
297.%T TR 24732:2009 (aka decimal floating-point)
298.Re
299.Pp
300.Rs
301.%A ISO/IEC
302.%T TR 24731-2:2010 (aka dynamic allocation functions)
303.Re
304.Pp
305.Rs
306.%A ISO/IEC
307.%T 9899:2011 (aka C11)
308.Re
309.Pp
310.Rs
311.%A ISO/IEC
312.%T 9899:2011/COR 1:2012, Technical Corrigendum 1
313.Re
314.Pp
315.Rs
316.%A ISO/IEC
317.%T TS 17961:2013 (aka C secure coding rules)
318.Re
319.Pp
320.Rs
321.%A ISO/IEC
322.%T TS 18861-1:2014 (aka binary floating-point)
323.Re
324.Pp
325.Rs
326.%A ISO/IEC
327.%T TS 18861-2:2015 (aka decimal floating-point)
328.Re
329.Pp
330.Rs
331.%A ISO/IEC
332.%T TS 18861-3:2015 (aka interchange and extended types)
333.Re
334.Pp
335.Rs
336.%A ISO/IEC
337.%T TS 18861-4:2015 (aka supplementary functions)
338.Re
339.Pp
340.Rs
341.%A ISO/IEC
342.%T TS 17961:2013/COR 1:2016 (aka C secure coding rules TC1)
343.Re
344.Pp
345.Rs
346.%A ISO/IEC
347.%T TS 18861-5:2016 (aka supplementary attributes)
348.Re
349.Pp
350.Rs
351.%A ISO/IEC
352.%T 9899:2018 (aka C17)
353.Re
354.Sh HISTORY
355This manual page first appeared in
356.Fx 9.0 .
357.Sh AUTHORS
358.An -nosplit
359This manual page was originally written by
360.An Gabor Kovesdan Aq Mt gabor@FreeBSD.org .
361It was updated for
362.Fx 14.0
363by
364.An Faraz Vahedi Aq Mt kfv@kfv.io
365with information about more recent C standards.
366