Unresolved constant
A CONSTANT declaration could not be resolved to a compile-time value.
This error is reported when the compiler cannot determine a valid constant initializer, for example when:
- the initializer references non-constant values,
- the initializer contains non-constant operations/calls,
- a referenced constant is itself unresolved,
- a
CONSTANThas no explicit initializer and no usable default can be derived from its type.
Example
TYPE MyInt : INT; END_TYPE
VAR_GLOBAL CONSTANT
// No explicit initializer, and no type default available
a : MyInt;
// Not a constant expression
b : INT := someVar + 1;
END_VAR
Possible fixes
- Provide an explicit compile-time initializer, e.g.
a : MyInt := 0;. - Ensure all referenced symbols in the initializer are themselves constants.
- Replace non-constant calls/operations with compile-time expressions.
- If relying on implicit defaults, define a default on the declared type.