In the documentation for network variables it states that arrays must "have limits defined with a literal or constant". However any constant I have tried to use (defined with VAR_GLOBAL CONSTANT) throws the error:
Network Variables: GVL.length. not allowed. literal or constant expected
I put together a simple test project to verify this. Defining the following in a network variable is all it takes. The constant can be defined in another global list or it can be defined right in the NVL, it will fail to compile:
Is the documentation wrong, and you can only use literals to define array length in Network Variables? Or am I maybe misunderstanding what the the Network Variable needs to be properly defined? Kind of at a brick wall here...
Last edit: bosulliv 2021-04-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Constantexpressionsarenotpermittedforthispurpose.
Example: βarrVar : ARRAY[0..g_iArraySize-1] OFINT;β is not transmitted, but βarrVar : ARRAY[0..10] OF INT ;β is transmitted.
So yes. Constants wont work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I made the assumption that the documentation would not have a sentence that immediately contradicts the sentence that precedes it. Maybe it meant that constant expressions are not allowed but that constants are allowed? The example you included shows an expression after all.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For anyone reading this later, it turns out that you CAN use constants, you just have to remove the auto-populated pragma {attribute 'qualifiedonly'} and then only reference those constants using their un-qualified name. Ex:
The same is true for enumerations, you can use them, but only if you don't use the fully qualified name.
I can't imagine why the compiler can't recognize the variable as a constant if you use its fully qualified name (NVL_Constants.test vs test). That really seems like a bug to me . . . and the requirement isn't documented in the Network Variable documentation. Hopefully this can be corrected.
Last edit: bosulliv 2021-04-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In the documentation for network variables it states that arrays must "have limits defined with a literal or constant". However any constant I have tried to use (defined with VAR_GLOBAL CONSTANT) throws the error:
Network Variables: GVL.length. not allowed. literal or constant expected
I put together a simple test project to verify this. Defining the following in a network variable is all it takes. The constant can be defined in another global list or it can be defined right in the NVL, it will fail to compile:
Is the documentation wrong, and you can only use literals to define array length in Network Variables? Or am I maybe misunderstanding what the the Network Variable needs to be properly defined? Kind of at a brick wall here...
Last edit: bosulliv 2021-04-19
From the same page:
So yes. Constants wont work.
I made the assumption that the documentation would not have a sentence that immediately contradicts the sentence that precedes it. Maybe it meant that constant expressions are not allowed but that constants are allowed? The example you included shows an expression after all.
For anyone reading this later, it turns out that you CAN use constants, you just have to remove the auto-populated pragma {attribute 'qualifiedonly'} and then only reference those constants using their un-qualified name. Ex:
Constant list:
Network variable list:
The same is true for enumerations, you can use them, but only if you don't use the fully qualified name.
I can't imagine why the compiler can't recognize the variable as a constant if you use its fully qualified name (NVL_Constants.test vs test). That really seems like a bug to me . . . and the requirement isn't documented in the Network Variable documentation. Hopefully this can be corrected.
Last edit: bosulliv 2021-04-22