Do pointers exist in basic4ppc?

rmschreuder

Member
Licensed User
In C++ there are variables that can be declared pointers, so one can address more objects of the same type by setting a pointer to point to one of them.
This is very usefull, does that exist in b4ppc?

Mike

 

agraham

Expert
Licensed User
Longtime User
No. They are considered dangerous due to type-safety and buffer overrun considerations and are discouraged in .NET based languages. C# for example offers reference parameters and delegates, which are type-safe function pointers, to avoid the need for the explicit use of pointers.

Also most objects in .NET are adressed by reference so setting a variable to an instance of a reference type is actually setting a pointer to it. For instance a Basic4ppc array is a reference type so if you assign the same arrays to two different array variables they will all actually be be the same array.

Dim A(10)
Dim B(0)
Dim C(0)
...
B() = A()
C() = A()
A(0) = "fred"
msgbox(B(0) & " " & C(0)) ' shows "fred fred"
 
Last edited:

taximania

Well-Known Member
Licensed User
Longtime User
B4X:
B() = A()
C() = A()
A(0) = "fred"
msgbox(B(0) & " " & C(0)) ' shows "fred fred"

Sorry for me being thick AGraham. Are you saying,

if I'm using an array a()
and want a copy of the data currently in the array, b()=a()
then alter the data in a()
when I go back to check my stored data in b(), it will have changed.

This sounds totally dangerous :sign0137:
Or have I totally misread or understood your post.
 

agraham

Expert
Licensed User
Longtime User
 

specci48

Well-Known Member
Licensed User
Longtime User
 

taximania

Well-Known Member
Licensed User
Longtime User
Many thanks Agraham and Specci48.
This was something I was totally unaware of.

I knew ArrayCopy existed, but never knew why.
a()=b() Sorted :sign0060: NOT !!

I'm glad I asked the question, It might be of help to others.
I've probably spent hours in the past trying to figure out why arrays don't
contain the data I thought they should do.

copy array urelly written for the forum search

Ta guys
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…