QB64Team / qb64

BASIC for the modern era.
https://www.qb64.org
Other
667 stars 94 forks source link

GET/PUT fixed string array Compilation error #211

Open QB64Cobalt opened 2 years ago

QB64Cobalt commented 2 years ago

QB64 info (please complete the following information): 2.0.2 (4d85302)

*Describe the bug** Attempting to PUT or GET a fixed length string array causes compilation error

To Reproduce DIM A(255) AS STRING * 255 OPEN "File.tmp" FOR BINARY AS #1 PUT #1, ,A() CLOSE #1

Expected behavior Should not cause compilation error

Screenshots In file included from qbx.cpp:2185: ..\temp\main.txt: In function 'void QBMAIN(void)': ..\temp\main.txt:10:107: error: lvalue required as unary '&' operand sub_put( 1 ,NULL,byte_element((uint64)(&(qbs_new_fixed(&((uint8)(ARRAY_STRING255_A[0]))[(0)255],255,1))),(255(ARRAY_STRING255_A[2]&1)__ARRAY_STRING255_A[5])-(255(0)),byte_element_1),0); ^ compilation terminated due to -Wfatal-errors.

Additional context Has been noted on Forum. Created here as per Fellippe's instruction.

GeorgeMcGinn commented 2 years ago

Let me try this again, as I didn't read the forum posts before answering this.

I see the issue, and below I modified the code above and it works. You just need to change the OPEN as OUTPUT and use a PRINT statement instead of a PUT. It accomplishes the same thing. Here is the code that I did to make the above work using the same principle:

DIM A(255) AS STRING * 255 OPEN "File.tmp" FOR OUTPUT AS #1 FOR I = 1 TO 255 B$ = "" FOR Z = 1 TO 255 B$ = B$ + "A" NEXT Z B$ = B$ + "ZZZZZ" A(I) = B$ PRINT #1, A(I) NEXT I CLOSE #1

When I ran the code by just replacing the two items listed, I got a file with nulls in it. The code above makes A$ larger than 255 characters by adding Z's after it to test whether it truncates correctly, and it does.