Preprocessor definitions (-D)
Replace macros in preprocessed code
Description
Replace macros with their definitions in preprocessed code.
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 enter macro definitions for this option.
Command line and options file: Use the option
-D. See Command-Line Information.
Why Use This Option
Use this option to emulate your compiler behavior. For instance, if your compiler considers a macro _WIN32 as defined when you build your code, it executes code in a #ifdef _WIN32 statement. If Polyspace® does not consider that macro as defined, you must use this option to replace the macro with 1.
Depending on your settings for Compilation toolchain (Static analysis), some macros are defined by default. Use
this option to define macros that are not implicitly defined.
Typically, you recognize from compilation errors that a certain macro is not defined. For instance, the following code does not compile if the macro _WIN32 is not defined.
#ifdef _WIN32
int env_var;
#endif
void set() {
env_var=1;
}env_var is undefined. However, the definition of env_var is in the #ifdef _WIN32 statement. The underlying cause for the error is that the macro _WIN32 is not defined. You must define _WIN32.Settings
No Default
Use the Add empty row button
to add a new row for each macro you want to define, or add
multiple rows by using the Add/edit multiple rows button
. The definition must be in the format
. If
you want Polyspace to ignore the macro, leave the
Macro=Value blank.Value
For example:
name1=name2replaces all instances ofname1byname2.name=instructs the software to ignorename.namewith no equals sign or value replaces all instances ofnameby 1. To define a macro to execute code in a#ifdefstatement, use this syntax.macro_name
Tips
If Polyspace does not support a non-ANSI® keyword and shows a compilation error, use this option to replace all occurrences of the keyword with a blank string in preprocessed code. The replacement occurs only for the purposes of the analysis. Your original source code remains intact.
For instance, if your compiler supports the
__farkeyword, to avoid compilation errors:In the user interface (desktop products only), enter
__far=.On the command line, use the flag
-D __far=.
The software replaces the
__farkeyword with a blank string during preprocessing. For example:is converted to:int __far* pValue;
int * pValue;
Polyspace recognizes keywords such as
restrictand does not allow their use as identifiers. If you use those keywords as identifiers (because your compiler does not recognize them as keywords), replace the disallowed name with another name using this option. The replacement occurs only for the purposes of the analysis. Your original source code remains intact.For instance, to allow use of
restrictas identifier:In the user interface, enter
restrict=my_restrict.On the command line, use the flag
-D restrict=my_restrict.
Your compiler specification determines the values of many compiler-specific macros. In case you want to know how Polyspace defines a specific macro, use the option
-dump-preprocessing-info.To override the macro definition coming from a compiler specification, use this option.
To undefine a macro, use the option
Disabled preprocessor definitions (-U).
Command-Line Information
You can specify only one flag with each -D option. However, you can specify the option multiple times.
Parameter:
-D |
| No Default |
Value:
|
Example (Bug Finder):
polyspace-bug-finder -D HAVE_MYLIB -D int32_t=int |
Example (Code Prover):
polyspace-code-prover -D HAVE_MYLIB -D int32_t=int |
Example (Bug Finder Server):
polyspace-bug-finder-server -D HAVE_MYLIB -D int32_t=int |
Example (Code Prover Server):
polyspace-code-prover-server -D HAVE_MYLIB -D int32_t=int |