Author Topic: Bug Report for STATIC with RUN or CLEAR statement.  (Read 3773 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Bug Report for STATIC with RUN or CLEAR statement.
« on: November 18, 2018, 12:08:03 am »
RUN and CLEAR statements should clear all variables. The code below uses RUN but errors out with subscript out of range in line 12.

Code: QB64: [Select]
  1. testsub
  2.  
  3. PRINT "Hello World"
  4.  
  5. SUB testsub
  6. STATIC testarray(1 TO 100)
  7. FOR i = 1 TO 100
  8.     testarray(i) = i
  9.  

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Bug Report for STATIC with RUN or CLEAR statement.
« Reply #1 on: November 18, 2018, 02:25:04 am »
Hi Pete. If you place as first:

REDIM SHARED testarray(1 TO 100)

then it run correctly.

And STATIC you need not, why preserve field values, if this are in next loop rewrited to the same values.
« Last Edit: November 18, 2018, 02:40:42 am by Petr »

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Bug Report for STATIC with RUN or CLEAR statement.
« Reply #2 on: November 18, 2018, 04:07:27 am »
The program Pete gave does not compile in QuickBASIC. Here is one that does:
Code: QB64: [Select]
  1. testsub
  2.  
  3. PRINT "Hello World"
  4.  
  5. SUB testsub
  6.     STATIC testarray()
  7.     DIM testarray(1 TO 100)
  8.     FOR i = 1 TO 100
  9.         testarray(i) = i
  10.     NEXT
Given that, and the fact that the above program does behave correctly in QB64, and that RUN and arrays are, in general, a huge mess, I'm not going to be rushing to fix this any time soon (and I seriously hope you're not using RUN in any new programs).

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Bug Report for STATIC with RUN or CLEAR statement.
« Reply #3 on: November 18, 2018, 09:31:16 am »
Here's a bug in QB64 with STATIC:

Code: QB64: [Select]
  1. testsub
  2.  
  3. PRINT "Hello World"
  4.  
  5. SUB testsub
  6.     STATIC testarray()
  7.     DIM testarray(1 TO 100)
  8.     DIM testarray(1 TO 100)
  9.     FOR i = 1 TO 100
  10.         testarray(i) = i
  11.     NEXT

If we try to DIM a static variable inside the main part of our program (such as DIM x(10) twice in a row), we get an error, "cannot redim a static array/variable".  Inside a SUB, such as above, the IDE thinks it should work just fine.  Compiling it, however, gives the expected, "Duplicate Definition" error.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Bug Report for STATIC with RUN or CLEAR statement.
« Reply #4 on: November 18, 2018, 11:44:06 am »
Hi Pete. If you place as first:

REDIM SHARED testarray(1 TO 100)

then it run correctly.

And STATIC you need not, why preserve field values, if this are in next loop rewrited to the same values.

Yep, that's the workaround for the bug but this wasn't a program of mine I was having a problem with. it was something I was testing with Steve, ironically to try and locate another bug in _LOADFONT. I added a RUN statement to automatically test for crashes and than this STATIC / RUN bug popped up. I checked the bug list for problems with STATIC and couldn't find any search results, so I posted here for bug report submission. Steve had mentioned issues with RUN but having a specific bug report for STATIC might help some other poor sap who encounters this and wonders what the hell isn't working right. Maybe it would be good for others to add a list of other known RUN / CLEAR problems?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Bug Report for STATIC with RUN or CLEAR statement.
« Reply #5 on: November 18, 2018, 12:19:19 pm »
Oh, thanks for the clarification, Pete.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Bug Report for STATIC with RUN or CLEAR statement.
« Reply #6 on: November 18, 2018, 01:05:35 pm »
Actually, I should apologize for not mentioning I was not having a code problem, which is how most people stumble upon bugs, but if you would just spend your time on politics, instead of trying to help people, this wouldn't be an issue! :D

Anyway, yesterday when I was testing the code I did substitute in REDIM SHARED testarray(1 TO 100), the same thing you came up with, just to be sure it was the STATIC keyword that was messing up the RUN and CLEAR statements, and it was.

@powers that be:
I did check the WIKI, and if RUN and CLEAR have had other issues, why hasn't someone placed these in a known issue thread?
http://qb64.org/wiki/Main_Page#Known_issues

Under the WIKI RUN statement, it does mention these:

RUN should reset the RANDOMIZE sequence to the starting RND function value.(Not in QB64)
Note: Qbasic also allowed /RUN in a command line call to run a BAS file with the interpreter. QB64 cannot run BAS files!
Note: RUN causes a stack leak in QB64 if it is called from within a SUB or FUNCTION. Avoid when possible!
NOTE: Not available in Linux or Mac operating systems.

If anyone is still updating the WIKI, maybe STATIC should be added. Also, if the "Known Issues" will not be including all known issues, maybe consider adding something like: Check keywords in the WIKI for known issues with particular QB64 statements.

Pete



Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/