P4042

Code

P4042

Message

STRING(n)/WSTRING(n) parenthesis length delimiter requires –allow-paren-string-length flag

This error occurs when a string type’s maximum length is delimited with parentheses (STRING(n) / WSTRING(n)) instead of the standard square brackets, without the --allow-paren-string-length compiler flag.

The IEC 61131-3 standard grammar (Annex B) declares a string length only with square brackets – single_byte_string_spec ::= 'STRING' ['[' unsigned_int ']'] ... (and the corresponding 'WSTRING' ['[' unsigned_int ']']). The parenthesis form is a vendor extension.

A bracketed length (STRING[255]) is standard syntax and is always allowed.

Example

The following code will generate error P4042:

FUNCTION_BLOCK FB_Example
VAR
    hostName : STRING(255);
END_VAR
END_FUNCTION_BLOCK

To fix this error, either use the standard bracket form:

FUNCTION_BLOCK FB_Example
VAR
    hostName : STRING[255];
END_VAR
END_FUNCTION_BLOCK

Or enable the vendor extension with the --allow-paren-string-length flag. See Enabling Dialects and Features for how to enable vendor extensions and which dialects include them.

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.