Process initialization with user-defined types

23 views
Skip to first unread message

Allan Nouri

unread,
Sep 24, 2020, 8:21:03 AM9/24/20
to UPPAAL

Did:
  1. Defined datatype in global declaration:
    typedef struct {int[0,7] a, int b} myRecord;
  2. Create template Template in UPPAAL GUI, type into parameter textfield: myRecord r
  3. Create process with instance of new datatype as argument in system declaration.
    myRecord r = {0,0};
    P = Template(r);
  4. Save model and check syntax
Happened:

    Error
  /system incompatible argument
    r is highlighted in red in editor

Expected:

    Not sure. Are records allowed as process parameters? In this example, replacing the record parameter with two int parameters works fine.

Additional info:

   I get a similar error also for other user-defined types. For instance when creating an alias for a type e.g. typedef int myType;

Marius Mikučionis

unread,
Sep 24, 2020, 11:59:23 AM9/24/20
to UPPAAL
On Thursday, 24 September 2020 at 14:21:03 UTC+2 Allan Nouri wrote:

Did:
  1. Defined datatype in global declaration:
    typedef struct {int[0,7] a, int b} myRecord;
it's probably:
typedef struct {int[0,7] a; int b; } myRecord;
 
  1. Create template Template in UPPAAL GUI, type into parameter textfield: myRecord r
  2. Create process with instance of new datatype as argument in system declaration.
    myRecord r = {0,0};
    P = Template(r);
Now we have two indeependent variables: global variable r and template argument r (which works the same as local variable).
The result is that it occupies twice as much memory, which is inneficient, thus Uppaal discourages that.

You have three options:
a) spare the parameter and use the global variable r: declare the template parameter as reference "myRecord& r" which will bind to the global variable.
b) use global variable r as special value for initialization only, thus declare it as const: "const myRecord r = {0,0};".
c) insist on having two copies:

const myRecord r_const = {0,0}; // does not occupy state memory
myRecord r = r_const; // r is initialized with r_const and occupies state memory
P = Template(r_const); // parameter is initialized with r_const

  1. Save model and check syntax
Happened:

    Error
  /system incompatible argument
    r is highlighted in red in editor

Expected:

    Not sure. Are records allowed as process parameters?

Yes, but Uppaal discourages having copies.

In this example, replacing the record parameter with two int parameters works fine.

Independent int variables do not work either. Perhaps you used literal values which are const int? 
i.e. they are not changing and thus do not occupy state memory.
 

Additional info:

   I get a similar error also for other user-defined types. For instance when creating an alias for a type e.g. typedef int myType;

That's right, they get the same treatment.

Best regards,
Marius 

Allan Nouri

unread,
Sep 25, 2020, 3:02:29 AM9/25/20
to UPPAAL
Thank you, Marius, for clarifying the situation.
Since I really only used the global variable for initialization, it makes sense declaring it as const.
Good to also be aware of the C++-style reference syntax for the future, though.

Allan Nouri

unread,
Sep 25, 2020, 3:12:57 AM9/25/20
to UPPAAL
This fixes my issue, by the way.
Consider this thread closed.

Thank you again.

Kind regards,
Allan
Reply all
Reply to author
Forward
0 new messages