[Implemented] DIM index range check?

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] DIM index range check?

Post by BackupUser »

Restored from previous forum. Originally posted by horst.

Purebasic accepts an index beyond the range defined by DIM,
but the program may crash (or other data may be overwritten?).

It would be a great help if this would produce an "Index
beyond range" error by the compiler.

Another one:

If I use a DIM variable without index, like:

DIM bla(2)
bla = 12

this is just ignored by Purebasic (but I have not checked for
side effects.. Does it overwrite other data?)



Horst
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.
If I use a DIM variable without index, like:

DIM bla(2)
bla = 12

this is just ignored by Purebasic (but I have not checked for
side effects.. Does it overwrite other data?)
You change the pointer to the array, so don't do this unless you really know what you're doing..
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
DIM bla(2)
bla = 12
you just declare a new variable long, called bla

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by horst.
You change the pointer to the array, so don't do this unless you really know what you're doing..
Oops,I didn't know it was so easy to produce a desaster
by mistake.


Horst
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by horst.
you just declare a new variable long, called bla
Yes, but let's assume I just forgot the index (0).
I did not know that "bla = 12" is a meaningful and legal
instruction (when bla is an array).


Horst
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

array and variable can have the same name. It's different objects..

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> DIM bla(2)
> bla = 12

What you've done here is create 4 variables: bla(0), bla(1), bla(2), and bla.
Perfectly normal for all versions of basic, including PureBasic.

PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by horst.
array and variable can have the same name. It's different objects..
Thanks, I got a little confused.
I have to get used to these Basic features...


Horst
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Pupil.
You change the pointer to the array, so don't do this unless you really know what you're doing..
Disregard what i said, i was mixing things up a bit. If you for instance would have done it this way bla()=12 then my claims of changing array pointers would have been true, but you didn't do it that way, so don't read this as it will only add to the confusion :wink:
Post Reply