xref: /freebsd/share/man/man9/cdefs.9 (revision cfd8866818abb68fbfbffb925298c0b457cb32b5)
14122295aSWarner Losh.\"-
24122295aSWarner Losh.\" Copyright (c) 2024 M. Warner Losh <imp@FreeBSD.org>
34122295aSWarner Losh.\"
44122295aSWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause
54122295aSWarner Losh.\"
66fc164c7SWarner Losh.Dd January 6, 2025
74122295aSWarner Losh.Dt CDEFS 9
84122295aSWarner Losh.Os
94122295aSWarner Losh.Sh NAME
104122295aSWarner Losh.Nm cdefs
114122295aSWarner Losh.Nd compiler portability macro definitions
124122295aSWarner Losh.Sh DESCRIPTION
134122295aSWarner Losh.In sys/cdefs.h
144122295aSWarner Loshdefines macros for compiler, C language standard portability, POSIX standards
154122295aSWarner Loshcompliance and symbol visibility.
164122295aSWarner LoshIt defines programming interfaces for the system header files to adopt to the
174122295aSWarner Loshmany environments
184122295aSWarner Losh.Fx
194122295aSWarner Loshsupports compilation for.
204122295aSWarner LoshIt defines convenience macros for the
214122295aSWarner Losh.Fx
224122295aSWarner Loshsources, tailored to the base
234122295aSWarner Loshsystem's needs.
244122295aSWarner Losh.Pp
254122295aSWarner LoshMost of these macros are for use inside the
264122295aSWarner Losh.Fx
274122295aSWarner Loshsources only.
284122295aSWarner LoshThey are not intended as a general portability layer.
294122295aSWarner Losh.Sh Supported Compilers
304122295aSWarner Losh.Bl -tag -offset 2n -width 0
314122295aSWarner Losh.It Compilers supported for building programs on Fx :
324122295aSWarner Losh.Bl -column -offset 0n indent-two
334122295aSWarner Losh.It Sy Compiler Ta Sy Versions
344122295aSWarner Losh.It gcc Ta 9, 10, 11, 12, 13, 14
354122295aSWarner Losh.It clang Ta 10, 11, 12, 13, 14, 15, 16, 17, 18
364122295aSWarner Losh.It TinyC (tcc) Ta 0.9
374122295aSWarner Losh.It pcc Ta 1.1
384122295aSWarner Losh.El
394122295aSWarner Losh.Pp
404122295aSWarner LoshDue to testing constraints, tcc and pcc may not always work.
414122295aSWarner Losh.It Compilers supported for building Fx itself:
424122295aSWarner Losh.Bl -column -offset 0n indent-two
43f7331f4eSWarner Losh.It Sy Compiler Ta Sy Major Versions Supported
44f7331f4eSWarner Losh.It gcc Ta 12, 13, 14
45f7331f4eSWarner Losh.It clang Ta 16, 17, 18
464122295aSWarner Losh.El
47f7331f4eSWarner Losh.Pp
48f7331f4eSWarner LoshPlease note: Not every single minor versions of these compilers
49f7331f4eSWarner Loshwill work or are supported.
50229381deSGraham Percival.El
514122295aSWarner Losh.Sh Macros and Magic for Programming Environment
524122295aSWarner Losh.Nm
534122295aSWarner Loshdefines (or refrains from defining) a number of macros to increase portability
544122295aSWarner Loshof compiled programs.
554122295aSWarner LoshThese are to allow more advanced language features to appear in header files.
564122295aSWarner LoshThe header files assume a compiler that accepts C prototype function
574122295aSWarner Loshdeclarations.
584122295aSWarner LoshThey also assume that the compiler accepts ANSI C89 keywords for all language
594122295aSWarner Loshdialects.
604122295aSWarner Losh.Ss General Macros
614122295aSWarner LoshGeneral macros that facilitate multiple language environments and language
624122295aSWarner Loshdialects.
634122295aSWarner Losh.Bl -column "---------------"
644122295aSWarner Losh.It Sy Macro Ta Sy Description
654122295aSWarner Losh.It Dv __volatile Ta expands to volatile in C++ and C89 and newer environments,
664122295aSWarner Losh__volatile in pre-ANSI environments that support this extension or nothing
674122295aSWarner Loshotherwise.
684122295aSWarner Losh.It Dv __inline Ta expands to inline in C++ and C89 and newer environments,
694122295aSWarner Losh__inline in pre-ANSI environments that support this extension or nothing
704122295aSWarner Loshotherwise.
714122295aSWarner Losh.It Dv __restrict Ta expands to restrict in C99 and newer environments, or
724122295aSWarner Losh__restrict otherwise.
734122295aSWarner Losh.It Dv __CONCAT Ta used to paste two pre-processor tokens.
744122295aSWarner Losh.It Dv __STRING Ta used to convert the argument to a string.
754122295aSWarner Losh.It Dv __BEGIN_DECLS Ta Start a group of functions.
764122295aSWarner Losh.It Dv __END_DECLS Ta End a group of functions.
774122295aSWarner LoshIn a C environment, these are defined as nothing.
784122295aSWarner LoshIn a C++ environment, these declare the functions to have
794122295aSWarner Losh.Dq C
804122295aSWarner Loshlinkage.
814122295aSWarner Losh.El
824122295aSWarner Losh.Ss Function, Structure and Variable Modifiers
834122295aSWarner Losh.Bl -column "---------------"
844122295aSWarner Losh.It Sy Macro Ta Sy Description
854122295aSWarner Losh.It Sy __weak_symbol Ta Declare the symbol to be a weak symbol
864122295aSWarner Losh.It Sy __dead2 Ta Function will not return
874122295aSWarner Losh.It Sy __pure2 Ta Function has no side effects
8816672453SWarner Losh.It Sy __unused Ta To Variable may be unused (usually arguments), so do not
8916672453SWarner Loshwarn about it
904122295aSWarner Losh.It Sy __used Ta Function really is used, so emit it even if it appears unused.
9116672453SWarner Losh.It Sy __deprecated Ta Function interface has been deprecated, and clients
9216672453SWarner Loshshould migrate to a new interface.
9316672453SWarner LoshA warning will be issued for clients of this interface.
946da04bcfSJohn Baldwin.It Sy __deprecated1(msg) Ta Function interface has been deprecated, and clients
956da04bcfSJohn Baldwinshould migrate to a new interface.
966da04bcfSJohn BaldwinThe string
976da04bcfSJohn Baldwin.Fa msg
986da04bcfSJohn Baldwinwill be included in a warning issued for clients of this interface.
994122295aSWarner Losh.It Sy __packed Ta \&Do not have space between structure elements for natural alignment.
1004122295aSWarner LoshUsed when communicating with external protocols.
1014122295aSWarner Losh.It Sy __aligned(x) Ta Specify in bytes the minimum alignment for the specified field, structure or variable
1024122295aSWarner Losh.It Sy __section(x) Ta Place function or variable in section Fa x
1034122295aSWarner Losh.It Sy __writeonly Ta Hint that the variable is only assigned to, but do not warn about it.
1044122295aSWarner LoshUseful for macros and other places the eventual use of the result is unknown.
1054122295aSWarner Losh.It Sy __alloc_size(x) Ta The function always returns at least the number of
1064122295aSWarner Loshbytes determined by argument number Fa x
1074122295aSWarner Losh.It Sy __alloc_size2(x,n) Ta  The function always returns an array, whose size
1084122295aSWarner Loshis at least the number of bytes determined by argument number Fa x times the
1094122295aSWarner Loshnumber of elements specified by argument number Fa n
1104122295aSWarner Losh.It Sy __alloc_align(x) Ta Function either returns a pointer aligned to Fa x bytes
1114122295aSWarner Loshor Dv NULL.
1124122295aSWarner Losh.It Sy __min_size Ta Declare the array to have a certain, minimum size
1134122295aSWarner Losh.It Sy __malloc_like Ta Function behaves like the
1144122295aSWarner Losh.Dq malloc
1154122295aSWarner Loshfamily of functions.
1164122295aSWarner Losh.It Sy __pure Ta Function has no side effects
1174122295aSWarner Losh.It Sy __always_inline Ta Always inline this function when called
1184122295aSWarner Losh.It Sy __fastcall Ta Use the
1194122295aSWarner Losh.Dq fastcall
1204122295aSWarner LoshABI to call and name mangle this function.
1214122295aSWarner Losh.It Sy __result_use_check Ta Warn if function caller does not use it's return value
1224122295aSWarner Losh.It Sy __result_use_or_ignore_check Ta Warn if function caller does not use it's return value.
1234122295aSWarner LoshAllows the value to be explicitly ignored with a (void) cast.
1244122295aSWarner Losh.It Sy __returns_twice Ta Returns multiple times, like
1254122295aSWarner Losh.Xr fork 2
1264122295aSWarner Losh.It Sy __unreachable Ta This code is not reachable at runtime
1274122295aSWarner Losh.It Sy __predict_true(x) Ta Hint to the compiler that
1284122295aSWarner Losh.Fa x
1294122295aSWarner Loshis true most of the time.
1304122295aSWarner LoshShould only be used when performance is improved for a frequently called bit of code.
1314122295aSWarner Losh.It Sy __predict_false(x) Ta Hint to the compiler that
1324122295aSWarner Losh.Fa x
1334122295aSWarner Loshis false most of the time.
1344122295aSWarner LoshShould only be used when performance is improved for a frequently called bit of code.
1354122295aSWarner Losh.It Sy __null_sentinel Ta The varadic function contains a parameter that is
1364122295aSWarner Losha NULL sentinel to mark the end of its arguments.
1374122295aSWarner Losh.It Sy __exported Ta
1384122295aSWarner Losh.It Sy __hidden Ta
1394122295aSWarner Losh.It Sy __printflike(fmtarg,firstvararg) Ta Function is similar to
1404122295aSWarner Losh.Fn printf
1414122295aSWarner Loshwhich specifies the format argument with
1424122295aSWarner Losh.Fa fmtarg
1434122295aSWarner Loshand where the arguments formatted by that format start with the
1444122295aSWarner Losh.Fa firstvararg ,
1454122295aSWarner Loshwith 0 meaning that
1464122295aSWarner Losh.Dv va_arg
1474122295aSWarner Loshis used and cannot be checked.
1484122295aSWarner Losh.It Sy __scanflike(fmtarg,firstvararg) Ta Function is similar to
1494122295aSWarner Losh.Fn scanf
1504122295aSWarner Loshwhich specifies the format argument with
1514122295aSWarner Losh.Fa fmtarg
1524122295aSWarner Loshand where the arguments formatted by that format start with the
1534122295aSWarner Losh.Fa firstvararg ,
1544122295aSWarner Loshwith 0 meaning that
1554122295aSWarner Losh.Dv va_arg
1564122295aSWarner Loshis used and cannot be checked.
1574122295aSWarner Losh.It Sy __format_arg(f) Ta Specifies that arg
1584122295aSWarner Losh.Fa f
1594122295aSWarner Loshcontains a string that will be passed to a function like
1604122295aSWarner Losh.Fn printf
1614122295aSWarner Loshor
1624122295aSWarner Losh.Fa scanf
1634122295aSWarner Loshafter being translated in some way.
1644122295aSWarner Losh.It Sy __strfmonlike(fmtarg,firstvararg) Ta Function is similar to
1654122295aSWarner Losh.Fn scanf
1664122295aSWarner Loshwhich specifies the format argument with
1674122295aSWarner Losh.Fa fmtarg
1684122295aSWarner Loshand where the arguments formatted by that format start with the
1694122295aSWarner Losh.Fa firstvararg ,
1704122295aSWarner Loshwith 0 meaning that
1714122295aSWarner Losh.Dv va_arg
1724122295aSWarner Loshis used and cannot be checked.
1734122295aSWarner Losh.It Sy __strtimelike(fmtarg,firstvararg) Ta Function is similar to
1744122295aSWarner Losh.Fn scanf
1754122295aSWarner Loshwhich specifies the format argument with
1764122295aSWarner Losh.Fa fmtarg
1774122295aSWarner Loshand where the arguments formatted by that format start with the
1784122295aSWarner Losh.Fa firstvararg ,
1794122295aSWarner Loshwith 0 meaning that
1804122295aSWarner Losh.Dv va_arg
1814122295aSWarner Loshis used and cannot be checked.
1824122295aSWarner Losh.It Sy __printf0like(fmtarg,firstvararg) Ta Exactly the same
1834122295aSWarner Loshas
1844122295aSWarner Losh.Sy __printflike
1854122295aSWarner Loshexcept
1864122295aSWarner Losh.Fa fmtarg
1874122295aSWarner Loshmay be
1884122295aSWarner Losh.Dv NULL.
1894122295aSWarner Losh.It Sy __strong_reference(sym,aliassym) Ta
1904122295aSWarner Losh.It Sy __weak_reference(sym,alias) Ta
1914122295aSWarner Losh.It Sy __warn_references(sym,msg) Ta
1924122295aSWarner Losh.It Sy __sym_compat(sym,impl,verid) Ta
1934122295aSWarner Losh.It Sy __sym_default(sym,impl,verid) Ta
1944122295aSWarner Losh.It Sy __GLOBAL(sym) Ta
1954122295aSWarner Losh.It Sy __WEAK(sym) Ta
1964122295aSWarner Losh.It Sy __DECONST(type,var) Ta
1974122295aSWarner Losh.It Sy __DEVOLATILE(type,var) Ta
1984122295aSWarner Losh.It Sy __DEQUALIFY(type,var) Ta
1994122295aSWarner Losh.It Sy __RENAME(x) Ta
2004122295aSWarner Losh.It Sy __arg_type_tag Ta
2014122295aSWarner Losh.It Sy __datatype_type_tag Ta
2024122295aSWarner Losh.It Sy __align_up(x,y) Ta
2034122295aSWarner Losh.It Sy __align_down(x,y) Ta
2044122295aSWarner Losh.It Sy __is_aligned(x,y) Ta
2054122295aSWarner Losh.El
2064122295aSWarner Losh.Ss Locking and Debugging Macros
2074122295aSWarner LoshMacros for lock annotation and debugging, as well as some general debugging
2084122295aSWarner Loshmacros for address sanitizers.
2094122295aSWarner Losh.Bl -column "---------------"
2104122295aSWarner Losh.It Sy __lock_annotate(x) Ta
2114122295aSWarner Losh.It Sy __lockable Ta
2124122295aSWarner Losh.It Sy __locks_exclusive Ta
2134122295aSWarner Losh.It Sy __locks_shared Ta
2144122295aSWarner Losh.It Sy __trylocks_exclusive Ta
2154122295aSWarner Losh.It Sy __trylocks_shared Ta
2164122295aSWarner Losh.It Sy __unlocks Ta
2174122295aSWarner Losh.It Sy __asserts_exclusive Ta
2184122295aSWarner Losh.It Sy __asserts_shared Ta
2194122295aSWarner Losh.It Sy __requires_exclusive Ta
2204122295aSWarner Losh.It Sy __requires_shared Ta
2214122295aSWarner Losh.It Sy __requires_unlocked Ta
2224122295aSWarner Losh.It Sy __no_lock_analysis Ta
2234122295aSWarner Losh.It Sy __nosanitizeaddress Ta
2244122295aSWarner Losh.It Sy __nosanitizememory Ta
2254122295aSWarner Losh.It Sy __nosanitizethread Ta
2264122295aSWarner Losh.It Sy __nostackprotector Ta
2274122295aSWarner Losh.It Sy __guarded_by(x) Ta
2284122295aSWarner Losh.It Sy __pt_guarded_by(x) Ta
2294122295aSWarner Losh.El
2304122295aSWarner Losh.Ss Emulated Keywords
2314122295aSWarner LoshAs C evolves, many of the old macros we once used have been incorporated into
2324122295aSWarner Loshthe standard language.
2334122295aSWarner LoshAs this happens, we add support for these keywords as macros for older
2344122295aSWarner Loshcompilation environments.
2354122295aSWarner LoshSometimes this results in a nop in the older environment.
2364122295aSWarner Losh.Bl -column "---------------"
2374122295aSWarner Losh.It Sy Keyword Ta Sy Description
2384122295aSWarner Losh.It Sy _Alignas(x) Ta
2394122295aSWarner Losh.It Sy _Alignof(x) Ta
2404122295aSWarner Losh.It Sy _Noreturn Ta Expands to
2414122295aSWarner Losh.Dq [[noreturn]]
2424122295aSWarner Loshin C++-11 and newer compilation environments, otherwise
2434122295aSWarner Losh.Dq __dead2
2444122295aSWarner Losh.It Sy _Static_assert(x, y) Ta Compile time assertion that
2454122295aSWarner Losh.Fa x
2464122295aSWarner Loshis true, otherwise emit
2474122295aSWarner Losh.Fa y
2484122295aSWarner Loshas the error message.
2494122295aSWarner Losh.It Sy _Thread_local Ta Designate variable as thread local storage
2504122295aSWarner Losh.It Sy __generic Ta implement _Generic-like features which aren't entirely possible to emulate the _Generic keyword
2514122295aSWarner Losh.It Sy __noexcept Ta to emulate the C++11 argument-less noexcept form
2524122295aSWarner Losh.It Sy __noexcept_if Ta to emulate the C++11 conditional noexcept form
2534122295aSWarner Losh.It Sy _Nonnull Ta
2544122295aSWarner Losh.It Sy _Nullable Ta
2554122295aSWarner Losh.It Sy _Null_unspecified Ta
2564122295aSWarner Losh.El
2574122295aSWarner Losh.Ss Support Macros
2584122295aSWarner LoshThe following macros are defined, or have specific values, to denote certain
2594122295aSWarner Loshthings about the build environment.
2604122295aSWarner Losh.Bl -column "---------------"
2614122295aSWarner Losh.It Sy Macro Ta Sy Description
2624122295aSWarner Losh.It Sy __LONG_LONG_SUPPORTED Ta Variables may be declared
2634122295aSWarner Losh.Dq long long .
2644122295aSWarner LoshThis is defined for C99 or newer and C++ environments.
2654122295aSWarner Losh.It Sy __STDC_LIMIT_MACROS Ta
2664122295aSWarner Losh.It Sy __STDC_CONSTANT_MACROS Ta
2674122295aSWarner Losh.El
2684122295aSWarner Losh.Ss Convenience Macros
2694122295aSWarner LoshThese macros make it easier to do a number of things, even though strictly
2704122295aSWarner Loshspeaking the standard places their normal form in another header.
2714122295aSWarner Losh.Bl -column "---------------"
2724122295aSWarner Losh.It Sy Macro Ta Sy Description
2734122295aSWarner Losh.It Sy __offsetof(type,field) Ta
2744122295aSWarner Losh.It Sy __rangeof(type,start,end) Ta
2754122295aSWarner Losh.It Sy __containerof(x,s,m) Ta
2764122295aSWarner Losh.El
2774122295aSWarner Losh.Ss ID Strings
2784122295aSWarner LoshThis section is deprecated, but is kept around because too much contrib software
2794122295aSWarner Loshstill uses these.
2804122295aSWarner Losh.Bl -column "---------------"
2814122295aSWarner Losh.It Sy Macro Ta Sy Description
2824122295aSWarner Losh.It Sy __IDSTRING(name,string) Ta
2834122295aSWarner Losh.It Sy __FBSDID(s) Ta
2844122295aSWarner Losh.It Sy __RCSID(s) Ta
2854122295aSWarner Losh.It Sy __RCSID_SOURCE(s) Ta
2864122295aSWarner Losh.It Sy __SCCSID(s) Ta
2874122295aSWarner Losh.It Sy __COPYRIGHT(s) Ta
2884122295aSWarner Losh.El
2894122295aSWarner Losh.Sh Supported C Environments
2904122295aSWarner Losh.Fx
2914122295aSWarner Loshsupports a number C standard environments.
2924122295aSWarner LoshSelection of the language dialect is a compiler-dependent command line option,
2934122295aSWarner Loshthough it is usually
294eaa3d34bSWarner Losh.Fl std=XX
2954122295aSWarner Loshwhere XX is the standard to set for compiling, such as c89 or c23.
2964122295aSWarner Losh.Fx
2974122295aSWarner Loshprovides a number of selection macros to control visibility of symbols.
2984122295aSWarner LoshPlease see the section on Selection Macros for the specifics.
2994122295aSWarner Losh.Pp
3004122295aSWarner Losh.Bl -tag
3014122295aSWarner Losh.It K \*(Am R
3024122295aSWarner LoshPre-ANSI Kernighan and Ritchie C.
3034122295aSWarner LoshSometimes called
3044122295aSWarner Losh.Dq knr
3054122295aSWarner Loshor
3064122295aSWarner Losh.Dq C78
3074122295aSWarner Loshto distinguish it from newer standards.
3084122295aSWarner LoshSupport for this compilation environment is dependent on compilers supporting
3094122295aSWarner Loshthis configuration.
3104122295aSWarner LoshMost of the old forms of C have been deprecated or removed in
31175b635c7SWarner Losh.St -isoC-2024 .
3124122295aSWarner LoshCompilers make compiling in this mode increasingly difficult and support for it
3134122295aSWarner Loshmay ultimately be removed from the tree.
3144122295aSWarner Losh.It St -ansiC
3154122295aSWarner Losh.Dv __STDC__
3164122295aSWarner Loshis defined, however
3174122295aSWarner Losh.Dv __STDC_VERSION__
3184122295aSWarner Loshis not.
3194122295aSWarner Losh.Pp
3204122295aSWarner LoshStrict environment selected with
3214122295aSWarner Losh.Dv _ANSI_SOURCE .
3224122295aSWarner Losh.It St -isoC-99
3234122295aSWarner Losh.Dv __STDC_VERSION__ = 199901L
3244122295aSWarner Losh.Pp
3254122295aSWarner LoshStrict environment selected with
3264122295aSWarner Losh.Dv _C99_SOURCE .
3274122295aSWarner Losh.It St -isoC-2011
3284122295aSWarner Losh.Dv __STDC_VERSION__ = 201112L
3294122295aSWarner Losh.Pp
3304122295aSWarner LoshStrict environment selected with
3314122295aSWarner Losh.Dv _C11_SOURCE .
3324122295aSWarner Losh.It ISO/IEC 9899:2018 (“ISO C17”)
3334122295aSWarner Losh.Dv __STDC_VERSION__ = 201710L
3344122295aSWarner Losh.Pp
3354122295aSWarner LoshStrict environment selected with
3364122295aSWarner Losh.Dv _C11_SOURCE
3374122295aSWarner Loshsince there are no new C17 only symbols or macros.
3384122295aSWarner Losh.Pp
3394122295aSWarner LoshThis version of the standard did not introduce any new features, only made
3404122295aSWarner Loshminor, technical corrections.
34175b635c7SWarner Losh.It St -isoC-2024
3424122295aSWarner Losh.Dv __STDC_VERSION__ = 202311L
3434122295aSWarner LoshStrict environment selected with
3444122295aSWarner Losh.Dv _C23_SOURCE
34575b635c7SWarner Loshthough ISO C23 support is only partially implemented.
3464122295aSWarner Losh.El
3474122295aSWarner Losh.Pp
3484122295aSWarner LoshFor more information on C standards, see
3494122295aSWarner Losh.Xr c 7 .
3504122295aSWarner Losh.Ss Programming Environment Selection Macros
3514122295aSWarner LoshDefining the macros outlined below requests that the system header files provide
3524122295aSWarner Loshonly the functions, structures and macros (symbols) defined by the appropriate
3534122295aSWarner Loshstandard, while suppressing all extensions.
3544122295aSWarner LoshHowever, system headers not defined by that standard may define extensions.
3556fc164c7SWarner LoshYou may only define one of the following for any compilation unit.
3564122295aSWarner Losh.Bl -column "---------------"
3574122295aSWarner Losh.It Sy Macro Ta Sy Environment
3584122295aSWarner Losh.It Dv _POSIX_SOURCE Ta St -p1003.1-88 including St -ansiC
3594122295aSWarner Losh.It Dv _POSIX_C_SOURCE = 1 Ta St -p1003.1-88 including St -ansiC
3604122295aSWarner Losh.It Dv _POSIX_C_SOURCE = 2 Ta St -p1003.1-90 including St -ansiC
3614122295aSWarner Losh.It Dv _POSIX_C_SOURCE = 199309 Ta St -p1003.1b-93 including St -ansiC
3624122295aSWarner Losh.It Dv _POSIX_C_SOURCE = 199506 Ta St -p1003.1c-95 including St -ansiC
3634122295aSWarner Losh.It Dv _POSIX_C_SOURCE = 200112 Ta St -p1003.1-2001 including St -isoC-99
3644122295aSWarner Losh.It Dv _POSIX_C_SOURCE = 200809 Ta St -p1003.1-2008 including St -isoC-99
36575b635c7SWarner Losh.It Dv _POSIX_C_SOURCE = 202405 Ta St -p1003.1-2024 including ISO/IEC 9899:2018 ("ISO C17"),
3664365a13bSWarner Losh.It Dv _XOPEN_SOURCE defined Ta St -p1003.1-90 with XPG Extensions to St -susv1 including St -ansiC .
3674365a13bSWarner LoshHowever,
3684365a13bSWarner Losh.Fx
3694365a13bSWarner Loshimplements this as a NOP because too much software breaks with the correct strict environment.
3704122295aSWarner Losh.It Dv _XOPEN_SOURCE = 500 Ta St -p1003.1c-95 and XPG extensions to St -susv2 including St -ansiC
3714122295aSWarner Losh.It Dv _XOPEN_SOURCE = 600 Ta St -p1003.1-2001 and XPG extensions to St -susv3 including St -isoC-99
3724122295aSWarner Losh.It Dv _XOPEN_SOURCE = 700 Ta St -p1003.1-2008 and XPG extensions to St -susv4 including St -isoC-99
37375b635c7SWarner Losh.It Dv _XOPEN_SOURCE = 800 Ta St -p1003.1-2024 and XPG extensions to Version 5 of the Single UNIX Specification (“SUSv5”) including ISO/IEC 9899:2018 (“ISO C17”)
3744122295aSWarner Losh.It Dv _ANSI_SOURCE Ta St -ansiC
3754122295aSWarner Losh.It Dv _C99_SOURCE Ta St -isoC-99
3764122295aSWarner Losh.It Dv _C11_SOURCE Ta St -isoC-2011
37775b635c7SWarner Losh.It Dv _C23_SOURCE Ta St -isoC-2024
3784122295aSWarner Losh.It Dv _BSD_SOURCE Ta Everything, including Fx extensions
3794122295aSWarner Losh.El
3804122295aSWarner Losh.Pp
38175b635c7SWarner LoshNote:
38275b635c7SWarner Losh.St -p1003.1-2024
38375b635c7SWarner Loshand XPG extensions to Version 5 of the Single UNIX Specification ("SUSv5")
38475b635c7SWarner Loshsupport is incomplete.
38575b635c7SWarner Losh.Pp
3864122295aSWarner LoshWhen both POSIX and C environments are selected, the POSIX environment selects
3874122295aSWarner Loshwhich C environment is used.
3884122295aSWarner LoshHowever, when C11 dialect is selected with
3894122295aSWarner Losh.St -p1003.1-2008 ,
3904122295aSWarner Loshdefinitions for
3918b92fa1cSGraham Percival.St -isoC-2011
39275b635c7SWarner Loshare also included.
39375b635c7SWarner LoshLikewise, when C23 dialog is selected with
39475b635c7SWarner Losh.St -p1003.1-2008
39575b635c7SWarner Loshor
39675b635c7SWarner Losh.St -p1003.1-2024 ,
39775b635c7SWarner Loshdefinitions for
3981bfc8428SWarner Losh.St -isoC-2024
39975b635c7SWarner Loshare also included.
4004122295aSWarner Losh.Ss Header Visibility Macros
4014122295aSWarner LoshThese macros are set by
4024122295aSWarner Losh.Nm
4034122295aSWarner Loshto control the visibility of different standards.
404*cfd88668SWarner LoshUsers must not define these, and doing so will produced undefined results.
405*cfd88668SWarner LoshThey are documented here for developers working on system's header files.
4064122295aSWarner Losh.Bl -column "---------------"
4074122295aSWarner Losh.It Dv __XSI_VISIBLE Ta Restricts the visibility of XOPEN Single Unix Standard version.
4084122295aSWarner LoshPossible values are 500, 600, 700 or 800, corresponding to Issue 5, 6, 7, or 8
4094122295aSWarner Loshof the Single Unix Standard.
4104122295aSWarner LoshThese are extra functions in addition to the normal POSIX ones.
4114122295aSWarner Losh.It Dv __POSIX_VISIBLE Ta Make symbols associated with certain standards versions visible.
4124122295aSWarner LoshSet to the value assigned to
4134122295aSWarner Losh.Dv _POSIX_C_SOURCE
4144122295aSWarner Loshby convention with 199009 for
4154122295aSWarner Losh.St -p1003.1-88
4164122295aSWarner Loshand 199209
4174122295aSWarner Losh.St -p1003.1-90 .
4184122295aSWarner Losh.It Dv __ISO_C_VISIBLE Ta The C level that's visible.
41975b635c7SWarner LoshPossible values include 1990, 1999, 2011, 2017 and 2023 for
4204122295aSWarner Losh.St -isoC-90 ,
42175b635c7SWarner Losh.St -isoC-99 ,
42275b635c7SWarner Losh.St -isoC-2011 ,
42375b635c7SWarner LoshISO/IEC 9899:2018 ("ISO C17"), and
42475b635c7SWarner Losh.St -isoC-2024 ,
4254122295aSWarner Loshrespectively.
4264122295aSWarner Losh.It Dv __BSD_VISIBLE Ta 1 if the
4274122295aSWarner Losh.Fx
4284122295aSWarner Loshextensions are visible, 0 otherwise.
4294122295aSWarner Losh.It Dv __EXT1_VISIBLE Ta 1 if the
4304122295aSWarner Losh.St -isoC-2011
4314122295aSWarner LoshAppendix K 3.7.4.1
4324122295aSWarner Loshextensions are visible, 0 otherwise.
433643fc698SGraham Percival.El
434eaa3d34bSWarner Losh.Sh Supported C++ Environments
435eaa3d34bSWarner Losh.Fx
436eaa3d34bSWarner Loshsupports C++11 and newer standards fully.
437eaa3d34bSWarner Losh.Bl -tag
438eaa3d34bSWarner Losh.It ISO/IEC 14882:1998 ("C++98")
439eaa3d34bSWarner Losh.Dv __cplusplus = 199711
440eaa3d34bSWarner Losh.Pp
441eaa3d34bSWarner LoshThe first standardized version of C++.
442eaa3d34bSWarner LoshUnlike K \*(Am R support in C, compilers dropped support for versions of
443eaa3d34bSWarner Loshthe language prior to C++98.
444eaa3d34bSWarner Losh.It ISO/IEC 14882:2003 ("C++03")
445eaa3d34bSWarner Losh.Dv __cplusplus = 199711
446eaa3d34bSWarner Losh.Pp
447eaa3d34bSWarner LoshNote, this is the same value as C++98.
448eaa3d34bSWarner LoshC++03 did not define a new value for
449eaa3d34bSWarner Losh.Dv __cplusplus .
450eaa3d34bSWarner LoshThere is no way, at compile time, to detect the difference.
451eaa3d34bSWarner LoshThe standard resolved a number of defect reports and slightly
452eaa3d34bSWarner Loshexpanded value initialization.
453eaa3d34bSWarner LoshMost compilers support it the same as C++98.
454eaa3d34bSWarner Losh.It ISO/IEC 14882:2011 ("C++11")
455eaa3d34bSWarner Losh.Dv __cplusplus = 201103
456eaa3d34bSWarner Losh.It ISO/IEC 14882:2014 ("C++14")
457eaa3d34bSWarner Losh.Dv __cplusplus = 201402
458eaa3d34bSWarner Losh.It ISO/IEC 14882:2017 ("C++17")
459eaa3d34bSWarner Losh.Dv __cplusplus = 201703
460eaa3d34bSWarner Losh.It ISO/IEC 14882:2020 ("C++20")
461eaa3d34bSWarner Losh.Dv __cplusplus = 202002
462eaa3d34bSWarner Losh.It ISO/IEC 14882:2023 ("C++23")
463eaa3d34bSWarner Losh.Dv __cplusplus = 202302
464eaa3d34bSWarner Losh.El
465eaa3d34bSWarner Losh.Pp
466eaa3d34bSWarner Losh.Fx
467eaa3d34bSWarner Loshuses llvm project's libc++.
468eaa3d34bSWarner LoshHowever, they are removing support for C++ prior to C++11.
469eaa3d34bSWarner LoshWhile programs can still build with earlier environments for now, these changes
470eaa3d34bSWarner Loshmean that
471eaa3d34bSWarner Losh.Fl pedantic-errors
472eaa3d34bSWarner Loshcannot be reliably enabled for standards older than C++11.
4734122295aSWarner Losh.Sh HISTORY
4744122295aSWarner Losh.In sys/cdefs.h
4754122295aSWarner Loshfirst appeared in
4764122295aSWarner Losh.Bx 4.3 NET/2 .
477