Author Topic: Re: QB 4.5 minor incompatibility  (Read 985 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

FellippeHeitor

  • Guest
Re: QB 4.5 minor incompatibility
« on: December 23, 2018, 07:55:44 pm »
In QB64, if it's not immediately followed by the colon then it's not considered a label. I do see what you mean by QB64 prioritising it as a sub even with the colon immediately following it.

I hope you found that by chance and not because some older program of yours relied on that odd behaviour.

Either way, thanks for reporting.
« Last Edit: December 23, 2018, 07:56:54 pm by FellippeHeitor »

FellippeHeitor

  • Guest
Re: QB 4.5 minor incompatibility
« Reply #1 on: December 23, 2018, 08:15:10 pm »
After a quick look at QB64's source looking for labels vs subs it seems Galleon had the original behaviour in mind at some point:

At ~ line 3450:
Code: QB64: [Select]
  1.     'label?
  2.     'note: ignores possibility that this could be a single command SUB/FUNCTION (as in QBASIC?)

But then there's this:
Code: QB64: [Select]
  1. SubNameLabels = sp 'QB64 will perform a repass to resolve sub names used as labels

The reason behind it is unknown.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Q
« Reply #2 on: December 24, 2018, 03:01:02 am »
by that method should you not be able to use PRINT, LINE, OPEN ect as line labels too? seems to me QB64s approach is more, shall we say 'Logical', once you define a SUB\FUNCTION shouldn't its name be treated like syntax?
I had an odd occurance though, I ran the following code in QB45,
Code: QB64: [Select]
  1. hello: if inkey$<>chr$(27) then hello
  2.  
  3. sub Hello
  4. print hellob
  5.  

the first time I ran this, It hung. it treated the "THEN HELLO" as a "goto hello" and waited until i pressed ESC
but the second time and then on it treated the THEN HELLO as a sub call and printed 0 and quit on its own. I had to restart DOSBOX to cause it to repeat this and then only randomly. might be an error with my copy of dosbox.

now I havent used GOTO since GWBasic and then only rarely,so why can't I do this,

Code: QB64: [Select]
  1. hello: if inkey$<>chr$(27) then hello
  2.  
  3. sub Hello
  4. GOTO hello
  5.  
That one says "Label not defined"
BUT
Code: QB64: [Select]
  1. hello: if inkey$<>chr$(27) then hello
  2.  
  3. sub Hello
  4. hello:
  5. GOTO hello
  6.  
that one says "duplicate label"
I mean WTH!, it can't find the label to GOTO in the SUB but if I add it in the SUB all the sudden IT knows there is already a hello label? or is it now realizing that Hello is already taken as the SUB name? by all means it should flag the first occurrence of hello and SUB hello as duplicate label or else treat the 'label' hello as a syntax and call the sub there first. its not like it lets you use PRINT as a label, but by all means to be fair with this phenomenon you should be able to.

maybe Galleon realized it wouldn't be worth it to allow such poor coding practices to propagate on. or maybe I am just ranting because of such vulgar coding practice and lack of sleep(3 am here) coupled with my extreme (irrational) hatred of GOTO jumping. or I have completely missed the whole point of the issue,(reporting that QB64 doesn't behave just like QB45) QB64 isn't meant to be a  100% clone of QB45, just really close as modern OS can allow. This is one thing I personally believe we don't need to duplicate.
Granted after becoming radioactive I only have a half-life!

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: QB 4.5 minor incompatibility
« Reply #3 on: December 24, 2018, 06:05:37 am »
Fun fact: on my personal list of syntactic pet peeves, this one (using the : for both labels and statement concatenation) takes the cake at #1.

I don't know who thought was a good idea at the time.

Marked as best answer by on November 12, 2024, 06:50:22 pm

Offline Stuart

  • Newbie
  • Posts: 11
    • View Profile
Re: Q
« Reply #4 on: December 24, 2018, 06:45:46 am »
  • Undo Best Answer
  • I had an odd occurance though, I ran the following code in QB45,
    Code: QB64: [Select]
    1. hello: if inkey$<>chr$(27) then hello
    2.  
    3. sub Hello
    4. print hellob
    5.  

    the first time I ran this, It hung. it treated the "THEN HELLO" as a "goto hello" and waited until i pressed ESC
    but the second time and then on it treated the THEN HELLO as a sub call and printed 0 and quit on its own. I had to restart DOSBOX to cause it to repeat this and then only randomly. might be an error with my copy of dosbox.

    This runs without any problems when I use QB4.5 -- "THEN HELLO" is always treated as a SUB call.
    NOTE :  When using QB4.5, "GOTO" is optional with a line number but is _required_ with a line label.


    now I havent used GOTO since GWBasic and then only rarely,so why can't I do this,

    Code: QB64: [Select]
    1. hello: if inkey$<>chr$(27) then hello
    2.  
    3. sub Hello
    4. GOTO hello
    5.  
    That one says "Label not defined"

    The reason for that is because you can't use GOTO, GOSUB, or RETURN to enter or exit a subprogram.
    The label that you want to GOTO is required to be _inside_ the SUB.


    BUT
    Code: QB64: [Select]
    1. hello: if inkey$<>chr$(27) then hello
    2.  
    3. sub Hello
    4. hello:
    5. GOTO hello
    6.  
    that one says "duplicate label"

    That's because the same name for a label was used in the module-level code.
    Each line number or label in a module is _required_ to be unique -- including all the SUB and function definitions in the module.