Preprocessor definitions (-D
)
Replace macros in preprocessed code
Description
Replace macros with their definitions in preprocessed code.
Set Option
User interface (desktop products only): In your project configuration, the option is on the Macros node.
User interface (Polyspace Platform, desktop products only): In your project configuration, the option is on the Build tab on the Target & Compiler node.
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 Compiler (-compiler)
, 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
Using the button, add a row for
the macro you want to define. The definition must be in the format
.
If you want Polyspace to ignore the macro, leave the Macro
=Value
blank.Value
For example:
name1=name2
replaces all instances ofname1
byname2
.name=
instructs the software to ignorename
.name
with no equals sign or value replaces all instances ofname
by 1. To define a macro to execute code in a#ifdef
statement, 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
__far
keyword, 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
__far
keyword with a blank string during preprocessing. For example:is converted to:int __far* pValue;
int * pValue;
Polyspace recognizes keywords such as
restrict
and 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
restrict
as 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 |