Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 CONSTANT has 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.