ST BASIC and its bugs

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

Post Reply
Robbizz
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 118
Joined: Wed Jul 01, 2020 7:08 pm

ST BASIC and its bugs

Post by Robbizz »

I am using ST Basic to load a program in machine language thanks to the DATA instructions, when, a little doubtful, I go back to looking at the syntax and the explanations of how the dimensioning of an array in C works; face that in STBASIC it works in my opinion incorrectly.
For example, when you want to create a vector of 10 elements of integer type, in C it works like this:

Code: Select all

int myarray[10];
where the first element has index 0, and the last element has index 9.
In STBASIC instead it can be done like this:

Code: Select all

10 DIM myarray%(9)
you can easily refer to the element with index 0 (rightly), but we can go up to and including index 9: 10 elements in total even if we have declared 9 elements.

Reading the ST BASIC manual it seems that the behavior that the DIM instruction must have is similar to that of C.
Are any of you aware of this? Is it to be considered a bag? On the internet I found many bugs on ST BASIC, but not this one.
Playmobil
Captain Atari
Captain Atari
Posts: 261
Joined: Fri Nov 13, 2015 7:40 pm

Re: ST BASIC and its bugs

Post by Playmobil »

In GFABASIC, DIM dummy&(10), make an array from 0 to 10, so 11 elements...
Robbizz
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 118
Joined: Wed Jul 01, 2020 7:08 pm

Re: ST BASIC and its bugs

Post by Robbizz »

Playmobil wrote: Tue May 24, 2022 9:18 pm In GFABASIC, DIM dummy&(10), make an array from 0 to 10, so 11 elements...
In ST BASIC Sourcebook and Tutorial 1987 we have:
ST BASIC establishes the size of an array the first time you refer to it. The default size of an array is 10 rows by 10 columns (10,10). You can declare your own array dimensions with the DIM statement. DIM TOTAL (5,50) defines TOTAL as an array with 5 rows and 50 columns.

In Tim Knight's Atari ST Basic Programming Book we have (more precise than the previous definition):

If you don't use OPTION BASE, any array of variables you set will start at element 0; so, if you type DIM A (5), you will have A (0), A (1), A (2), A (3), A (4) and A (5). However, many people prefer to start from the number 1 instead of 0 and just type OPTION BASE 1 for the matrix to start from element 1. OPTION BASE 1 followed by DIM A (5) will provide you with the variables A (1), A (2 ), A (3), A (4) and A (5). If you want to return to the default setting, just type OPTION BASE 0.

So I think it's a BUG from the ST BASIC Sourcebook and Tutorial 1987 ...
xdelatour
Atariator
Atariator
Posts: 18
Joined: Sun Mar 02, 2008 11:14 pm
Location: Poitiers (France)
Contact:

Re: ST BASIC and its bugs

Post by xdelatour »

In this book (ST BASIC Sourcebook and Tutorial, 1987, available on docs.dev-docs.org), "OPTION BASE" is described page 155 :

Code: Select all

Example:
OK 10 OPTION BASE 1
Ok 20 DIM A%(10)
Ok 30 OPTION BASE 0
Ok 40 DIM B%(10)
A% now has 10 elements, 1-10. B% has 11 elements, 0-10.
10 is the upper bound, not the count of elements.
Robbizz
Obsessive compulsive Atari behavior
Obsessive compulsive Atari behavior
Posts: 118
Joined: Wed Jul 01, 2020 7:08 pm

Re: ST BASIC and its bugs

Post by Robbizz »

In that book, I was talking about that definition of DIM (page 52) without any reference to option base.
Post Reply

Return to “Other BASIC”