Static analysis. Variable A greater 1024 bytes

DavidBo
2022-07-21
2022-07-21
  • DavidBo - 2022-07-21

    I am using static analysis which warn me about variable A being greater than 1024 bytes
    Why is that a problem? And what should I do if I have big variables?

    PROGRAM PLC_PRG
    VAR CONSTANT
    nr_of_motors:INT:=2;
    END_VAR
    VAR
    GetState : ARRAY[1..nr_of_motors] OF CIA405.GET_STATE;
    devState : ARRAY[1..nr_of_motors] OF CiA405.DEVICE_STATE;
    enableDev: ARRAY[1..nr_of_motors] OF BOOL:=[nr_of_motors(FALSE)];
    confirmDev: ARRAY[1..nr_of_motors] OF BOOL;
    A: ARRAY [1..nr_of_motors] OF Motor;
    initPRG:BOOL:=TRUE;
    operational:ARRAY [1..nr_of_motors] OF BOOL;
    i0:int;
    END_VAR

     
  • i-campbell

    i-campbell - 2022-07-21

    there is a justification in the help but I couldn't find any such coding guidelines in the first two google results. I suppose it is good to check your biggest variables, maybe you accidentally made a very large array that would cost processor time loading it into memory. Once checked, you can add the static analysis pragmas to ignore it in future. Or you could change the limit a bit higher.

     
    • fajean - 2022-07-21

      I would like to understand what you mean by "that would cost processor time loading it into memory". Outside of arguments passed by value and assignments (which require the array to be copied, but probably are an atypical way to use an array), do you know of cases where a large array size causes sustained CPU load issues by itself, not related to explicit processing such as iterating over the array?

       

Log in to post a comment.