Language standard
Language standard supported by compiler
Model Configuration Pane: Code Generation
Description
The Language standard parameter specifies the language standard supported by your compiler.
Dependencies
C++ language standards are available for use only if you select
C++
for the Language parameter.When you change the value of the Language parameter, the Language standard is updated to
C99 (ISO)
for C andC++11 (ISO)
for C++.
Settings
C99 (ISO)
if
Language is set to C
or
C++11 (ISO)
if Language is set
to C++
(default) | C89/C90 (ANSI)
| C++03 (ISO)
| C++11 (ISO)
| C++14 (ISO)
| C++17 (ISO)
| C++20 (ISO)
C89/C90 (ANSI)
Generates code that conforms to the ISO®/IEC 9899:1990 C language standard.
C99 (ISO)
Generates code that conforms to the ISO/IEC 9899:1999 C language standard.
C++03 (ISO)
Generates code that conforms to the ISO/IEC 14882:2003 C++ language standard and is compatible with subsequent versions of C++.
C++11 (ISO)
Generates code that conforms to the ISO/IEC 14882:2011 C++ language standard and is compatible with subsequent versions of C++.
C++14 (ISO)
Generates code that conforms to the ISO/IEC 14882:2014 C++ language standard and is compatible with subsequent versions of C++.
C++17 (ISO)
Generates code that conforms to the ISO/IEC 14882:2017 C++ language standard and is compatible with subsequent versions of C++.
C++20 (ISO)
Generates code that conforms to the ISO/IEC 14882:2020 C++ language standard and is compatible with subsequent versions of C++.
Tips
Before setting this parameter, verify that your compiler supports the standard you want to use. If you select a parameter value that your compiler does not support, compiler errors can occur.
For example, if you select
C99 (ISO)
, the code generator implements minimal scoping in the generated code, which is not supported byC89/90
compilers.
If you are using a compiler that does not support ISO/IEC 9899:1999 C, set this parameter to
C89/C90 (ANSI)
.The build process checks whether the specified language standard and toolchain are compatible. If they are not compatible, a warning occurs during code generation and the build process continues.
If you use a Linux® GCC compiler for the build process, the software uses the compiler default language standard to compile the generated code. Depending on the compiler version, the default language standard varies. For more information, see C++ Standards Support in GCC.
For example, if you use the GCC compiler version 8.x and set the parameter Language standard to
C++03
, the software uses theC++14
language standard during compilation. The usage ofC++14
enables building the generated code that integrates custom code that usesC++11
orC++14
features.If you want to enforce the language standard specified in the parameter on the compilation process, then you must add language standard specific compiler flags. If your model is configured to use a toolchain for building code, use this procedure:
In the Configuration Parameters dialog box, set Build configuration to
Specify
.Under Toolchain details, at the end of the
C Compiler
andC++ Compiler
Options field entries, manually add these compiler flags:When the Language standard is set to
C99(ISO)
, add the flag-std=c99 -pedantic
.When the Language standard is set to
C89/90(ANSI)
, add the flag-ansi -pedantic -Wno-long-long
. Depending on model configuration, the build process might include a codertypedef
header file that contains the definition'typedef unsigned long long ulonglong_T'
.-Wno-long-long
suppresses the C90 compiler warning about the use of thelong long
type.When the Language standard is set to
C++03
, add the flag-std=c++03 -pedantic
.When the Language standard is set to
C++11
, add the flag-std=c++11 -pedantic
.When the Language standard is set to
C++14
, add the flag-std=c++14 -pedantic
.When the Language standard is set to
C++17
, add the flag-std=c++17 -pedantic
.When the Language standard is set to
C++20
, add the flag-std=c++20 -pedantic
.
When the Language standard is set to
C++17
orC++20
, the software automatically adds the compiler flag that enforces the specified standard.If your model is configured to use a CMake-based toolchain, the software adds the
target_compile_features
command to the generatedCMakeLists.txt
command to declare a dependency on the specified standard. For example,target_compile_features(myComponent PUBLIC cxx_std_20)
. The command instructs CMake to provide the required compiler flags when generating the build system for your code.If your model is configured to use one of these toolchains:
GNU gcc/g++ | gmake (64-bit Linux)
, on LinuxMinGW64 | gmake (64-bit Windows)
, on Windows®Microsoft Visual C++
, on Windowsmsvc_release ver
.0 | nmake (64-bit Windows)
then, the software uses the compiler default language standard to compile the generated code, which typically is
C99
forC
orC++14
forC++
. If the Language standard is set toC++17
orC++20
, the software automatically applies the required compiler flag.If your model is configured to use one of these toolchains:
Xcode with Clang | gmake (64-bit Mac)
, on Intel® or ARM® MacIntel oneAPI
, on Windowsintel_release
(w/Microsoft Visual Studiomsvs_release
) | nmake (64-bit Windows)
then:
To compile
C
code, the software uses the compiler default language standard (typicallyC99
).To compile
C++
code forC++14
or below, the software adds the compiler flag required forC++14
.To compile
C++
code forC++17
orC++20
, the software adds the corresponding compiler flag.
If your model is configured to use any other toolchain, then include the required language standard-specific compiler flags in the
C Compiler
andC++ Compiler
flags used by the toolchain. Use one of these methods:Specify the flags through the toolchain definition.
Set Build configuration to
Specify
and manually add the flagsUse the
addCompileFlags
method of theRTW.BuildInfo
object, for example, through the Post code generation command field, a
file, or a build hook.specificSFunction
_makecfg.mTo provide the required flags for the
C
compiler only, you can use this command:To provide the required flags for thebuildInfo.addCompileFlags('-std=c99', 'C_OPTS');
C++
compiler only, you can use this command:buildInfo.addCompileFlags('-std=c++17', 'CPP_OPTS');
For more information, see Customize Post-Code-Generation Build Processing, Use makecfg to Customize Generated Makefiles for S-Functions, and Customize Build Process with STF_make_rtw_hook File.
Recommended Settings
Application | Setting |
---|---|
Debugging | No impact |
Traceability | No impact |
Efficiency | Valid library |
Safety precaution | No impact |
Programmatic Use
Parameter: TargetLangStandard |
Type: character vector |
Value:
'C89/C90 (ANSI)' | 'C99 (ISO)' |
'C++03 (ISO)' | 'C++11 (ISO)' |
'C++14 (ISO)' | 'C++17 (ISO)' |
'C++20 (ISO)' |
Default: For C, 'C99 (ISO)' ; for C++ 'C++11 (ISO)' |
Version History
Introduced in R2014a