The cost of using STRING ?

shutten
2007-06-08
2017-03-01
  • shutten - 2007-06-08

    Hi,

    I'm new to IEC 61131-3 programming. Could someone clarify what the assignment operator (":=") in ST does when working with strings.

    E.g. myString := originalString;

    I was assuming this does a full character by character copy of the string, but I know in some lanuages only a reference pointer is copied. Now I wonder if my assumption is incorrect since there is string copy function in the system string library - SysStrCpy() in SysLibStr.lib.

    I've had some strange bugs happening ever since I started using strings and SFC (SFCCurrentStep in particular) and want to make sure I am using strings correctly.

    Any feeback on STRING usage is appreciated.

    Sebastian Hutten

     
  • Igor Petrov - 2007-06-09

    Hi

    You are right. ':=' is a full character by character copy. (Certainly you may get a pointer to string see. ADR operator). Moreover you can use '=','>','<' in ST (but not '+', use CONCAT function). For example:

    IF s2 = 'Shutten' THEN

     s1 := CONCAT('Hello Mr.', s2);
    

    END_IF

    I advice you to use string functions from (LEN, LEFT, FIND etc. see 'String functions' in the manual) instead SysLibs…. (platform dependent).

    One limitation: do not use the same string functions in different tasks.

     
  • HenryK - 2017-03-01

    Hi, its a very old topic but still valid. I have a question regarding the statement >Zitat:
    do not use the same string functions in different tasks

    I already found that recommendation or hint, that STRING functions from the standard library are not programmed to be reentrant.
    Okay, usually its clear. But can you tell me why?
    If I need STRING functions in POUs outsourced in libraries, do have to avoid the usage oif the functions from this Standard lib!?
    Which should I use else?

    Thank you for your support.

     

Log in to post a comment.