Author Topic: Compilation failed, log shows PUT fixed length string array  (Read 4977 times)

0 Members and 1 Guest are viewing this topic.

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Compilation failed, log shows PUT fixed length string array
« on: February 26, 2021, 04:31:26 pm »
Well, with a file opened for BINARY, a PUT #1, , ms_name() seems to have failed.  dim shared ms_name(100) as string * 64 in the header.

Quote
In file included from qbx.cpp:2208:
..\\temp\\main.txt: In function 'void SUB_SAVE_FILE(qbs*)':
..\\temp\\main.txt:624:110: error: lvalue required as unary '&' operand
 sub_put( 1 ,NULL,byte_element((uint64)(&(qbs_new_fixed(&((uint8*)(__ARRAY_STRING64_MS_NAME[0]))[(0)*64],64,1))),(64*(__ARRAY_STRING64_MS_NAME[2]&1)*__ARRAY_STRING64_MS_NAME[5])-(64*(0)),byte_element_26),0);
                                                                                                              ^
compilation terminated due to -Wfatal-errors.

In the text file, the caret is pointing at that red close-paren.

This isn't crucial to my program's function - it's a script editor, and this is the name of each script, which is handy for exporting code blocks as I don't have to retype the script names in several places.  But it would be nice to get this to work.  Don't think I've ever tried to PUT an array of fixed-length strings before.
« Last Edit: February 26, 2021, 04:32:39 pm by johannhowitzer »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #1 on: February 26, 2021, 10:22:29 pm »
Open for Random was made for Fixed length Records, but Steve may tell you how to do it with Binary.

If try to do it Unary, you might go blind.

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #2 on: February 26, 2021, 10:56:06 pm »
Is STRING * 64 not fixed length?  I was getting the variable length error before compiling, so I changed from variable length string to fixed.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #3 on: February 26, 2021, 11:16:32 pm »
Yes string * n is fixed, did it help?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #4 on: February 26, 2021, 11:18:20 pm »
You wanna try one big long string?

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #5 on: February 27, 2021, 12:07:36 am »
Quote
Yes string * n is fixed, did it help?

I was already using string * n at the start of this thread, that's the whole point.  The compiler is failing despite that.
« Last Edit: February 27, 2021, 12:10:47 am by johannhowitzer »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #6 on: February 27, 2021, 12:49:38 am »
Random so much easier to use for fixed length stuff

Code: QB64: [Select]
  1. _TITLE "Bplus Gets Random" 'B+ 2021-02-26
  2. OPEN "bplus.txt" FOR RANDOM AS #1 LEN = 64
  3. REDIM bplus AS STRING * 64
  4. FOR i = 1 TO 100
  5.     B$ = "B"
  6.     FOR j = 1 TO i
  7.         MID$(bplus, j, 1) = "B"
  8.     NEXT
  9.     FOR j = i + 1 TO 64
  10.         MID$(bplus, j, 1) = "+"
  11.     NEXT
  12.     PUT #1, i, bplus
  13.  
  14.     'r = INT(RND * 100) + 1
  15.     r = r + 1
  16.     IF r > 100 THEN r = 1
  17.     GET #1, r, bplus
  18.     PRINT bplus
  19.     _LIMIT 30
  20.  
  21.  
« Last Edit: February 27, 2021, 01:03:04 am by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Compilation failed, log shows PUT fixed length string array
« Reply #7 on: February 27, 2021, 01:05:05 am »
Can you share the code that fails?  Or a simplified demonstration of the problem.  It’s hard to debug without something to test.

EDIT: Tested the following code -- it does, indeed, give a C++ compilation failure, as you describe.

Code: QB64: [Select]
  1. DIM test(100) AS STRING * 64
  2. OPEN "temp.txt" FOR BINARY AS #1
  3. PUT #1, , test()
  4.  

This used to work, at one time in the past, I think, but it doesn't currently.  Someone will probably need to look into it when they have time.


EDIT 2: For now, I'd use the following as a quick and easy method for a workaround:

Code: QB64: [Select]
  1. DIM test(100) AS STRING * 64
  2. DIM m AS _MEM: m = _MEM(test())
  3. temp$ = SPACE$(m.SIZE)
  4. _MEMGET m, m.OFFSET, temp$
  5.  
  6. OPEN "temp.txt" FOR BINARY AS #1
  7. PUT #1, , temp$
  8.  
  9. _MEMFREE m: temp$ = ""
  10.  
  11.  
« Last Edit: February 27, 2021, 01:16:54 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #8 on: February 27, 2021, 01:21:15 am »
Yeah I got same crappy message from same kind of test, I'm tell'n ya Random is easier.

Just pick your line number and get it, Plus it actually works!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Compilation failed, log shows PUT fixed length string array
« Reply #9 on: February 27, 2021, 01:24:48 am »
Yeah I got same crappy message from same kind of test, I'm tell'n ya Random is easier.

Just pick your line number and get it, Plus it actually works!

Binary works too, if you GET/PUT a single record at a time like with RANDOM.  The glitch comes when trying to put the whole array at once.

Code: QB64: [Select]
  1. DIM test(100) AS STRING * 64
  2.  
  3. OPEN "temp.txt" FOR BINARY AS #1
  4. FOR i = 0 TO 100
  5.     PUT #1, , test(i)
  6.  
  7. [/code
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #10 on: February 27, 2021, 01:27:02 am »
There is a way. Evidently it is doable in C but here is what I found

Code: QB64: [Select]
  1. DIM A(100) AS STRING * 64
  2.  
  3. PRINT LEN(A())        
  4.  
  5.  
  6. B = _OFFSET(A(0))
  7.  
  8. B = _OFFSET(A(1))
  9.  
  10. B = _OFFSET(A(2))

Notice that the array elements are contiguous in memory.

The address of A(0) is known so that must be the start of the arrray's memory block.  So how do we write to that memory block?

Size of memory block is fixed at 6464 bytes
« Last Edit: February 27, 2021, 01:31:20 am by NOVARSEG »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #11 on: February 27, 2021, 01:58:35 am »
fghsh
« Last Edit: February 27, 2021, 02:03:58 am by NOVARSEG »

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Compilation failed, log shows PUT fixed length string array
« Reply #12 on: February 27, 2021, 03:08:51 am »
Quote
Binary works too, if you GET/PUT a single record at a time like with RANDOM.  The glitch comes when trying to put the whole array at once.

Thanks, tried that and it worked.  Guess I'm 2 for 2 now, on finding QB64 bugs!

Here's the full code, in case you're still interested.  It's a script editor for my main game project, to cut down on the math I've been having to do by hand.  Line 77 has the fixed string declaration, lines 219 and 236 have the get/put of the array, which I have now enclosed in a for loop.

Code: QB64: [Select]
  1. const true = -1
  2. const false = 0
  3.  
  4. const screenw = 800
  5. const screenh = 600
  6. const hud_top = 513
  7. fullscreen = _newimage(screenw, screenh, 32)
  8. screen fullscreen
  9.  
  10. _source fullscreen ' Prevent handles from ever being null
  11. _dest   fullscreen
  12.  
  13. type coordinate_dec ' for stage-wide position coordinates, needs to handle large values with decimals
  14.    x as double
  15.    y as double
  16. type coordinate_int
  17.    x as integer
  18.    y as integer
  19.  
  20. const hue_transparent = 0
  21. hue(hue_transparent) = _rgba32(  0,   0,   0,   0)
  22. const hue_black      = 1
  23. hue(hue_black)       = _rgba32(  0,   0,   0, 255)
  24. const hue_white      = 2
  25. hue(hue_white)       = _rgba32(255, 255, 255, 255)
  26. const hue_red        = 3
  27. hue(hue_red)         = _rgba32(255,   0,   0, 255) ' Only used for enemy health bars
  28. const hue_green      = 4
  29. hue(hue_green)       = _rgba32(  0, 255,   0, 255) ' Only used in debug menu
  30. const hue_dkblue     = 5
  31. hue(hue_dkblue)      = _rgba32(  0,  74, 149, 223) ' Windows
  32. const hue_ltblue     = 6
  33. hue(hue_ltblue)      = _rgba32(  0, 124, 249, 255)
  34.  
  35. color hue(hue_black), hue(hue_white)
  36.  
  37. const up    = 1
  38. const down  = 2
  39. const left  = 3
  40. const right = 4
  41. dim shared arrow(4) as string * 2
  42. arrow(up)    = chr$(0) + chr$(72)
  43. arrow(right) = chr$(0) + chr$(77)
  44. arrow(down)  = chr$(0) + chr$(80)
  45. arrow(left)  = chr$(0) + chr$(75)
  46.  
  47. const aim_e  = 0
  48. const aim_se = 1 * atn(1)
  49. const aim_s  = 2 * atn(1)
  50. const aim_sw = 3 * atn(1)
  51. const aim_w  = 4 * atn(1)
  52. const aim_nw = 5 * atn(1)
  53. const aim_n  = 6 * atn(1)
  54. const aim_ne = 7 * atn(1)
  55.  
  56. const script_limit = 100
  57.  
  58. type movescript_structure
  59.    angle       as single
  60.    speed       as single
  61.    angle_abs   as _byte   ' true overwrites previous angle, false adds to it, false by default
  62.    speed_abs   as _byte   ' true overwrites previous speed, false adds to it, false by default
  63.  
  64.    ' Vector addition
  65.    accel_abs_a as single  ' "Absolute" - added vector related to basis angle
  66.    accel_abs_v as single     ' Magnitude of absolute vector
  67.    accel_rel_a as single  ' "Relative" - added vector relative to current angle
  68.    accel_rel_v as single     ' Magnitude of relative vector
  69.  
  70.    length      as integer ' duration of script in frames
  71. dim shared ms(script_limit) as movescript_structure
  72. dim shared ms_name(script_limit) as string * 64
  73. dim shared mss$(script_limit) ' Preview of what script contains
  74. dim shared ms_count as _byte
  75.  
  76. type entity_structure
  77.    pos      as coordinate_dec ' Position relative to stage, not screen
  78.    angle    as single         ' Angle of movement, or angle of normal aim for a weapon
  79.    speed    as single         ' Pixels of movement per frame
  80.  
  81.    ' Vector addition
  82.    accel_abs_a as single  ' Absolute angle - relative to standard angles
  83.    accel_abs_v as single  '    Magnitude
  84.    accel_rel_a as single  ' Relative angle - added to current angle
  85.    accel_rel_v as single  '    Magnitude
  86.  
  87.    size as coordinate_int
  88. dim shared entity as entity_structure
  89. entity.size.x = 20
  90. entity.size.y = 15
  91.  
  92. dim shared start as coordinate_dec
  93. start.x = -600
  94. start.y = 0
  95.  
  96. ms_count = 0
  97.  
  98.  
  99.  
  100.  
  101.  
  102. c = 1
  103.  
  104.    _limit 60
  105.    cls , hue(hue_white)
  106.    locate 1, 3: print "Options"
  107.    locate 2, 3: print "Start:"; start.x; ","; start.y
  108.    for n = 1 to ms_count
  109.       locate n + 2, 3: print trim$(n); " "; mss$(n)
  110.    next n
  111.    locate c, 1: print ">"
  112.  
  113.    k$ = inkey$
  114.  
  115.    if k$ = arrow(down) then c = wrap(c + 1, 1, ms_count + 2)
  116.    if k$ = arrow(up)   then c = wrap(c - 1, 1, ms_count + 2)
  117.  
  118.    if k$ = chr$(13) then
  119.       select case c
  120.          case 1: call option_menu
  121.          case 2
  122.             call clear_row(c)
  123.             locate 2, 3: input "Start x: ", start.x
  124.             call clear_row(c)
  125.             locate 2, 3: input "Start y: ", start.y
  126.          case else: call edit_script(c - 2)
  127.       end select
  128.    end if
  129.  
  130.    if k$ = "-" then ms_count = plus_limit(ms_count, -1, 0)
  131.    if k$ = "=" then
  132.       ms_count = plus_limit(ms_count,  1, script_limit)
  133.       call get_mss(ms_count)
  134.    end if
  135.  
  136.    if k$ = " " then call run_scripts
  137.  
  138.    if k$ = chr$(27) then
  139.       locate 1, 20: print "Enter to exit, any other key to cancel"
  140.       do
  141.          _limit 60
  142.          _display
  143.          k$ = inkey$
  144.          if k$ = chr$(13) then system
  145.       loop while k$ = ""
  146.    end if
  147.  
  148.  
  149.  
  150.  
  151.  
  152. sub option_menu
  153.  
  154. c = 1
  155.  
  156.    _limit 60
  157.    cls , hue(hue_white)
  158.    locate 1, 3: print "Entity width: "; entity.size.x
  159.    locate 2, 3: print "Entity height:"; entity.size.y
  160.    locate 3, 3: print "Save to file"
  161.    locate 4, 3: print "Load from file"
  162.    locate 5, 3: print "Export to code"
  163.    locate c, 1: print ">"
  164.    line(100, 100)-step(entity.size.x, entity.size.y), hue(hue_black), b
  165.  
  166.    k$ = inkey$
  167.  
  168.    if k$ = arrow(down) then c = wrap(c + 1, 1, 5)
  169.    if k$ = arrow(up)   then c = wrap(c - 1, 1, 5)
  170.  
  171.    d = 0
  172.    if k$ = arrow(left)  or k$ = "-" then d = -1
  173.    if k$ = arrow(right) or k$ = "=" then d =  1
  174.  
  175.    if c = 1 then entity.size.x = wrap(entity.size.x + d, 2, 100)
  176.    if c = 2 then entity.size.y = wrap(entity.size.y + d, 2, 100)
  177.  
  178.    if k$ = chr$(13) and c = 3 then
  179.       input "Save filename: ", f$
  180.       call save_file(f$)
  181.    end if
  182.  
  183.    if k$ = chr$(13) and c = 4 then
  184.       input "Load filename: ", f$
  185.       call load_file(f$)
  186.    end if
  187.  
  188.    if k$ = chr$(13) and c = 5 then
  189.       input "Export filename: ", f$
  190.       call export_code(f$)
  191.    end if
  192.  
  193. loop until k$ = chr$(27)
  194.  
  195.  
  196.  
  197. sub save_file(f$)
  198.  
  199. put #1, 1, entity.size.x
  200. put #1, , entity.size.y
  201. put #1, , start.x
  202. put #1, , start.y
  203. put #1, , ms_count
  204. put #1, , ms()
  205. for s = 1 to script_limit
  206.    put #1, , ms_name(s)
  207.  
  208.  
  209.  
  210. sub load_file(f$)
  211.  
  212. get #1, 1, entity.size.x
  213. get #1, , entity.size.y
  214. get #1, , start.x
  215. get #1, , start.y
  216. get #1, , ms_count
  217. get #1, , ms()
  218. for s = 1 to script_limit
  219.    get #1, , ms_name(s)
  220.  
  221. for s = 1 to ms_count
  222.    call get_mss(s)
  223.  
  224.  
  225.  
  226. sub edit_script(s)
  227.  
  228. c = 1
  229.  
  230.    _limit 60
  231.    cls , hue(hue_white)
  232.    locate 1, 3: print "Name     :"; crop$(ms_name(s))
  233.    locate 2, 3: print "Angle    :"; ms(s).angle;
  234.       if ms(s).angle_abs = false then print "(Rel)" else print
  235.    locate 3, 3: print "Speed    :"; ms(s).speed;
  236.       if ms(s).speed_abs = false then print "(Rel)" else print
  237.    locate 4, 3: print "Length   :"; int(ms(s).length / 60); "."; trim$(ms(s).length mod 60)
  238.    locate 5, 3: print "Abs acc a:"; ms(s).accel_abs_a
  239.    locate 6, 3: print "Abs acc v:"; ms(s).accel_abs_v
  240.    locate 7, 3: print "Rel acc a:"; ms(s).accel_rel_a
  241.    locate 8, 3: print "Rel acc v:"; ms(s).accel_rel_v
  242.    locate c, 1: print ">"
  243.  
  244.    k$ = inkey$
  245.  
  246.    if k$ = arrow(down) then c = wrap(c + 1, 1, 8)
  247.    if k$ = arrow(up)   then c = wrap(c - 1, 1, 8)
  248.  
  249.    if k$ = "r" and c = 2 then ms(s).angle_abs = toggle(ms(s).angle_abs, true, false)
  250.    if k$ = "r" and c = 3 then ms(s).speed_abs = toggle(ms(s).speed_abs, true, false)
  251.  
  252.    if k$ = chr$(27) then exit do
  253.  
  254.    if k$ = chr$(13) then
  255.       select case c
  256.          case 1
  257.             call clear_row(c)
  258.             locate c, 3: input "Name     : ", t$
  259.             for n = 1 to len(ms_name(s))
  260.                mid$(ms_name(s), l) = " "
  261.             next n
  262.             mid$(ms_name(s), 1) = t$
  263.          case 2
  264.             call clear_row(c)
  265.             locate 9, 3: print "Shortcuts: up, down, left, right, n, s, w, e, nw, ne, sw, se"
  266.             locate c, 3: input "Angle    : ", a$
  267.             ms(s).angle = angle_shortcut(a$)
  268.          case 3
  269.             call clear_row(c)
  270.             locate c, 3: input "Speed    : ", ms(s).speed
  271.          case 4
  272.             call clear_row(c)
  273.             locate c, 3: input "Length   : ", l
  274.             ms(s).length = frames(l)
  275.          case 5
  276.             call clear_row(c)
  277.             locate 9, 3: print "Shortcuts: up, down, left, right, n, s, w, e, nw, ne, sw, se"
  278.             locate c, 3: input "Abs acc a: ", a$
  279.             ms(s).accel_abs_a = angle_shortcut(a$)
  280.          case 6
  281.             call clear_row(c)
  282.             locate c, 3: input "Abs acc v: ", ms(s).accel_abs_v
  283.             if ms(s).accel_abs_v <> 0 then
  284.                ms(s).accel_rel_a = 0
  285.                ms(s).accel_rel_v = 0
  286.             end if
  287.          case 7
  288.             call clear_row(c)
  289.             locate 9, 3: print "Shortcuts: up, down, left, right, n, s, w, e, nw, ne, sw, se"
  290.             locate c, 3: input "Rel acc a: ", a$
  291.             ms(s).accel_rel_a = angle_shortcut(a$)
  292.          case 8
  293.             call clear_row(c)
  294.             locate c, 3: input "Rel acc v: ", ms(s).accel_rel_v
  295.             if ms(s).accel_rel_v <> 0 then
  296.                ms(s).accel_abs_a = 0
  297.                ms(s).accel_abs_v = 0
  298.             end if
  299.       end select
  300.    end if
  301.  
  302. call get_mss(s)
  303.  
  304.  
  305.  
  306. sub run_scripts
  307.  
  308. entity.pos.x = start.x
  309. entity.pos.y = start.y
  310.  
  311. entity.angle = 0
  312. entity.speed = 0
  313.  
  314. entity.accel_abs_a = 0
  315. entity.accel_abs_v = 0
  316. entity.accel_rel_a = 0
  317. entity.accel_rel_v = 0
  318.  
  319. cls , hue(hue_white)
  320.  
  321. for s = 1 to ms_count
  322.  
  323.    ' Execute script
  324.  
  325.    entity.angle = wrap_a(entity.angle + ms(s).angle)
  326.    if ms(s).angle_abs = true then entity.angle = ms(s).angle
  327.    entity.speed = entity.speed + ms(s).speed
  328.    if ms(s).speed_abs = true then entity.speed = ms(s).speed
  329.  
  330.    entity.accel_abs_a = ms(s).accel_abs_a
  331.    entity.accel_abs_v = ms(s).accel_abs_v
  332.  
  333.    if ms(s).accel_rel_v <> 0 then
  334.       a = entity.angle
  335.       entity.accel_abs_a = wrap_a(a + ms(s).accel_rel_a)
  336.       entity.accel_abs_v = ms(s).accel_rel_v
  337.    end if
  338.  
  339.    for f = 1 to ms(s).length
  340.       _limit 60
  341.  
  342.       line(entity.pos.x, entity.pos.y)-step(entity.size.x, entity.size.y), hue(hue_ltblue), b
  343.  
  344.       ' ----- Update position -----
  345.  
  346.       entity.pos.x = entity.pos.x + vector_x(entity.angle, entity.speed)
  347.       entity.pos.y = entity.pos.y + vector_y(entity.angle, entity.speed)
  348.  
  349.       ' ----- Acceleration -----
  350.  
  351.       ' Get vector to be added
  352.       if entity.accel_rel_v <> 0 then
  353.          a = entity.angle
  354.          a = wrap_a(a + entity.accel_rel_a)
  355.          v = entity.accel_rel_v
  356.       end if
  357.       ' Absolute overrides relative
  358.       if entity.accel_abs_v <> 0 then
  359.          a = entity.accel_abs_a
  360.          v = entity.accel_abs_v
  361.       end if
  362.  
  363.       ' Add vector to entity
  364.       if entity.accel_rel_v <> 0 or entity.accel_abs_v <> 0 then
  365.          x = vector_x(entity.angle, entity.speed) + vector_x(a, v)
  366.          y = vector_y(entity.angle, entity.speed) + vector_y(a, v)
  367.          entity.angle = arctan(y, x)
  368.          entity.speed = hypo(x, y)
  369.       end if
  370.  
  371.       line(entity.pos.x, entity.pos.y)-step(entity.size.x, entity.size.y), hue(hue_black), b
  372.       _display
  373.  
  374.       k$ = inkey$
  375.  
  376.       if k$ = chr$(27) then exit sub
  377.    next f
  378.  
  379.    _limit 60
  380.    k$ = inkey$
  381. loop until k$ = chr$(27)
  382.  
  383.  
  384.  
  385. function shorten_dec$(n)
  386. shorten_dec$ = left$(trim$(n), 6)
  387.  
  388.  
  389. function trim$(n)
  390. trim$ = mid$(str$(n), 2)
  391.  
  392.  
  393. sub clear_row(n)
  394. locate n, 1
  395. print "                                                                      "
  396.  
  397.  
  398. function toggle(v, p, q)
  399. if v = p then toggle = q
  400. if v = q then toggle = p
  401.  
  402.  
  403. function frames(s)
  404. ' Pass in a decimal in seconds.frames, returns integer frames
  405. f = int(s) * 60
  406. frames = int(f + ((s - int(s)) * 100))
  407.  
  408.  
  409. function wrap(n, l1, h1)
  410. ' n is adjusted back within lower(l) and upper(h) bounds similar to mod operator
  411. l = l1: h = h1 ' make sure h is never less than l, this also prevents division by zero
  412. if h1 < l1 then
  413.    l = h1: h = l1
  414. x = (l - n) / ((h - l) + 1)
  415. if x <> int(x) then x = x + 1
  416. wrap = n + (int(x) * ((h - l) + 1))
  417.  
  418.  
  419. function wrap_a(a)
  420. ' angle a is adjusted back within 0 and 2pi, 2pi noninclusive
  421. x = -a / atn1(8)
  422. if x <> int(x) then x = x + 1
  423. wrap_a = a + (int(x) * atn1(8))
  424.  
  425.  
  426. function vector_x(a, v)
  427. vector_x = 0
  428. if a = aim_n or a = aim_s then exit function ' Protect against undefined cos()
  429. vector_x = v * cos(a)
  430. function vector_y(a, v)
  431. vector_y = 0
  432. if a = aim_w or a = aim_e then exit function ' Protect against undefined sin()
  433. vector_y = v * sin(a)
  434.  
  435.  
  436. function hypo(a, b)
  437. hypo = sqr(sq(a) + sq(b))
  438.  
  439.  
  440. function arctan(y, x)
  441. arctan = 0
  442. if x = 0 and y = 0 then exit function
  443. a = atn1(2)
  444. if x <> 0 then ' prevent division by zero
  445.    a = abs(atn(y / x))
  446.    if x < 0 then a = atn1(4) - a
  447. if y < 0 then a = flip_y(a)
  448. arctan = a
  449.  
  450.  
  451. function angle_shortcut(a$)
  452.  
  453.    case "e":  angle_shortcut = aim_e
  454.    case "se": angle_shortcut = aim_se
  455.    case "s":  angle_shortcut = aim_s
  456.    case "sw": angle_shortcut = aim_sw
  457.    case "w":  angle_shortcut = aim_w
  458.    case "nw": angle_shortcut = aim_nw
  459.    case "n":  angle_shortcut = aim_n
  460.    case "ne": angle_shortcut = aim_ne
  461.    case else: angle_shortcut = val(a$)
  462.  
  463.  
  464.  
  465. function plus_limit(n, p, l)
  466. q = n + p
  467. if sgn(q - l) = sgn(p) then q = l
  468. plus_limit = q
  469.  
  470.  
  471. function half(n)
  472. half = n * 0.5
  473.  
  474.  
  475. sub get_mss(s)
  476.  
  477. mss$(s) = "'" + crop$(ms_name(s)) + "' L: " + trim$(ms(s).length)
  478.  
  479. mss$(s) = mss$(s) + " a:" + string_angle$(ms(s).angle)
  480.    if ms(s).angle_abs = false then mss$(s) = mss$(s) + "(r)"
  481.  
  482. mss$(s) = mss$(s) + " v:" + trim$(ms(s).speed)
  483.    if ms(s).speed_abs = false then mss$(s) = mss$(s) + "(r)"
  484.  
  485. if ms(s).accel_abs_v <> 0 then mss$(s) = mss$(s) + " abs a:" + string_angle$(ms(s).accel_abs_a) + " v: " + trim$(ms(s).accel_abs_v)
  486. if ms(s).accel_rel_v <> 0 then mss$(s) = mss$(s) + " rel a:" + string_angle$(ms(s).accel_rel_a) + " v: " + trim$(ms(s).accel_rel_v)
  487.  
  488.  
  489.  
  490. function string_angle$(a)
  491.  
  492. string_angle$ = shorten_dec$(a)
  493.  
  494.    case aim_e:  string_angle$ = "aim_e"
  495.    case aim_se: string_angle$ = "aim_se"
  496.    case aim_s:  string_angle$ = "aim_s"
  497.    case aim_sw: string_angle$ = "aim_sw"
  498.    case aim_w:  string_angle$ = "aim_w"
  499.    case aim_nw: string_angle$ = "aim_nw"
  500.    case aim_n:  string_angle$ = "aim_n"
  501.    case aim_ne: string_angle$ = "aim_ne"
  502.  
  503.  
  504.  
  505. sub export_code(f$)
  506.  
  507.  
  508. for s = 1 to ms_count
  509.    print #1, "   msd.angle       = "; string_angle$(ms(s).angle)
  510.    if ms(s).angle_abs = true then print #1, "   msd.angle_abs   = true"
  511.    print #1, "   msd.speed       = "; trim$(ms(s).speed)
  512.    if ms(s).speed_abs = true then print #1, "   msd.speed_abs   = true"
  513.  
  514.    if ms(s).accel_abs_v <> 0 then
  515.       print #1, "   msd.accel_abs_a = "; string_angle$(ms(s).accel_abs_a)
  516.       print #1, "   msd.accel_abs_v = "; trim$(ms(s).accel_abs_v)
  517.    end if
  518.  
  519.    if ms(s).accel_rel_v <> 0 then
  520.       print #1, "   msd.accel_rel_a = "; string_angle$(ms(s).accel_rel_a)
  521.       print #1, "   msd.accel_rel_v = "; trim$(ms(s).accel_rel_v)
  522.    end if
  523.  
  524.    sc$ = trim$(int(ms(s).length / 60))
  525.    fr$ = trim$(ms(s).length mod 60)
  526.    print #1, "   msd.length      = frames("; sc$; "."; fr$; ")"
  527.  
  528.    if s <> ms_count then
  529.       print #1, "   msd.next_script = "; crop$(ms_name(s + 1))
  530.    end if
  531.  
  532.    print #1, "call set_movescript("; crop$(ms_name(s)); ")"
  533.    print #1, "   call clear_msd"
  534.    print
  535.  
  536.  
  537.  
  538.  
  539. function crop$(t$)
  540. p = instr(t$, " ")
  541. crop$ = left$(t$, p - 1)
  542.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Compilation failed, log shows PUT fixed length string array
« Reply #13 on: March 02, 2021, 04:27:41 pm »
I've pinpointed the issue in our code, but I have no clue how the heck to implement any fixes in the source for this yet...

Here's a simple little QB64 program for illustration purposes:
Code: QB64: [Select]
  1. DIM b(100) AS _BYTE
  2. DIM s(100) AS STRING * 1
  3. FOR i = 1 TO 100
  4.     b(i) = i
  5.     s(i) = CHR$(i)
  6. OPEN "temp.txt" FOR BINARY AS #1
  7. PUT #1, , b()
  8. PUT #1, , s()

Now, this produces code with the glitch in it for us, which looks like this:
Code: C++: [Select]
  1. S_0:;
  2.  
  3.  
  4. fornext_value2= 1 ;
  5. fornext_finalvalue2= 100 ;
  6. fornext_step2= 1 ;
  7. if (fornext_step2<0) fornext_step_negative2=1; else fornext_step_negative2=0;
  8. if (new_error) goto fornext_error2;
  9. goto fornext_entrylabel2;
  10. while(1){
  11. fornext_value2=fornext_step2+(*__SINGLE_I);
  12. fornext_entrylabel2:
  13. *__SINGLE_I=fornext_value2;
  14. if (fornext_step_negative2){
  15. if (fornext_value2<fornext_finalvalue2) break;
  16. }else{
  17. if (fornext_value2>fornext_finalvalue2) break;
  18. }
  19. fornext_error2:;
  20. tmp_long=(qbr(*__SINGLE_I))-__ARRAY_BYTE_B[4];
  21. if (!new_error) ((int8*)(__ARRAY_BYTE_B[0]))[tmp_long]=qbr_float_to_long(*__SINGLE_I);
  22. tmp_long=(qbr(*__SINGLE_I))-__ARRAY_STRING1_S[4];
  23. if (!new_error) qbs_set(qbs_new_fixed(&((uint8*)(__ARRAY_STRING1_S[0]))[tmp_long*1],1,1),func_chr(qbr(*__SINGLE_I)));
  24. qbs_cleanup(qbs_tmp_base,0);
  25. fornext_continue_1:;
  26. }
  27. fornext_exit_1:;
  28. sub_open(qbs_new_txt_len("temp.txt",8), 2 ,NULL,NULL, 1 ,NULL,0);
  29. qbs_cleanup(qbs_tmp_base,0);
  30. sub_put( 1 ,NULL,byte_element((uint64)(&(((int8*)(__ARRAY_BYTE_B[0]))[0])),(1*(__ARRAY_BYTE_B[2]&1)*__ARRAY_BYTE_B[5])-(1*(0)),byte_element_3),0);
  31. //sub_put( 1 ,NULL,byte_element((uint64)(&(qbs_new_fixed(&((uint8*)(__ARRAY_STRING1_S[0]))[(0)*1],1,1))),(1*(__ARRAY_STRING1_S[2]&1)*__ARRAY_STRING1_S[5])-(1*(0)),byte_element_4),0);
  32. sub_put( 1 ,NULL,byte_element((uint64)(&(((uint8*)(__ARRAY_STRING1_S[0]))[(0)*1])),(1*(__ARRAY_STRING1_S[2]&1)*__ARRAY_STRING1_S[5])-(1*(0)),byte_element_4),0);
  33. qbs_cleanup(qbs_tmp_base,0);
  34. sub_end();
  35. return;
  36. }
  37.  

Now, you might notice that there's a line already commented out for us above -- that's the line that's producing the glitch for us.  Let me grab it and the line above it and below it to highlight the issue...

Here's the line above it, which works for _BYTE arrays:
sub_put( 1 ,NULL,byte_element((uint64)(&(((int8*)(__ARRAY_BYTE_B[0]))[0])),(1*(__ARRAY_BYTE_B[2]&1)*__ARRAY_BYTE_B[5])-(1*(0)),byte_element_3),0);

And here's our problem line, as we're currently translating it:
sub_put( 1 ,NULL,byte_element((uint64)(&(qbs_new_fixed(&((uint8*)(__ARRAY_STRING1_S[0]))[(0)*1],1,1))),(1*(__ARRAY_STRING1_S[2]&1)*__ARRAY_STRING1_S[5])-(1*(0)),byte_element_4),0);

And, if we change it to match the previous syntax, it works as it should for us with:
sub_put( 1 ,NULL,byte_element((uint64)(&(((uint8*)(__ARRAY_STRING1_S[0]))[(0)*1])),(1*(__ARRAY_STRING1_S[2]&1)*__ARRAY_STRING1_S[5])-(1*(0)),byte_element_4),0);

The issue is in the colored sections which I'll highlight here, which really don't seem to be needed at all in the code:
sub_put( 1 ,NULL,byte_element((uint64)(&(qbs_new_fixed(&((uint8*)(__ARRAY_STRING1_S[0]))[(0)*1],1,1))),(1*(__ARRAY_STRING1_S[2]&1)*__ARRAY_STRING1_S[5])-(1*(0)),byte_element_4),0);



If someone can find the segment in our source (QB64.BAS, I'd imagine) that's adding the section above to our output, and we can remove it, I think the issue will disappear for us.  Unfortunately, as you can tell from the code above, the source for this translation is kinda a mess, and so far, I haven't been able to locate the line(s) that are producing this extra, unneeded information for us. 

I think I've zoomed in and found the problem, but I'm still looking for where the shooting range is, before I can even take a shot at fixing the glitch itself.  :P



And for those that want to test the fix for themselves, you can manually go into main.txt and make the changes to your own code, and then run recompile.bat to create an EXE which works without issue while putting a whole string * 1 array to file.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Compilation failed, log shows PUT fixed length string array
« Reply #14 on: March 02, 2021, 04:34:41 pm »
In QB64.bas, lines 14154 - 14168

Code: QB64: [Select]
  1.             If cmemlist(idn + 1) Then
  2.                 id.t = id.t + ISINCONVENTIONALMEMORY
  3.                 If f Then Print #13, "if(" + n$ + "==NULL){"
  4.                 If f Then Print #13, "cmem_sp-=" + str2(bytes) + ";"
  5.                 If f Then Print #13, "if (cmem_sp<qbs_cmem_sp) error(257);"
  6.                 If f Then Print #13, n$ + "=qbs_new_fixed((uint8*)(dblock+cmem_sp)," + str2(bytes) + ",0);"
  7.                 If f Then Print #13, "memset(" + n$ + "->chr,0," + str2(bytes) + ");"
  8.                 If f Then Print #13, "}"
  9.             Else
  10.                 If f Then Print #13, "if(" + n$ + "==NULL){"
  11.                 o$ = "(uint8*)mem_static_malloc(" + str2$(bytes) + ")"
  12.                 If f Then Print #13, n$ + "=qbs_new_fixed(" + o$ + "," + str2$(bytes) + ",0);"
  13.                 If f Then Print #13, "memset(" + n$ + "->chr,0," + str2$(bytes) + ");"
  14.                 If f Then Print #13, "}"
  15.             End If
Shuwatch!