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