marcuslee
08-09-2008, 03:09
I found BOUNDCHECK while compiling my list of help file gaps (http://community.thinbasic.com/index.php?topic=2013.0). I didn't include it in the list because its documentation was just fine. But, I wonder: why is BOUNDCHECK needed? When would you ever want to use it?
Mark ???
Petr Schreiber
08-09-2008, 08:42
Hi Mark,
this one very useful feature! Thanks for bringing this topic here, let me explain.
#DEFAULT BOUNDCHECK ON
Positives:
-Invaluable when debugging, it cannot happen you write to bad index of array and program crashes, because ThinBasic informs you immediately what bad index you tried to use, and what are allowed values.
When you specify array index by number, you probably won't do any mistake. But if you use some variable, it is quite common you will supply wrong index by accident.
This feature was very useful for me when I was experimenting with binary MD2 fileformat - when I loaded bad part of file thinking it is where indices are stored, invalid loaded data were captured by ThinBasic so I knew exactly where problem was.
Negatives:
- It might make script execution a bit slower, as each array index is tested for validity.
#DEFAULT BOUNDCHECK OFF
Positives:
- Best for final, tested scripts for release. It provides the best execution speed, as no checking is performed
Negatives:
- In case you tested your program well ... none. In untested program with wrong indices your program might crash and you do not know why.
Hope I put more light on the topic,
Petr
marcuslee
08-09-2008, 13:47
That makes sense. Thank you for clarifying that up for me.
Mark