GOTO -1

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Post Reply
User avatar
hellomike
Posts: 55
Joined: Sat 09 Jun 2018, 09:47

GOTO -1

Post by hellomike » Fri 08 Nov 2019, 20:30

Hi,

Yes, indeed, after days of coding I ended up with this 'program' ;)

Code: Select all

	GOTO -1
Actually found that this 'program' crashes BB4W 6.12a. No error message, just dies.

SLIDE 1.07a also stops silently but unlike BB4W, the editor stays put.

Of course this would never occur in modern (>1988) programming since no one is using GOTO's. So I can't be bothered but I thought Richard would like to be aware of it. It could give unexpected behavior in old large sources that uses calculated GOTO's, like: GOTO A.

I stumbled on it after copying the Sinclair ZX81 BASIC source verbatim from: http://rosettacode.org/wiki/Chaos_game# ... ZX81_BASIC

Regards,

Mike

RichardRussell
Posts: 94
Joined: Tue 15 Oct 2019, 09:10

Re: GOTO -1

Post by RichardRussell » Fri 08 Nov 2019, 22:08

hellomike wrote:
Fri 08 Nov 2019, 20:30
I thought Richard would like to be aware of it.
I am. You may be surprised to learn that it happens 'by design'. :o

In the 'old days', before the introduction of labels in BB4W and BBCSDL, the only valid destination of a GOTO, GOSUB or RESTORE was a line number, which must be in the range 1-65535. So before labels existed 'GOTO -1' was equivalent to 'GOTO 65535' and wouldn't crash. But with labels any value is accepted and if outside the range 1-65535 is assumed to be the address of a label in your program.

If you know about such things, you will be aware that 'address validation', that is determining whether an address corresponds to 'real' (accessible) memory or not, isn't straightforward. Raymond Chen, the Microsoft guru and blogger, takes the view that the easiest and safest way to deal with an invalid address is to allow your program to crash, so I do!

One of the advantages of BBCSDL over BB4W is that the IDE and the user's BASIC program(s) run in separate processes, so are isolated from one another by the OS. However catastrophically a BASIC program crashes, it should not be possible for it to bring down the IDE. Of course crashing may not be the best thing to do from the point of view of debugging - it can make finding the cause of the fault more difficult.

I could treat -1 as a special case, since it's highly unlikely to be the address of a label, but currently my interpreters accept all values. If you use GOTOs in your programs you deserve everything you get... :evil:
My posts are moderated; if you are seeing this it has already been approved. If you have a comment about the style or tone of the message please report it to the moderators by clicking the exclamation mark icon rather than complaining on the public forum.

User avatar
hellomike
Posts: 55
Joined: Sat 09 Jun 2018, 09:47

Re: GOTO -1

Post by hellomike » Sat 09 Nov 2019, 09:17

If you use GOTOs in your programs you deserve everything you get... :evil:
Fair enough Richard. I feel I do have not to emphasize it but to be absolutely clear on this: it was NOT a complaint.

Regards,

Mike

Soruk
Posts: 5
Joined: Mon 30 Jul 2018, 20:24

Re: GOTO -1

Post by Soruk » Mon 11 Nov 2019, 12:59

For the purpose of comparison, Matrix Brandy allows GOTO 0 (and a program line number of 0). Indeed the range 0..65279 is valid.

GOTO -1 (and any negative number, or a variable) gives "Syntax error". GOTO requires a constant, you cannot give it a variable.

p_m21987
Posts: 144
Joined: Mon 02 Apr 2018, 21:51

Re: GOTO -1

Post by p_m21987 » Mon 11 Nov 2019, 19:37

I'm surprised to hear that, Soruk. I remember using GOTO with a variable in a program I wrote for the BBC Micro. Did BASIC on the ARM/Archimedes allow GOTO with variables?

RichardRussell
Posts: 94
Joined: Tue 15 Oct 2019, 09:10

Re: GOTO -1

Post by RichardRussell » Mon 11 Nov 2019, 23:26

Soruk wrote:
Mon 11 Nov 2019, 12:59
GOTO requires a constant, you cannot give it a variable.
Are you sure? That seems unlikely given that every other implementation of BBC BASIC I am aware of does allow a variable to be used as the destination of a GOTO. It certainly works in the original 6502 BASIC and in Acorn's ARM BASIC (which Brandy is generally closely compatible with). It also works in all my BASICs: Z80, 8086, Windows and SDL 2.0 (including 64-bit and ARM editions).
My posts are moderated; if you are seeing this it has already been approved. If you have a comment about the style or tone of the message please report it to the moderators by clicking the exclamation mark icon rather than complaining on the public forum.

KenDown
Posts: 91
Joined: Wed 04 Apr 2018, 06:36

Re: GOTO -1

Post by KenDown » Tue 12 Nov 2019, 04:39

10 x%=20
20 PRINT"Test""
30 GOTO x%

This works fine *provided* you have line numbers. If you do not - which is the default with BB4W - you get a "No such line no." error. I should imagine that GOTO 20 would produce the same error.

Soruk
Posts: 5
Joined: Mon 30 Jul 2018, 20:24

Re: GOTO -1

Post by Soruk » Tue 12 Nov 2019, 09:37

KenDown wrote:
Tue 12 Nov 2019, 04:39
10 x%=20
20 PRINT"Test""
30 GOTO x%

This works fine *provided* you have line numbers. If you do not - which is the default with BB4W - you get a "No such line no." error. I should imagine that GOTO 20 would produce the same error.
It looks like we've unearthed another Brandy bug!

Code: Select all

Matrix Brandy BASIC VI version 1.22.1 (Linux) 20 Sep 2019

Starting with 524288 bytes free

>10 x%=20
>20 PRINT "Test"
>30 GOTO x%
>RUN
Test

Syntax error at line 30
>_
Edit: It turns out expressions and variables were allowed, if wrapped in parentheses. I've removed this restriction for variables (still required for expressions that begin with a number), and matches behaviour for BASIC IV, V and VI.

Post Reply