Announcement

Collapse
No announcement yet.

Difference between srtlen and str_Length ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Difference between srtlen and str_Length ?

    What's the difference between these two functions ?

    From the manual "PICASO-4DGL-Internal-Functions-REV6.2.pdf":

    strlen(pointer)
    returns the length of a zero terminated string in character units. Note that any string constants declared in your program are automatically terminated with a zero as an end marker by the compiler. Any string that you create in the DATA section or MEM section must have a zero added as a terminator for this function to work correctly.

    str_Length(ptr)

    Returns the length of a string excluding terminator.

  • #2


    strlen works on a word aligned buffer.

    str_Length works on a byte aligned str_Ptr
    Mark

    Comment


    • #3
      Ok. So to work with byte aligned strings, one uses str_Ptr() to obtain a string pointer (str). Actually, I though that was the only way to work with string of characters. But it seems one can work with normal word aligned array as if they were string of characters ? I am getting a bit confused here between what I would call 8bit characters arrays and "normal" 16bit arrays that can contain strings. Could you please help me with that.

      Actually I was just trying out this code :
      Code:
       
      var label1[10];
      var label1Ptr;
       
      label1Ptr := str_Ptr(label1);
      to(label1Ptr); print("%s", [STR] msgPtr);
      str_Printf ( &label1Ptr , "labelPtr1 = %s\n" 
      msgPtr points to a string that I can output with str_Printf ( &msgPtr , "%s" ).
      but here str_Printf ( &label1Ptr , "labelPtr1 = %s\n" 
      does not output anything
      Is it because, the to() and print() cannot be used on byte aligned strings?




      Comment


      • #4


        I think (and I hope someone will correct me if I am wrong) that all str_ functions operate on string (byte aligned) pointers and that all other functions that use strings use word aligned pointers.

        The obvious exception being str_Ptr that returns a byte aligned pointer.

        So, thinking that way, it becomes obvious that 'to' and 'print' only work on word aligned pointers.
        Mark

        Comment


        • #5
          [pre]
          Code:
          var label1[10];
          var label1Ptr;
          
          label1Ptr := str_Ptr(label1);
          str_Cat( &label1Ptr, "Hello");
          str_Printf ( &label1Ptr , "labelPtr1 = %s\n");
          [/pre]
          I must still be doing something wrong since this code does not output "Hello".

          Maybe this obvious fact should be added to the manual in a little section that could be called "Handling strings".

          Comment


          • #6


            Try

            str_Cat(label1Ptr, "Hello");
            Mark

            Comment


            • #7


              OK, it's working fine. Thanks

              Comment

              Working...
              X