Skip to main content

Compiler Error C0509

Message: Multiple assignments for operator '__New' not allowed

Possible error cause: In one line of code, the assignment operator ":=" is called a multiple number of times with the __New operator.

Error correction: Program the memory allocation with the __New operator in a separate line of code for each pointer that points to dynamically allocated memory.

Example 479. Example of the error:
PROGRAM PLC_PRG
VAR
    pbAlpha : POINTER TO BYTE; // Typed pointer to Alpha
    pbBeta: POINTER TO BYTE;        // Typed pointer to Beta
    xInit : BOOL := TRUE;
    xDelete : BOOL;
END_VAR

IF (xInit) THEN
    pbBeta := pbAlpha := __NEW(BYTE); // Incorrect code for memory allocation
END_IF

pbBeta := pbAlpha := 16#01;

IF (xDelete) THEN
    __DELETE(pbAlpha); // Frees memory of pointer
END_IF

Message:

C0509: Multiple assignments for operator '__NEW' not allowed

Error correction:

PROGRAM PLC_PRG
VAR
    pbAlpha : POINTER TO BYTE; // Pointer to Alpha
    pbBeta: POINTER TO BYTE;        // Pointer to Beta
    xInit : BOOL := TRUE;
    xDelete : BOOL;
END_VAR

IF (xInit) THEN
    pbAlpha := __NEW(BYTE); // Allocates memory for Alpha
    pbBeta :=  __NEW(BYTE); // Allocates memory for Beta
END_IF

pbBeta := pbAlpha := 16#01; // Multiple assignment

IF (xDelete) THEN
    __DELETE(pbAlpha); // Frees memory of pointer
END_IF


For more information, see: __NEW