P4016¶
- Code
P4016
- Message
Function declaration name is duplicated
This error occurs when a function declaration name is duplicated within the same scope.
Example¶
The following code will generate error P4016:
FUNCTION MyFunction : INT
MyFunction := 0;
END_FUNCTION
FUNCTION MyFunction : INT (* Error: Duplicate function name *)
MyFunction := 0;
END_FUNCTION
PROGRAM main
VAR
dummy : INT;
END_VAR
END_PROGRAM
The function MyFunction is declared twice, which is not allowed.
To fix this error, ensure all function names are unique within their scope:
FUNCTION MyFunction1 : INT
MyFunction1 := 0;
END_FUNCTION
FUNCTION MyFunction2 : INT
MyFunction2 := 0;
END_FUNCTION
PROGRAM main
VAR
dummy : INT;
END_VAR
END_PROGRAM
Note that changing the return type or the parameter list of one of the duplicates does not resolve the error, because IEC 61131-3 does not permit overloading. The two declarations below still produce P4016:
FUNCTION Scale : INT
VAR_INPUT v : INT; END_VAR
Scale := v;
END_FUNCTION
FUNCTION Scale : REAL (* Error: same name, different signature is still a duplicate *)
VAR_INPUT v : REAL; END_VAR
Scale := v;
END_FUNCTION
PROGRAM main
VAR
dummy : INT;
END_VAR
END_PROGRAM
Give each function a distinct name (for example, ScaleInt and
ScaleReal) instead of relying on overloading.
See Also¶
References¶
IEC 61131-3 §2.5.1
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.