Passing multidimensional array to subprogram

  • Passing cell[,] is underlined with a red line inside WorkVisual


    DAT-file:

    Code
    ; ...
    ENUM XAlign_T left, center, right
    ENUM YAlign_T top, center, bottom
    STRUC CellConfig_T XAlign_T xalign, YAlign_T yalign, REAL xoffset, yoffset, rot
    ; ...

    SRC-file:

    Code
    DEF mainProgram()    DECL GridConfig_T grid    DECL CellConfig_T cell[20,20] ; Declared as runtime variables
        setDefaults(grid, cell[,], total)    ; <-- ERROR on cell[,]: "The given index is invalid"
        ; ...
    END
    
    DEF setDefaults(grid:OUT, cell[,]:OUT, total:OUT)   DECL GridConfig_T grid   DECL CellConfig_T cell[,]   DECL INT total
       ;...
    END

    When trying to pass cell[,] I get the following error inside WorkVisual: "The given index is invalid". I have tried to initialize every element of the array with a FOR-loop as well, but I get the same error.


    The System Integrator manual also tells me that arrays may only be transferred as OUT parameters (page 573 in "KSS 8.6 SI en"), but still underlines the parameters with a blue line telling me "The value of this parameter is never changed inside the function. IN modifier would be sufficient"


    Any suggestions? Thanks!

  • work visual tips are a bit flaky, don't hang on to every warning or error it shows up.


    systax looks ok but if you are going to pass anything as an OUT parameter, that parameter MUST be a variable and it MUST be initialised BEFORE you try to pass it to some sub.

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • I agree with Panic, this is one of those cases where WV's syntax checking falls on its face. The syntax looks correct. I pulled an example from a working program in my archives:

    Code
    trans_orient(cAp[,], r0err[])
    ;.....
    GLOBAL DEF trans_orient(t[,] :OUT, o[] :OUT)
    DECL REAL    t[,], o[]

    As long as the dimensionality of the arrays matches in the call, the DEF, and the DECL, it should work.

  • The System Integrator manual also tells me that arrays may only be transferred as OUT parameters (page 573 in "KSS 8.6 SI en"), but still underlines the parameters with a blue line telling me "The value of this parameter is never changed inside the function. IN modifier would be sufficient"


    Red = error, Green = ok, blue = warning / suggestion


    arrays do need OUT type of transfer. the only exception is the CHAR arrays to allow passing "strings".

    parameter transfer OUT does not mean that one HAS TO change the value of the parameter, just that value CAN be changed if needed.

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

  • try it, it can work with in some cases like your own code. but it is not always going to work. most of functions etc will expect values already initialised.

    1) read pinned topic: READ FIRST...

    2) if you have an issue with robot, post question in the correct forum section... do NOT contact me directly

    3) read 1 and 2

Advertising from our partners