question

Alessio Merlo avatar image
0 Likes"
Alessio Merlo asked Alessio Merlo commented

Different way to define input parameter with an array

Hi,

I am sure to be stupid, but I don't find the error in my usercommand.

I attached a model where:

1. I create a usercommand which prints input parameter;

2. I execute the usercommand in a script console defining in different way the input parameter;

3. the command results in output console are foolish!

Where is my error? Help me!

compiler-issue.fsm

FlexSim 20.0.2
usercommandcompiler
compiler-issue.fsm (23.3 KiB)
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered Alessio Merlo commented

If you just pass in just the values of cnt++ and cnt2++, you'll see what's going on:

print("First Execution");
command1(1,2);

print("Second Execution");
int cnt = 1;
command1(cnt++,cnt++);

print("Third Execution");
int cnt2 = 0;
command1(cnt2++,cnt2++);

This produces the following output:

First Execution
param1:= 1
param2:= 2
Second Execution
param1:= 2
param2:= 1
Third Execution
param1:= 1
param2:= 0

Notice that cnt++ and cnt2++ are being evaluated from back to front.

You shouldn't depend on the order that the cnt++ expressions are being evaluated. We don't guarantee that they'll be the same between 64 and 32 bit, or that they'll even ever be evaluated in a certain order.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Alessio Merlo avatar image Alessio Merlo commented ·

Thanks @Matthew Gillespie! I will keep in mind next time!

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.