
When you need to compare two integers for equality you use the equality (=) operator in SCL. This is so intuitive that it hardly needs to be mentioned at all. The same is true for the inequality (<>) operator.
How about array of integers? Does the same still apply? Can I compare two arrays for equality? Will it work?
Yes. It works starting with Process Simulate v2509. Previously the equality/inequality operators on arrays were not supported.
As a bonus the assign (:=) operator also works on arrays.
Some questions:
Q: How are arrays compared?
A: Each element of the first array is compared by value with the corresponding element of the second array.
Q: What are the restrictions?
A: Both arrays should be equal in rank/bounds and also element types should match.
Q: Does it work on arrays of UDTs?
A: Yes. Definitely.
Q: What happens if arrays differ in rank/bounds but element type is the same?
A: In order to calculate the expression (#arr1 <> #arr2) both operands should be of the same type. The SCL interpreter tries to cast the second array to the type of the first one. In this case the cast will fail and you will get a type cast error.
Q: What happens if arrays differ in element type?
A: This is by definition not allowed so the error you'll get is about a malformed expression.
Q: How does this perform?
A: With UDTs you may expect slower performance compared to primitive types.
With primitive types it is fast.
Many questions for a simple array comparison like this:
Internally it is not that simple you know ...
It will take time to see how this flies ...
See you!
Comments