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