xref: /freebsd/share/man/man7/c.7 (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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 November 4, 2024
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 c23 ,
38.Nm c2y
39.Nd The C programming language
40.Sh DESCRIPTION
41C is a general purpose programming language, which has a strong connection
42with the UNIX operating system and its derivatives, since the vast
43majority of those systems were written in the C language.
44The C language contains some basic ideas from the BCPL language through
45the B language written by Ken Thompson in 1970 for the DEC PDP-7 machines.
46The development of the UNIX operating system was started on a PDP-7
47machine in assembly language, but it made very difficult to port the existing
48code to other systems.
49.Pp
50In 1972 Dennis M. Ritchie worked out the C programming language for
51further development of the UNIX operating system.
52The idea was to implement only the C compiler for different
53platforms, and implement most part of the operating system
54in the new programming language to simplify the portability between
55different architectures.
56It follows that C is very eligible for (but not limited to) writing
57operating systems and low-level applications.
58.Pp
59The C language did not have a specification or standardized version for
60a long time.
61It went through a lot of changes and improvements for ages.
62In 1978, Brian W. Kernighan and Dennis M. Ritchie published the
63first book about C under the title "The C Programming Language".
64We can think of this book as the first specification of the language.
65This version is often referred as K&R C after the names of the authors.
66Sometimes it is referred as C78, as well, after the publishing year of
67the first edition of the book.
68.Pp
69It is important to notice, that the instruction set of the language is
70limited to the most fundamental elements for simplicity.
71Handling of the standard I/O and such common functions are implemented in
72the libraries shipped with the compiler.
73As these functions are also widely used, it was demanded to include into
74the description what requisites the library should conform to, not just
75strictly the language itself.
76Accordingly, the aforementioned standards cover the library elements, as well.
77The elements of this standard library is still not enough for more
78complicated tasks.
79In this case the provided system calls of the given operating system can be
80used.
81To not lose the portability by using these system calls, the POSIX
82(Portable Operating System Interface) standard evolved.
83It describes what functions should be available to keep portability.
84Note, that POSIX is not a C standard, but an operating system standard
85and thus is beyond the scope of this manual.
86The standards discussed below are all C standards and only cover
87the C programming language and the accompanying library.
88All listed improvements for each standard edition are taken from the official
89standard drafts.
90For further details, check the publicly available drafts or
91purchase the published standards \(em from either ISO or IEC resources.
92.Pp
93After the publication of the book mentioned before,
94the American National Standards Institute (ANSI) started to work on
95standardizing the language, and they announced ANSI X3.159-1989
96in 1989.
97It is usually referred to as ANSI C or C89.
98The main difference in this standard were the function prototypes,
99which is a new way of declaring functions.
100With the old-style function declarations, the compiler was unable to
101check the sanity of the actual parameters at a function call.
102The old syntax was highly error-prone because incompatible parameters
103were hard to detect in the program code and the problem only showed up
104at run-time.
105.Pp
106In 1990, the International Organization for Standardization (ISO) adopted
107the ANSI standard as ISO/IEC 9899:1990 in 1990.
108This is also referred to as ISO C or C90.
109It only contains negligible minor modifications against ANSI C,
110so the two standards often considered to be fully equivalent.
111This was a very important milestone in the history of the C language, but the
112development of the language did not stop.
113.Pp
114The ISO C standard was later extended with an amendment as
115ISO/IEC 9899/AMD1 in 1995.
116This contained, for example, the wide-character support in
117.In wchar.h
118and
119.In wctype.h ,
120and also restricted character set support via diagraphs and
121.In iso646.h .
122This amendment is usually referred to as C95.
123Two technical corrigenda were also published: Technical Corrigendum 1 as
124ISO/IEC 9899/COR1 in 1994 and Technical Corrigendum 2 as ISO/IEC 9899/COR2
125in 1996.
126The continuous development and growth made it necessary to work out a new
127standard, which contains the new features and fixes the known defects and
128deficiencies of the language.
129As a result, ISO/IEC 9899:1999 was born in 1999 as the second edition of the
130standard.
131Similarly to the other standards, this is informally named after the
132publication year as C99.
133The improvements include (but are not limited to) the following:
134.Bl -bullet -offset indent
135.It
136digraphs, trigraphs, and alternative spellings for the operators that
137use non-ISO646 characters in
138.In iso646.h
139.It
140extended multibyte and wide character library support in
141.In wchar.h
142and
143.In wctype.h
144.It
145variable length arrays
146.It
147flexible array members
148.It
149complex (and imaginary) number arithmetic support in
150.In complex.h
151.It
152type-generic math macros in
153.In tgmath.h
154.It
155the long long int type and library functions
156.It
157remove implicit int type
158.It
159universal character names (\eu and \eU)
160.It
161compound literals
162.It
163remove implicit function declaration
164.It
165BCPL style single-line comments
166.It
167allow mixed declarations and code
168.It
169the
170.Fn vscanf
171family of functions in
172.In stdio.h
173and
174.In wchar.h
175.It
176allow trailing comma in enum declaration
177.It
178inline functions
179.It
180the
181.Fn snprintf
182family of functions in
183.In stdio.h
184.It
185boolean type and macros in
186.In stdbool.h
187.It
188empty macro arguments
189.It
190_Pragma preprocessing operator
191.It
192__func__ predefined identifier
193.It
194va_copy macro in
195.In stdarg.h
196.It
197additional strftime conversion specifiers
198.El
199.Pp
200Later in 2011, the third edition of the standard, ISO/IEC 1989:2011,
201commonly referred to as C11 (formerly C1x), came out and replaced the
202second edition by ISO/IEC 9899:1999/COR1:2001, ISO/IEC 9899:1999/COR2:2004,
203and ISO/IEC 9899:1999/COR3:2007.
204The improvements include (but are not limited to) the following:
205.Bl -bullet -offset indent
206.It
207support for multiple threads of execution and atomic operations in
208.In threads.h
209and
210.In stdatomic.h
211.It
212additional floating-point characteristic macros in
213.In float.h
214.It
215querying and specifying alignment of objects in
216.In stdalign.h
217and
218.In stdlib.h
219.It
220Unicode character types and functions in
221.In uchar.h
222.It
223type-generic expressions
224.It
225static assertions in
226.In assert.h
227.It
228anonymous structures and unions
229.It
230remove the gets function from
231.In stdio.h
232.It
233add the aligned_alloc, at_quick_exit, and quick_exit functions in
234.In stdlib.h
235.El
236.Pp
237C11 was later superseded by ISO/IEC 9899:2018, also known as C17 which was
238prepared in 2017 and published in June 2018 as the fourth edition.
239It incorporates the Technical Corrigendum 1 (ISO/IEC 9899:2011/COR1:2012)
240which was published in 2012.
241It addressed defects and deficiencies in C11 without introducing new features,
242only corrections and clarifications.
243.Pp
244C23, formally ISO/IEC 9899:2024, is the current standard with significant
245updates that supersede C17 (ISO/IEC 9899:2018).
246The standardization effort began in 2016, informally as C2x, with the first
247WG14 meeting in 2019, and was officially published on October 31, 2024.
248C23 was originally anticipated for an earlier release, but the timeline was
249extended due to COVID-19 pandemic.
250With C23, the value of __STDC_VERSION__ has been updated from 201710L to
251202311L.
252Key changes include (but are not limited to) the following:
253.Bl -bullet -offset indent
254.It
255Add null pointer type nullptr_t and the nullptr keyword
256.It
257Add constexpr keyword as a storage-class specifier for objects
258.It
259Redefine the usage of the auto keyword to support type inference while also
260retaining its previous functionality as a storage-class specifier when used
261with a type
262.It
263Add %b binary conversion specifier to the
264.Fn printf
265and
266.Fn scanf
267function families
268.It
269Add binary conversion support (0b and 0B) to the
270.Fn strtol
271and
272.Fn wcstol
273function families
274.It
275Add the #embed directive for binary resource inclusion and __has_embed to
276check resource availability with preprocessor directives
277.It
278Add the #warning directive for diagnostics
279.It
280Add the #elifdef and #elifndef directives
281.It
282Add the u8 prefix for character literals to represent UTF-8 encoding,
283compatible with C++17
284.It
285Add the char8_t type for UTF-8 encoded data and update the types of u8
286character constants and string literals to char8_t
287.It
288Add functions
289.Fn mbrtoc8
290and
291.Fn c8rtomb
292to convert between narrow multibyte
293characters and UTF-8 encoding
294.It
295Define all char16_t strings and literals as UTF-16 encoded and char32_t
296strings and literals as UTF-32 encoded unless specified otherwise
297.It
298Allow storage-class specifiers within compound literals
299.It
300Support the latest IEEE 754 standard, ISO/IEC 60559:2020, with binary and
301(optional) decimal floating-point arithmetic
302.It
303Add single-argument _Static_assert for compatibility with C++17
304.It
305Add _Decimal32, _Decimal64, _Decimal128 keywords for (optional) decimal
306floating-point arithmetic
307.It
308Add digit separator ' (the single quote character) for literals
309.It
310Enable specification of the underlying type of an enum
311.It
312Standardize the
313.Fn typeof
314operator
315.It
316Add
317.Fn memset_explicit
318in
319.In string.h
320to securely erase sensitive data
321regardless of optimizations
322.It
323Add
324.Fn memccpy
325in
326.In string.h
327for efficient string concatenation
328.It
329Add
330.Fn memalignment
331in
332.In stdlib.h
333to determine pointer alignment
334.It
335Add
336.Fn strdup
337and
338.Fn strndup
339in
340.In string.h
341to allocate string copies
342.It
343Introduce bit utility functions, macros, and types in the new header
344.In stdbit.h
345.It
346Add
347.Fn timegm
348in
349.In time.h
350for converting time structures to calendar time
351values
352.It
353Add __has_include for header availability checking via preprocessor
354directives
355.It
356Add __has_c_attribute to check attribute availability via preprocessor
357directives
358.It
359Add _BitInt(N) and unsigned _BitInt(N) for bit-precise integers, and
360BITINT_MAXWIDTH for maximum bit width
361.It
362Elevate true and false to proper keywords (previously macros from
363.In stdbool.h )
364.It
365Add keywords alignas, alignof, bool, static_assert, thread_local; previously
366defined keywords remain available as alternative spellings
367.It
368Enable zero initialization with {} (including initialization of VLAs)
369.It
370Introduce C++11 style attributes using [[]], with adding [[deprecated]],
371[[fallthrough]], [[maybe_unused]], [[nodiscard]], and [[noreturn]]
372.It
373Deprecate _Noreturn, noreturn, header
374.In stdnoreturn.h
375features introduced
376in C11
377.It
378Remove trigraph support
379.It
380Remove K&R function definitions and declarations
381.It
382Remove non-two's-complement representations for signed integers
383.El
384.Pp
385The next version of the C Standard, informally named C2y, is anticipated
386to release within the next six years, targeting 2030 at the latest.
387A charter for C2y is still being drafted and discussed, with several
388papers under debate from the January 2024 meeting in Strasbourg, France
389indicating that this new version may address long-standing requests and
390deficiencies noted by the C community, while preserving its core strengths.
391.Pp
392ISO/IEC JTC1/SC22/WG14 committee is responsible for the ISO/IEC 9899,
393C Standard.
394.Sh SEE ALSO
395.Xr c89 1 ,
396.Xr c99 1 ,
397.Xr cc 1
398.Sh STANDARDS
399.Rs
400.%A ANSI
401.%T X3.159-1989 (aka C89 or ANSI C)
402.Re
403.Pp
404.Rs
405.%A ISO/IEC
406.%T 9899:1990 (aka C90)
407.Re
408.Pp
409.Rs
410.%A ISO/IEC
411.%T 9899:1990/AMD 1:1995, Amendment 1: C Integrity (aka C95)
412.Re
413.Pp
414.Rs
415.%A ISO/IEC
416.%T 9899:1990/COR 1:1994, Technical Corrigendum 1
417.Re
418.Pp
419.Rs
420.%A ISO/IEC
421.%T 9899:1990/COR 2:1996, Technical Corrigendum 2
422.Re
423.Pp
424.Rs
425.%A ISO/IEC
426.%T 9899:1999 (aka C99)
427.Re
428.Pp
429.Rs
430.%A ISO/IEC
431.%T 9899:1999/COR 1:2001, Technical Corrigendum 1
432.Re
433.Pp
434.Rs
435.%A ISO/IEC
436.%T 9899:1999/COR 2:2004, Technical Corrigendum 2
437.Re
438.Pp
439.Rs
440.%A ISO/IEC
441.%T 9899:1999/COR 3:2007, Technical Corrigendum 3
442.Re
443.Pp
444.Rs
445.%A ISO/IEC
446.%T TR 24731-1:2007 (aka bounds-checking interfaces)
447.Re
448.Pp
449.Rs
450.%A ISO/IEC
451.%T TS 18037:2008 (aka, embedded C)
452.Re
453.Pp
454.Rs
455.%A ISO/IEC
456.%T TR 24747:2009 (aka mathematical special functions)
457.Re
458.Pp
459.Rs
460.%A ISO/IEC
461.%T TR 24732:2009 (aka decimal floating-point)
462.Re
463.Pp
464.Rs
465.%A ISO/IEC
466.%T TR 24731-2:2010 (aka dynamic allocation functions)
467.Re
468.Pp
469.Rs
470.%A ISO/IEC
471.%T 9899:2011 (aka C11)
472.Re
473.Pp
474.Rs
475.%A ISO/IEC
476.%T 9899:2011/COR 1:2012, Technical Corrigendum 1
477.Re
478.Pp
479.Rs
480.%A ISO/IEC
481.%T TS 17961:2013 (aka C secure coding rules)
482.Re
483.Pp
484.Rs
485.%A ISO/IEC
486.%T TS 18861-1:2014 (aka binary floating-point)
487.Re
488.Pp
489.Rs
490.%A ISO/IEC
491.%T TS 18861-2:2015 (aka decimal floating-point)
492.Re
493.Pp
494.Rs
495.%A ISO/IEC
496.%T TS 18861-3:2015 (aka interchange and extended types)
497.Re
498.Pp
499.Rs
500.%A ISO/IEC
501.%T TS 18861-4:2015 (aka supplementary functions)
502.Re
503.Pp
504.Rs
505.%A ISO/IEC
506.%T TS 17961:2013/COR 1:2016 (aka C secure coding rules TC1)
507.Re
508.Pp
509.Rs
510.%A ISO/IEC
511.%T TS 18861-5:2016 (aka supplementary attributes)
512.Re
513.Pp
514.Rs
515.%A ISO/IEC
516.%T 9899:2018 (aka C17)
517.Re
518.Pp
519.Rs
520.%A ISO/IEC
521.%T 9899:2024 (aka C23)
522.Re
523.Sh HISTORY
524This manual page first appeared in
525.Fx 9.0 .
526.Sh AUTHORS
527.An -nosplit
528This manual page was originally written by
529.An Gabor Kovesdan Aq Mt gabor@FreeBSD.org .
530It was updated by
531.An Faraz Vahedi Aq Mt kfv@kfv.io
532with information about more recent C standards.
533