Main Content

Verify C Application Without main Function

Polyspace® verification requires that your code must have a main function. You can do one of the following:

  • Provide a main function in your code.

  • Specify that Polyspace must generate a main.

Generate main Function

Before verification, specify one of the following options. In the user interface of the Polyspace desktop products, the options appear under the Code Prover Verification node.

OptionDescription
Verify whole application

The verification stops if the software does not detect a main.

Verify module or library (-main-generator)

Before verification, Polyspace checks if your code contains a main function.

If a main function exists, the software uses that main. Otherwise, the software generates a main using the options that you specify:

Manually Write main Function

During automatic main generation, the software makes certain assumptions about the function call sequence or behavior of global variables. For instance, the default automatically generated main models the following behavior:

  • The functions that you specify using the option Functions to call (-main-generator-calls) can be called in arbitrary order.

  • In the beginning of each function body, global variables can have the full range of values allowed by their type.

To provide a more accurate model of the call sequence, you can manually write a main function for the purposes of verification. You can add this main function in a separate file to your project. In some cases, providing an accurate call sequence can reduce the number of orange checks. For example, in the following code, Polyspace assumes that f and g can be called in any order. Therefore, it produces an orange overflow for the case when f is called before g. If you know that f is called after g, you can write a main function to model this sequence.

static char x;
static int y;

void f(void)
{
    y = 300;
}

void g(void)
{
    x = y; 
}

 Example 1: main Calls One Function Before Another

 Example 2: main Calls One Function 10 Times Before Another

Related Topics