Lines Matching refs:C
3 C++ Language Support
6 C++ is a general-purpose object-oriented programming language that is based on
7 the C language.
9 Enabling C++ Support
12 Zephyr supports applications written in both C and C++. However, to use C++ in
13 an application you must configure Zephyr to include C++ support by selecting
16 To enable C++ support, the compiler toolchain must also include a C++ compiler
18 :ref:`toolchain_zephyr_sdk`, which includes the GNU C++ Compiler (part of GCC),
22 The default C++ standard level (i.e. the language enforced by the
23 compiler flags passed) for Zephyr apps is C++11. Other standards are
26 tested in Zephyr is C++98.
28 When compiling a source file, the build system selects the C++ compiler based
30 or a **cxx** suffix are compiled using the C++ compiler. For example,
31 :file:`myCplusplusApp.cpp` is compiled using C++.
33 The C++ standard requires the ``main()`` function to have the return type of
40 Do not use C++ for kernel, driver, or system initialization code.
45 Zephyr currently provides only a subset of C++ functionality. The following
49 * OS-specific C++ standard library classes (e.g. ``std::thread``,
66 use of C++ is restricted to application code.
68 In order to make use of the C++ exceptions, the
72 Zephyr Minimal C++ Library
75 Zephyr minimal C++ library (:file:`lib/cpp/minimal`) provides a minimal subset
76 of the C++ standard library and application binary interface (ABI) functions to
77 enable basic C++ language support. This includes:
83 The scope of the minimal C++ library is strictly limited to providing the basic
84 C++ language support, and it does not implement any `Standard Template Library
90 components, such as ``std::string`` and ``std::vector``, must enable the C++
93 C++ Standard Library
96 The `C++ Standard Library`_ is a collection of classes and functions that are
97 part of the ISO C++ standard (``std`` namespace).
99 Zephyr does not include any C++ standard library implementation in source code
101 pre-built C++ standard library included in the C++ compiler toolchain.
103 To enable C++ standard library, select an applicable toolchain-specific C++
108 system can be configured to link against the GNU C++ Library (``libstdc++.a``),
109 which is a fully featured C++ standard library that provides all features
110 required by the ISO C++ standard including the Standard Template Library (STL),
114 The following C++ standard libraries are supported by Zephyr:
116 * GNU C++ Library (:kconfig:option:`CONFIG_GLIBCXX_LIBCPP`)
117 * ARC MetaWare C++ Library (:kconfig:option:`CONFIG_ARCMWDT_LIBCPP`)
119 A Zephyr subsystem that requires the features from the full C++ standard
122 compatible C++ standard library unless the Kconfig symbol for a specific C++
125 Header files and incompatibilities between C and C++
128 To interact with each other, C and C++ must share code through header
129 files: data structures, macros, static functions,... While C and C++
131 incompatibilities`_. C is not just a C++ subset. Standard levels (e.g.:
132 "C+11") add another level of complexity as new features are often
142 just because they have to be compatible between C and C++, but also
156 substitute for knowledge of C/C++ standards, textbooks and other
188 Twenty years later, C++20 added designated initializers to C++ but in
189 much more restricted way; partly because a C++ ``struct`` is actually a
190 ``class``. As described in the C++ proposal number P0329 (which compares
191 with C) or in any complete C++ reference, a mix is not allowed and
194 Interestingly, the new restrictions in C++20 can cause ``gcc -std=c++20``
197 C-style mix of initializers and bare expressions. This fails to compile
200 Recommendation: to maximize compatibility across different C and C++
202 should follow all C++20 rules and restrictions. Non-designated, pre-C99
211 C++20. Other standard revisions may vary. In doubt, do not rely on
217 Anonymous unions (a.k.a. "unnamed" unions) seem to have been part of C++
218 from its very beginning. They were not officially added to C until C11.
219 As usual, there are differences between C and C++. For instance, C
221 ``union``, empty lists ``{ }`` have always been allowed in C++ but they
229 required by C++20 and above which perceive such braces as mixing bare
232 - Do enclose *bare* expressions with braces. This is required by C.
233 Maybe because C is laxer and allows many initialization possibilities
234 and variations, so it may need such braces to disambiguate? Note C
248 .. _`C++ Standard Library`: https://en.wikipedia.org/wiki/C%2B%2B_Standard_Library
253 .. _`gcc commit [C++ PATCH] P0329R4: Designated Initialization`: