Bug in the translator: extra parenthesis before assignment to a string

Started by Quin, July 20, 2024, 11:46:28 AM

Previous topic - Next topic

Quin

my test code:

sub test
    local hand as HANDLE
    local str as string = Join$(2, "test", "ing")
end sub

BCX is putting an extra parenthesis before my string in the generated C source code. If you don't make it assign to Join$ it works, or if you rearrange it to work like: local as string str instead of local str as string it'll work too, hence why I think it's a bug.
-Quin.
GitHub

MrBcx

Quote from: Quin on July 20, 2024, 11:46:28 AM
my test code:

sub test
    local hand as HANDLE
    local str as string = Join$(2, "test", "ing")
end sub

BCX is putting an extra parenthesis before my string in the generated C source code. If you don't make it assign to Join$ it works, or if you rearrange it to work like: local as string str instead of local str as string it'll work too, hence why I think it's a bug.


SUB test
    LOCAL hand AS HANDLE
    LOCAL AS STRING str1 = "This is legal"          ' MUST be a literal/constant
    print str1
    LOCAL AS STRING str2 = TRIM$("  This is not. ") ' CANNOT be a function
    print str2
END SUB

test()
pause


'OUTPUT:

'This is legal
'(null)

'Press any key to continue . . .

MrBcx

This was added to the BCX Revisions in June 2021

**********************************************************************************************
2021/06/23       Changes in 7.7.2 from 7.7.1
**********************************************************************************************

Kevin Diggins  : We can now include quoted string literal initializations that are DIM'd
                 inside of SUBs and FUNCTIONs.  This will not work for GLOBAL strings.
                 It will not work for dynamic strings that are created using any
                 of the  memory allocation functions: malloc/calloc/realloc. String
                 functions and concatentations are NOT allowed -- only plain quoted
                 string LITERALS will work, like in the examples below:


                 Example 1:  DIM A$     = "This is handy!"
                 Example 2:  DIM RAW A$ = "This is too!"
                 Example 3:  LOCAL A$   = "This also works!"

                 BCX translates:  DIM A$ = "This is handy"
                 to:              char A[BCXSTRSIZE]; strcpy(A,"This is handy");



... and in the BCXHelp:  https://bcxbasiccoders.com/webhelp/html/variables.htm#lnk20210623_01


Quin

-Quin.
GitHub