Putten an array in parameters

80 views
Skip to first unread message

Aiden van Dijk

unread,
Jan 13, 2021, 12:31:52 PM1/13/21
to UPPAAL
Hi,

I have a template that I want to search if a certain index inside of an array has a certain value, I have multiple arrays and I want to choose which array my template will search in. This is of course done by the means of parameters, but I keep getting errors, basically I don't know how to make it so the parameter is an array, and when I call the template in "System declarations" I can fill in an array.

Right now I have a template with the name Horizontal and the Parameters Length, Column and Row, I want Length and Column to be integers and I want Row to be a Array integer, how do I make the program realise that Row is supposed to be an Array so I can use Row[blank] to check an index inside of that array/

kind regards,
Aiden

Marius Mikučionis

unread,
Jan 13, 2021, 8:00:26 PM1/13/21
to UPPAAL
Hi,

On Wednesday, 13 January 2021 at 18:31:52 UTC+1 Aiden wrote:
Hi,

I have a template that I want to search if a certain index inside of an array has a certain value, I have multiple arrays and I want to choose which array my template will search in. This is of course done by the means of parameters, but I keep getting errors, basically I don't know how to make it so the parameter is an array, and when I call the template in "System declarations" I can fill in an array.

Sounds like you are struggling with syntax, please paste your attempted code so we can fix it.
 
Right now I have a template with the name Horizontal and the Parameters Length, Column and Row, I want Length and Column to be integers and I want Row to be a Array integer, how do I make the program realise that Row is supposed to be an Array so I can use Row[blank] to check an index inside of that array/


the easiest is to define a separate array type and then use it everywhere, then the compiler will help checking the index ranges.
e.g.:
const int SIZE = 5;
typedef int[0,SIZE-1] range_t; // one can customize the offset of range, but let's stick to C way of counting
typedef int row_t[range_t]; // when range_t counts from 0 then it's equivalent to row_t[SIZE], but having range_t has benefits later.

then template arguments could be:
Template(row_t& Row, range_t blank) // passing by reference, i.e. array is shared

int find_index_of(int value) {
   for (i : range_t) // ranged loop over bounded integer type
      if (Row[i] == value)
         return i;
   return blank;
}

Then system declaration could be:

row_t myrow;
Process = Template(myrow, 0);


Alternatively, pass by value:

Template(row_t Row, range_t blank)
const row_t myrow = { 1, 2, 3, 4, 5 };

Process = Template(myrow, 0);

Marius

Aiden van Dijk

unread,
Jan 14, 2021, 5:17:35 AM1/14/21
to UPPAAL
Hello, my code was as following
In the declarations I had 6 arrays that all looked like this {0, 0, 0, 0, 0, 0} named from A to F. My template existed of a start point that had two loops pointing to itself, one for moving to the left, lowering the column value by 1 and one for moving to the right and increasing the column by 1. I had the following parameters: int Column, int &Row[], int Length I tried to find the right syntax but couldn't figure it out, I couldn't find the correct syntax for expecting an array in parameters. This one however didn't give me the "array expected" error for when I was trying to check Row[Column+Length] == 0. In the system declarations I had: Red = Template(0, A, 2) this gave me a couple errors, my pc sadly crashed overnight and I forgot to save it so I don't have the exact setup but it should be very similar to this.

Aiden

Reply all
Reply to author
Forward
0 new messages