Announcement

Collapse
No announcement yet.

string equates versus string literals

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

    string equates versus string literals

    What are the pros/cons of using macros for string literals versus using string equates?

    I understand that string equates are calculated/concatenated at compile time. Is the same true for macros of string literals?

    For example, what is the difference between:
    Code:
    $appname = "My App"
    $errmsg = " - Error"
    
    MSGBOX ERROR$( ERR),,$appname + $errmsg
    and

    Code:
    MACRO mappname = "My App"
    MACRO merrmsg = " - Error"
    
    MSGBOX ERROR$( ERR),,mappname + merrmsg
    Bernard Ertl
    InterPlan Systems

    #2
    A MACRO may hold a string longer than the permitted maximum length of a string equate.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


      #3
      I understand that string equates are calculated/concatenated at compile time. Is the same true for macros of string literals?
      String macros are not concatenated at compile time, but at runtime. Therefore each reference to the macro will result in the re-concatenation of the string and will use the processor cycles necessary to perform it.

      Comment


        #4
        Here is code to demo the difference mentioned above:
        Code:
        #COMPILE EXE
        #DIM ALL
        
        MACRO s1 = "lllllllllllllllllllllllll"&"ssssssssssssssssssssssss"
        $s2      = "rrrrrrrrrrrrrrrrrrrrooooo"&"rrrrrrrrrrrrrrrrrrrrrrrr"
        
        FUNCTION PBMAIN () AS LONG
        
                LOCAL ii AS LONG, s3 AS STRING, t, t1 AS SINGLE
        
                t = TIMER
                FOR ii = 1 TO 10000000
                    s3 = $s2
                NEXT
                t = TIMER - t
        
                t1 = TIMER
                FOR ii = 1 TO 10000000
                    s3 = s1
                NEXT
                t1 = TIMER - t1
                ? STR$(t) & "  vs " & STR$(t1) & " sec"
        '        WAITKEY$
        
        END FUNCTION

        Comment


          #5
          Thanks John. That helps.
          Bernard Ertl
          InterPlan Systems

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎