CAST_ functions buffer declaration

  • From my experience on KSS 8.3, the buffer array of the CAST_ functions must be locally declared.

    So, for example, this code will result in a compiler error:


    Code
    DEF ExampleError( notLocalBuffer :IN )
        DECL CHAR notLocaBuffer[]
        DECL INT offset, aInt
    
        offset = 0
        CAST_FROM( notLocalBuffer[], offset, aInt )
    END


    while, this will give no error


    Code
    DEF ExampleOk( notLocalBuffer :IN )
        DECL CHAR notLocaBuffer[], localBuffer[4]
        DECL INT offset, aInt
        DECL BOOL res
    
        res = strCopy(localBuffer[], notLocalBuffer[])
        offset = 0
        CAST_FROM( localBuffer[], offset, aInt )
    END


    The same happens with CAST_TO.


    Nothing changes if the buffer is declared as a global variable or if the buffer is passed by reference ( :OUT ).




    Does anyone know why?

    Are there other ways to use the CAST_ functions with not locally defined arrays?



    Thank you for the help

  • DEF ExampleError( notLocalBuffer[] :IN )

    The brackets in the definition of the input array do not affect the problem. The same error persist even with the brackets. as you can see in the attacched image (left side).



    so how about those details...? how and where is everything declared and initialized?

    My goal is to have a procedure that takes in input a char array of variable lenght and perform a CAST_TO or a CAST_FROM using this array as buffer.

    The example i reported is defined in a file .src with the same name of the procedure, located in a subfolder of KRC:\R1.

    In this particular case the procedure I am showing in the snaps is named "test_cast" and is written in the file "test_cast.src", located in "KRC:\R1\test" folder.




    I also tryed to declare a function instead of a procedure, as shown in the image (right side), but the error persist.


    Thank you for your help

  • you are still showing same thing (inside of your sub or function) where runtime variable is declared but ... not answering the question....


    you have not shown how and where external variables are declared and initialized... i am talking about variables PASSED TO your sub or function when your sub or function are called.

    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 am talking about variables PASSED TO your sub or function when your sub or function are called.


    Here I hope to give you a better example, also with external variable initialized.



    All the code above is contained in one single module.

    The error persist if I move the declaration of the char array "myBuffer" in the .dat file of the module.



    Thank you again for your time

  • i have tried it on KSS8.5.8 and can see the same behavior.

    passing array is done correctly and works for pretty much all other purposes but clearly CAST_FROM() cannot handle it.


    buffer array CAN be declared in a local DAT for example... but then there is no need to pass it as parameter, it can be used directly.

    problem seem to be only when passing buffer as a as parameter. perhaps has issue with dereferencing.

    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

  • [...] but clearly CAST_FROM() cannot handle it.

    The same applies to CAST_TO().



    [...] problem seem to be only when passing buffer as a as parameter. [...]

    Yes. Not only, as you suggesteded, the problem can be avoided declaring the buffer in the local DAT file but also if you declare the buffer as a GLOBAL variable and then using it directly in any subprogram, still without passing it as a parameter.



    Thank you very much for the help

Advertising from our partners