P4056¶
- Code
P4056
- Message
Enumeration base-type suffix requires choosing a dialect or –allow-enum-base-type flag
This error occurs when an enumeration declaration carries a base-type suffix
(e.g. TYPE E_Small : (A, B) WORD; END_TYPE) without the
--allow-enum-base-type compiler flag.
The suffix names the elementary type the members are stored in. IEC 61131-3
has no such form: its enumerated_specification (Annex B) is a
parenthesized list of member names or the name of another enumerated type,
and nothing may follow it, so the suffix is an extension.
Unlike explicit member values, which P4055 gates, this is not an Edition 3 addition. The two constructs often appear together but answer different questions about the standard, so each has its own flag.
Example¶
The following code will generate error P4056:
TYPE
E_Small : (A, B) WORD;
END_TYPE
To fix this error, drop the suffix and let the compiler size the type:
TYPE
E_Small : (A, B);
END_TYPE
IronPLC then picks the smallest elementary type that holds every member’s
value, so (A, B) occupies one byte where (A, B) WORD asked for two.
Automatic sizing is what every other IEC 61131-3 enumeration gets, and it is
the right answer unless a fixed width is part of an interface the program
does not control.
Or enable the extension:
Pass the --allow-enum-base-type flag to enable it, or select a dialect that includes it. See
Enabling Dialects and Features for the dialects and flags
reference.
Think IronPLC is wrong about this?
If you believe this diagnostic is incorrect, open an issue on GitHub with a small sample that demonstrates the problem.