Embedded Software

Embedded Software

Topics related to SCADE Suite, SCADE Display, SCADE One and more.

Replacing Nth element of array

    • jeremy.rutman
      Subscriber

      I can replace the element at a fixed index of an array using the Assign of Structured Element Array Operator. 
      However I need to replace the Nth element, where N is an input to my function - when I try this (using N instead of some constant) I hit 

      Type Error ERR_105 Not a size expression at REFRESH_CMD_TIMEOUT/_L21= 

      Identifier N should be bound to a static size expression 

      Can someone let me know if a. this is possible, and b. if possible, how to proceed

    • jeremy.rutman
      Subscriber

      For the Assign of Structured Element hidden parameter (the index) you can set [N] in  the parameters box at the bottom. 
      Why this allows you to  now use dynamic index is a mystery to me.  If you go out of the array bounds nothing happens, so apparently Scade knows not to write past array bounds. 
      But if it knows how to do that then why throw the 'Identifier N should be static' that started me on this little journey?

    • Benjamin Descorps
      Ansys Employee

      Hello,

      As indicated by the error message, the "with" predefined Scade operator only accepts static indexes. As the Scade language is mainly used to build critical safety systems, use of dynamic access is very limited to guarantee safety of the code. For dynamic access, the code shall guarantee that the index passed is well in the range of the array size (Example for the dynamic projection).

      To answer your need, you may declare a generic operator parameterized by size to change a value of an array. The index of the array element, to be modified is passed as a size parameter (i.e. <>). Example:

      function #pragma kcg expand #end F1 <>( i : int16 ^10;   v : int16) returns (  o : int16 ^10)
         o = (i with [idx] = v);

      F1 will then be instantiated with a static size:

      Hope this helps,

      Benjamin

       

Viewing 2 reply threads
  • You must be logged in to reply to this topic.