Array Ubound problem

Started by Nicola, November 13, 2023, 11:39:47 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nicola

Hi Charles,
Are there any problems with the ubound function?

I've tried this and it gives me some problems..

uses console
redim double a[5]

print "ubound of array: " ubound(a)

sub ff(double *d[])
===================
print "Test attributes of a passed dynamic array" cr cr
int i
print "dims: " tab dims(d) cr
print cr
print "ubound of array: " ubound(d)
end sub
'
'TEST:
ff a
wait
del a

This is the result I get:

ubound of array: 0
Test attributes of a passed dynamic array

dims:  1995979616

ubound of array: 0








http://forum.it-berater.org/index.php?msg=25169

Charles Pegge

#1
Hi Nicola,

It worked perfectly with multidimensional arrays. But I've now fixed it for 1d arrays:

PS:
Not quite!
My changes failed the self-compile test so I've withdrawn P9 until I have fixed the problem

Nicola

In fact, Charles,
I was still having trouble and thought it was me who wasn't declaring the variables correctly... 
I was having incomprehensible results.
Thank you for your valuable help.
Good luck with your work.

I'm looking forward to the new P9.

Cheers

Nicola

Hi Charles.
Could you please update me on the progress related to the Arrays?
Ubound? and other related commands working properly now?

Thank you very much.

Charles Pegge

Ubound etc last tested in March. Should be ok now.

Nicola

very good.  :)
In fact, I wasn't making use of arrays while waiting for news.
Thank you Charles.

Zlatko Vid

I must ask ..why you need Ubound
i never use it and i don't see purpose of that even some QB64 programeros
use them a lot ..same as REDIM ...omg ...maybe i am to limited or biased
to minimalism ... :D

Theo Gottwald

#7
Quote from: Zlatko Vid on May 03, 2024, 06:13:48 PMI must ask ..why you need Ubound
i never use it and i don't see purpose of that even some QB64 programeros
use them a lot ..same as REDIM ...omg ...maybe i am to limited or biased
to minimalism ... :D

Let me answer this.
Assume you hand over an ARRAY BYREF into a Function to do something with the Array Members.
How do yo ufind out if the Array is 0-based or 1-based and how large it is?
This is where LBOUND and UBOUND can help.

Charles Pegge

To clarify:
You can reference an array using any indexbase - it does not have to be the original indexbase, the lbound and ubound will automatically adjust. They are particularly useful for dynamic arrays.

Nicola

Good morning.
For me the use of vectors or matrices are very important. Since I was in school I learned how to use them and I stuck with them.
As Charles has shown through the examples in... demos\math, are very useful...

Zlatko Vid

QuoteHow do yo ufind out if the Array is 0-based or 1-based and how large it is?

easy
indexbase ..you define yourself
sizeOf() return array size

Charles Pegge

Indexbase can be  read as well as set:
print indexbase

sizeof only works for elements, not arrays in o2

Zlatko Vid

#12
and for what is spanof()

ahh yes ...spanof() seems that work  ;)
ye i remember, i use it few times .

'quick test
int arr[1000]

print spanof(arr)