Announcement

Collapse
No announcement yet.

string equates versus string literals

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

  • Bern Ertl
    replied
    Thanks John. That helps.

    Leave a comment:


  • John Gleason
    replied
    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

    Leave a comment:


  • John Gleason
    replied
    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.

    Leave a comment:


  • Michael Mattias
    replied
    A MACRO may hold a string longer than the permitted maximum length of a string equate.

    Leave a comment:


  • Bern Ertl
    started a topic string equates versus string literals

    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
Working...
X
😀
🥰
🤢
😎
😡
👍
👎