Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best Practice for Library Building and Toolboxes
#14
(10-18-2023, 07:54 PM)bplus Wrote: We (QB64) have ways of reading the lower and upper bounds of an array usually code lb and ub.
So generic code in library would not assume 0 or 1 but find out exactly lb = lbound(array) ub = ubound(array) and then proceed to use lb and ub.

You miss the point here:

What you suggest is absolutely true, if an array is passed to a library function as an argument, hence the array already exists and inside the function you just need to find out its LBOUND and UBOUND.

What I'm talking about is, if the library function itself needs to create an array for internal use without knowing if the base element is set to 0 or 1, then the (x TO y) syntax makes sure the array is created as I need it inside the function.

Of course we could also go the bulky way, 1st creating the array as usual (assuming base element is zero), 2nd use LBOUND on the array to check if the base is really zero and if not (base element is one), then 3rd redim the array with one more element.
However, that would be dumb, as in most cases there are also index counters like in a FOR/NEXT which need to know the correct lb and ub.

So alltogether, in a library funcntion just DIM a(0 TO 4) and be sure it works if you later access the array in a FOR i=0 TO 4 loop.
Reply


Messages In This Thread
RE: Best Practice for Library Building and Toolboxes - by RhoSigma - 10-18-2023, 09:22 PM



Users browsing this thread: 10 Guest(s)