Source code language (-lang)
Specify language of source files
Description
Specify the language of your source files. Before specifying other configuration options, choose this option because other options change depending on your language selection. This option applies to both dynamic testing and static analysis.
The source code language is determined after you add source files to a project.
| Files Added | Source Code Language |
|---|---|
Only files with extension .c | C if the project language was not changed from its default value or was previously set to C, otherwise C-CPP |
Only files with extension .cpp or .cc | CPP if the project language was previously set to CPP, otherwise C-CPP |
Files with extension .c, .cpp, and .cc | C-CPP |
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.
Command line and options file: Use the option
-lang. See Command-Line Information.
Settings
CIf your project contains only C files, choose this setting. This value restricts the verification to C language conventions. All files are interpreted as C files, regardless of their file extension.
CPPIf your project contains only C++ files, choose this setting. This value restricts the verification to C++ language conventions. All files are interpreted as C++ files, regardless of their file extension.
C-CPPIf your project contains C and C++ source files, choose this setting. This value allows for C and C++ language conventions.
.cfiles are interpreted as C files. Other file extensions are interpreted as C++ files.
Dependencies
The language option allows and disallows many options and option values. Some options change depending on your language selection. For more information, see the individual analysis option pages.
If you create a Polyspace® project or options file from your build system using the
polyspace-configurecommand orpolyspaceConfigurefunction, the value of this option is determined by the file extensions.For a project with both
.cand.cppfiles, the language optionC-CPPis used. During the analysis, each file is compiled based on the language standard determined by the file extensions. After the compilation, Polyspace verifies such mixed projects as C++ projects.
Tips
Source File Compilation
For a project with both C and C++ files, if you use the language C-CPP, each file is compiled based on the language standard determined by the file extensions. After the compilation, Polyspace verifies such mixed projects as C++ projects.
In particular, the analysis links all files as C++ files. Because of differences in linking behavior between C and C++, you might see differences in linking errors or warnings when C files in the mixed C-C++ projects are compiled with language C-CPP versus language C.
Source File Linking
C and C++ compilers have some differences in assumptions. For instance, the underlying type of enum is int for a C compiler. However, the underlying type of enum is implementation-defined for a C++ compiler. When using C-CPP as the language, the difference assumptions of C and C++ compiler can lead to a failed analysis.
Test Generation
If you generate tests using a project configuration that has the source language set to C-CPP, the tests are generated as C++ files and compiled using C++ compilation rules.
In particular, if your source code contains identifier names that are reserved keywords in C++, even if the source file is a C file, the generated test in C-CPP mode is in a C++ file and might fail compilation.
Command-Line Information
Parameter: -lang |
Value: c | cpp| c-cpp |
Example (Bug Finder):
polyspace-bug-finder -lang c-cpp -sources |
Example (Code Prover):
polyspace-code-prover -lang cpp -sources |
Example (Bug Finder Server):
polyspace-bug-finder-server -lang c-cpp -sources |
Example (Code Prover Server):
polyspace-code-prover-server -lang cpp -sources |
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 |