What is a pure stub and how can I force an automatic stub to be a pure function in PolySpace Server for C/C++?

13 views (last 30 days)
I have seen the term pure stub function in PolySpace documentation and verification logs and wondering what it means and how I can take advantage of it.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 20 Oct 2009
A stubbed function will be considered as pure by PolySpace if the function will not modify its parameters. In the following example f is a pure function as x will not be modified by f and only passed by value:
int f(int c);
...
int x = 3;
f(x);
Here is a more non-trivial example:
void g(void);
void h(const int *p); // the const qualifier here says that the pointed object
// should not be modified.
Example of a non-pure function:
void f(int *p); // the stub will consider that the object pointed by p can be //modified inside f
Note that you can also force automatically generated stub to be “pure” by using
#pragma POLYSPACE_PURE function_to_stub
somewhere in your code. Refer the Stubbing section under Preparing Source Code for Verification chapter of the PolySpace User's guide for C for more information.
One of the advantages of declaring a function to be pure for PolySPace verification purpose is not having to write a manual stub if you know for a fact that the function in run-time will not modify its parameters.
Example:
#pragma POLYSPACE_PURE f
int f(char *x);
int main(void) {
char c=0;
int i,x;
x = f(&c);
x = c; // c is not modified, and x equals 0
return 0;
}
Though f is accepting a char pointer the automatic stubber in PolySpace will stub f as a pure function.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!