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