Applies To:
  • CitectSCADA 5.xx

Summary:
If you use a global loop control counter variable in a FOR-DO expression it will result in a "Cicode Stack Overflow"

 // example test1.ci - this will cause a stack overflow
//
    // my global variable
    INT nCounter;


    FUNCTION
    TestLoop()


        INT nFooCounter;
        nFooCounter = 0;
        FOR nCounter = 1 to 500 DO
            nFooCounter = nFooCounter + 1;
        END;

    END


Solution:

If you need to use a global variable in a FOR-DO for versions before v530 ???spk??? then a work around would be to create a local variable in the function and assign the value of the global to it. The local copy should be used as the loop control variable and then the value stored back to the global at the end of the loop.

//

// example test2.ci - suggested work around for versions prior to v530 ???spk???
//
    // my global variable
    INT nCounter;


    FUNCTION
    TestLoop()


        INT nLoopCount;
        INT nFooCounter;


        nLoopCount = nCounter;
        nFooCounter = 0;
        FOR nLoopCount = 1 to 500 DO
            nFooCounter = nFooCounter + 1;
            // this can be placed inside or outside the loop
            // as required
            nCounter = nLoopCount;
        END;

    END

CIT has confirmed this to be a problem in Citect for Windows versions 5.00 to 5.30. This problem has been fixed in version 5.30 Service Pack A.

 

Keywords:
 

Attachments