LB Booster
« Contrived code »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 03:30am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Contrived code  (Read 210 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Contrived code
« Thread started on: Nov 25th, 2016, 1:25pm »

In general, the more 'contrived' the Liberty BASIC code the greater the likelihood of encountering an incompatibility with LBB. I recently came across some code which boiled down to this:

Code:
    array(newdim(100)) = 123
    end

function newdim(n)
    redim array(n)
    newdim = n
end function 

The essence of this code is that the array is dimensioned in a function called during the evaluation of the array's subscript! Whether or not this code will run successfully depends on the precise sequence of events inside the BASIC interpreter.

If the array's dimensions are determined before the subscript is evaluated the code will fail, because an attempt is being made to access an element of an array that doesn't yet exist. If, on the other hand, the array's dimensions are determined after the subscript is evaluated, the code will succeed.

It so happens that the former is true in LBB, so the code fails, whereas the latter is true in LB 4, so the code runs successfully. Quite why anybody would deliberately write code like that is a mystery; it would be much easier to understand and much easier to debug if split into two statements like this:

Code:
    subscript = newdim(100)
    array(subscript) = 123 

This code will of course run successfully in both LB 4 and LBB.

So the moral is: contrived code which relies on undocumented internal behavior of the interpreter is inevitably less likely to run successfully in LBB.

Richard.
User IP Logged

Mystic
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 53
xx Re: Contrived code
« Reply #1 on: Nov 25th, 2016, 5:19pm »

I love these little nuggets of knowledge!

Thanks Richard!
User IP Logged

- Rick
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls