but has no good solutions. The only remaining solution of that topic is to have unused array locations, but safety rules (for safety programming) generally state to avoid unused variables and empty location.
Any other ideas?
At now I probably define global variables, but it is an error-prone solution.
Francesco
Last edit: fraccaroli 2022-06-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Fless, hi i-campbell,
I added the warning disable as Fless suggest, but if I use the enum in the project the warning come:
[WARNING] INDEX C0125: The constant 2 is assigned to more than one enumeration
Compile complete -- 0 errors, 1 warnings
I think that the only workaround (without using global constant) is to remove the 'strict' attribute.
It seems that CODESYS does not support this way to use array and enums. I was only curious to understand if there were some other way conform with standard programming rules.
Thanks!
Francesco
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Topic: ARRAY idexed by ENUM value
Hi all,
I'm working with ARRAY indexing and I get some problems. I'm used to work with C and there I define and ENUM with indexes like this:
Then I generally declare an ARRAY with "NELEM" as size. In CODESYS is quite difficult, because if I write
values : ARRAY [0..INDEX.NELEM] OF INT;
the array has 4 elements, not 3.
If I write
values : ARRAY [1..INDEX.NELEM] OF INT;
the array has 3 elements, but INDEX.ID1 has no location, because the index in the array starts from 1.
I can't write
values : ARRAY [0..INDEX.NELEM-1] OF INT;
because of error C0359: Arithmetics not allowed on strict ENUM type '...'.
I read this topic:
https://forge.codesys.com/forge/talk/Engineering/thread/f237737cda/
but has no good solutions. The only remaining solution of that topic is to have unused array locations, but safety rules (for safety programming) generally state to avoid unused variables and empty location.
Any other ideas?
At now I probably define global variables, but it is an error-prone solution.
Francesco
Last edit: fraccaroli 2022-06-15
more posts ...
did you remove the 'strict' attribute from your enum definition already?
Welcome Francesco,
this works for me:
Hi Fless, hi i-campbell,
I added the warning disable as Fless suggest, but if I use the enum in the project the warning come:
[WARNING] INDEX C0125: The constant 2 is assigned to more than one enumeration
Compile complete -- 0 errors, 1 warnings
I think that the only workaround (without using global constant) is to remove the 'strict' attribute.
It seems that CODESYS does not support this way to use array and enums. I was only curious to understand if there were some other way conform with standard programming rules.
Thanks!
Francesco