Search code examples
arraysinitializationmodelinguppaal

Array Initialization In Uppaal


I have the following struct:

const int MAX = 6;
typedef struct {
    int num1;
    int arr1[MAX]; 
    int arr2[MAX];
    int num2;
} MyStruct;

And I initialize this array likes the following:

MyStruct myStruct = {1, {-1}, {2,-1}, 1};

But get the following errors, for the first element:

Invalid Initialiser

And for the second element:

too many elements in initialiser

I should have mentioned that the Uppaal version that I use is 4.1.19. So, the question is where is the problem?


Solution

  • As mentioned in the Uppaal documentation, some basic syntaxes are inherited from C++, including array initialization. However, there is a difference that is not bold anywhere. Suppose, we have the following array initialization in C++:

    int arr[5] = {1,2,3}; // arr has type int[5] and holds 1,2,3,0,0
    

    In the opposite side, if we write the same statement in Uppaal, we will get wrong number of elements in array initialiser error, and we need to initialize an array completely likes the below:

    int arr[5] = {1,2,3,0,0};
    

    It means you need to initialize the array with its size (not lesser).