Author Topic: Compilation error: simple fixed string binary file PUT  (Read 3012 times)

0 Members and 1 Guest are viewing this topic.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Compilation error: simple fixed string binary file PUT
« on: February 18, 2022, 01:02:24 pm »
Am I doing something wrong? My understanding is that QB64 can do a massed array PUT

Code: QB64: [Select]
  1. 'OPTION BASE 1
  2. SCREEN _NEWIMAGE(1024, 512, 32)
  3.  
  4. DIM An(1 TO 10) AS STRING * 10
  5.  
  6. FOR x% = 1 TO 10
  7.     READ An(x%)
  8. NEXT x%
  9.  
  10. OPEN "animals.dat" FOR BINARY AS f&
  11. PUT f&, , An()
  12. PRINT "done"
  13.  
  14. DATA dog,cat,bison,elephant,weasel,bear,skunk,ocelot,platypus,pig
  15.  

Compile log results in:
Code: QB64: [Select]
  1. In file included from qbx.cpp:2185:
  2. ..\\temp\\main.txt: In function 'void QBMAIN(void*)':
  3. ..\\temp\\main.txt:41:111: error: lvalue required as unary '&' operand
  4.  sub_put(*__LONG_F,NULL,byte_element((uint64)(&(qbs_new_fixed(&((uint8*)(__ARRAY_STRING10_AN[0]))[(0)*10],10,1))),(10*(__ARRAY_STRING10_AN[2]&1)*__ARRAY_STRING10_AN[5])-(10*(0)),byte_element_3),0);
  5.                                                                                                                ^
  6. compilation terminated due to -Wfatal-errors.
  7.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Compilation error: simple fixed string binary file PUT
« Reply #1 on: February 18, 2022, 02:15:36 pm »
Hi @OldMoses

It still make error. I've dealt with it too, so I'm going it through MEM:

Code: QB64: [Select]
  1. 'OPTION BASE 1
  2. Screen _NewImage(1024, 512, 32)
  3.  
  4. Dim An(1 To 10) As String * 10
  5.  
  6. For x% = 1 To 10
  7.     Read An(x%)
  8. Next x%
  9.  
  10. Open "animals.dat" For Binary As #f
  11.  
  12. 'method A
  13. 'For R = LBound(An) To UBound(An)
  14. 'Put #f, , An(R)
  15. 'Next
  16.  
  17. 'method B
  18. m = _Mem(An())
  19. r$ = Space$(m.SIZE)
  20. _MemGet m, m.OFFSET, r$
  21. Put #f, , r$
  22.  
  23.  
  24. Print "done"
  25.  
  26. Data dog,cat,bison,elephant,weasel,bear,skunk,ocelot,platypus,pig
  27.  
  28.  
  29.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Compilation error: simple fixed string binary file PUT
« Reply #2 on: February 18, 2022, 07:25:27 pm »
Thanks for looking at this, your _MEM solution works fine for me too.

I've worked with files somewhat, but I'm still pretty green at it, and was testing the efficacy of using PUT without the loop structure. The wiki seems to indicate that QB64 can do this, and my first inclination is to wonder what it is that I"M doing wrong.

To this point, I've always used UBOUND derived loops for array PUTs, and was investigating if I could save some keyboarding. Apparently, sometimes the longer road is the better route.