I have been reading through documentation but could not find an answer to this, so I hope it is not impossible. Maybe there is another way to approach this?
Thanks,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
It seems that the length of a chain must be defined only by a constant.
So you can only write : testName : STRING[10];
And not :
testLength : BYTE:=10; //Even if we initialize the value
testName : STRING[testLength]; //Not OK
Even in the case of a variable declaration (not a structure),
BR
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for confirming! I am a bit bummed out since this would make packing/unpacking structs not straight forward at all. But I guess the alternative would create possibility of buffer overflow, so it is not safe. Now, I need to really think about how to unpack structs with this limitation.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I would like to create a struct that has variable string length. However, CoDeSys compiler is not happy since testLength is not a constant.
STRUCT
testLength : BYTE;
testName : STRING[testLength];
END_STRUCT
I have been reading through documentation but could not find an answer to this, so I hope it is not impossible. Maybe there is another way to approach this?
Thanks,
Hi,
It seems that the length of a chain must be defined only by a constant.
So you can only write : testName : STRING[10];
And not :
testLength : BYTE:=10; //Even if we initialize the value
testName : STRING[testLength]; //Not OK
Even in the case of a variable declaration (not a structure),
BR
@JAPIB,
Thanks for confirming! I am a bit bummed out since this would make packing/unpacking structs not straight forward at all. But I guess the alternative would create possibility of buffer overflow, so it is not safe. Now, I need to really think about how to unpack structs with this limitation.