Code Prover Assumptions About #pragma Directives
The verification ignores most #pragma directives, because they do not carry information relevant to the verification.
However, the verification takes into account the behavior of these pragmas.
| Pragma | Effect on Verification |
|---|---|
| The verification ignores the content between the pragmas. If you use |
#pragma hdrstop | For Visual C++® compilers, the verification stops processing precompiled headers at the point where it encounters the pragma. |
#pragma once | The verification allows the current source file to be included only once in a compilation. |
#pragma pack(n), #pragma pack(push[,n]), #pragma pack(pop) | The verification takes into account the boundary alignment specified in the pragmas.
For more information, see the following example. |
#pragma inline global or #pragma inline | The verification considers the function as an inline function. In particular, by default, the Code Prover generated main does not call these functions directly with the assumption that they are called in other functions. |
| The verification does not inline function func. |
#error | The verification stops if it encounters the directive. For more information, see Fix Polyspace Compilation Errors Related to #error Directive. |
For more information on the pragmas, see your compiler documentation. If the verification does not take into account a certain pragma from the preceding list, see if you specified the right compiler for your verification. For more information, see Compilation toolchain (Static analysis).
For instance, in this code, the directives #pragma pack( force a new alignment boundary in the structure. The User assertion checks in the n)main function are green because the verification takes into account the behavior of the directives. The verification uses these options:
-target:i386(char: 1 byte,int: 4 bytes)
#include <assert.h>
#pragma pack(2)
struct _s6 {
char c;
int i;
} s6;
#pragma pack() /* Restores default packing: pack(4) */
struct _sb {
char c;
int i;
} sb;
#pragma pack(1)
struct _s5 {
char c;
int i;
} s5;
int main(void) {
assert(sizeof(s6) == 6);
assert(sizeof(sb) == 8);
assert(sizeof(s5) == 5);
return 0;
}