C standard version (-c-version)
Specify C language standard followed in source code
Description
Specify the C language standard that you follow in your source code. This option applies to both dynamic testing and static analysis.
Set Option
Set the option using one of these methods:
Polyspace Platform user interface (desktop products only): In your project configuration, on the Build tab, select the Target & Compiler node and then select a value for this option. See Dependencies for other options you must enable first.
Command line and options file: Use the option
-c-version. See Command-Line Information.
Why Use This Option
Use this option so that Polyspace® can allow features specific to a C standard version during compilation. For instance, if you compile with GCC using the flag -ansi or -std=c90, specify c90 for this option. If you are not sure of the language standard, specify defined-by-compiler.
For instance, suppose you use the boolean data type _Bool in your code. This type is defined in the C99 standard but unknown in prior standards such as C90. If the Polyspace compilation follows the C90 standard, you can see compilation errors.
Some MISRA C™ rules are different based on whether you use the C90 or C99 standard. For instance, MISRA C C:2012 Rule 5.2 requires that identifiers in the same scope and name space shall be distinct. If you use the C90 standard, different identifiers that have the same first 31 characters violate this rule. If you use the C99 standard, the number of characters increase to 63.
Settings
Default: defined-by-compiler
defined-by-compilerThe analysis uses a standard based on your specification for
Compilation toolchain (Static analysis).c90The analysis uses the ISO®/IEC 9899:1990 standard, informally referred to as the C90 standard. Polyspace allows the use of the C99 keyword
inlinewith the valuec90.c99The analysis uses the ISO/IEC 9899:1999 standard, informally referred to as C99 standard.
c11The analysis uses the ISO/IEC 9899:2011 standard, informally referred to as the C11 standard..
c17The analysis uses the ISO/IEC 9899:2018 standard, informally referred to as the C17 or C18 standard.
This version addresses defects in C11 Standard but does not introduce new language features. The value of the
__STDC_VERSION__macro is increased to201710L.
Dependencies
This option is available only if you set
Source code language (-lang)toCorC-CPP.If you create a project or options file from your build system using the
polyspace-configurecommand orpolyspaceConfigurefunction, the value of this option is automatically determined from your build system.If the build system uses different standards for different files, the subsequent Polyspace analysis can emulate your build system and use different standards for compiling those files. If you open such a project in the Polyspace user interface, the option value is shown as
defined-by-compiler. However, instead of one standard, Polyspace uses the hidden option-options-for-sourcesto associate different standards with different files.
Command-Line Information
Parameter: -c-version |
Value: defined-by-compiler | c90 | c99 | c11 | c17 |
Default:
defined-by-compiler |
Example (Bug Finder):
polyspace-bug-finder -lang c -sources |
Example (Code Prover):
polyspace-code-prover -lang c -sources |
Example (Bug Finder Server):
polyspace-bug-finder-server -lang c -sources |
Example (Code Prover Server):
polyspace-code-prover-server -lang c -sources |
Tips
This options helps Polyspace analyze version specific features during the compilation phase. It does not activate or deactivate coding rules associated with versions of the language.
If you specify earlier versions of the language using this option (such as C90 or C99), Polyspace can still report violations of coding rules that are intended for later versions. For example, coding rules from the MISRA C:2023 standard that concern C11 or C17 can be violated by code that use C99 language version. Polyspace reports these violations regardless of what value you specify for
-c-version.