Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Do pointers exist in basic4ppc?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-24-2009, 02:29 PM
Junior Member
 
Join Date: Sep 2009
Posts: 14
Question Do pointers exist in basic4ppc?

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

Reply With Quote
  #2 (permalink)  
Old 11-24-2009, 03:33 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

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"
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 11-24-2009 at 03:40 PM.
Reply With Quote
  #3 (permalink)  
Old 11-24-2009, 03:50 PM
Junior Member
 
Join Date: Sep 2009
Posts: 14
Red face

Ah,

Yes it is safer not to use them, thx for the reply Agraham.

Greetz,
Mike
Reply With Quote
  #4 (permalink)  
Old 11-24-2009, 04:28 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 592
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Code:
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
Or have I totally misread or understood your post.
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
Reply With Quote
  #5 (permalink)  
Old 11-24-2009, 04:44 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by taximania View Post
[code]when I go back to check my stored data in b(), it will have changed.
That is correct, try it.
Code:
Sub Globals
    
'Declare the global variables here.
    Dim A(1)
    
Dim B(0)
    
Dim C(0)
End Sub

Sub App_Start
    B() = A()
    C() = A()
    A(
0) = "fred"
    
Msgbox(B(0) & " " & C(0))
End Sub
It's not really dangerous as long as you know what is happening. This is the way .NET reference types work, and just about everything apart from numbers are reference types in .NET. In Basic4ppc you would use ArrayCopy if you wanted to make sure the original array was unchanged.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #6 (permalink)  
Old 11-24-2009, 04:48 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 1,057
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Quote:
Originally Posted by taximania View Post
[code]This sounds totally dangerous
References are not dangerous, but it's dangerous not to know if you work with a reference or not.

If you need a real copy of an array you have to use ArrayCopy.

Code:
Sub Globals
    
'Declare the global variables here.
     Dim A(10)
     
Dim B(0)
    
Dim C(0)

    
Dim AA(10)
     
Dim BB(10)
    
Dim CC(10)
End Sub

Sub App_Start
    Form1.Show
    
    A(
0) = "taxi"
    B() = A()
    C() = A()
    A(
0) = "fred"
    
Msgbox(B(0) & " " & C(0)) ' shows "fred fred" 

    AA(
0) = "taxi"    
    ArrayCopy(AA(), 
0, ArrayLen (AA()), BB(), 0)
    ArrayCopy(AA(), 
0, ArrayLen (AA()), CC(), 0)
    AA(
0) = "fred"
    
Msgbox(BB(0) & " " & CC(0)) ' shows "taxi taxi" 

End Sub
specci48


Edit: sorry agraham, 4 minutes late....
Reply With Quote
  #7 (permalink)  
Old 11-24-2009, 06:27 PM
taximania's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire. UK
Posts: 592
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Many thanks Agraham and Specci48.
This was something I was totally unaware of.

I knew ArrayCopy existed, but never knew why.
a()=b() Sorted 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 :Purelly written for the forum search

Ta guys
__________________
.
.
.
Don't ask, I'm fine, honest. !!
.
.
.
Just a little crazy at times



O2 XDA, GW Evo 2.1 UC WWE Rom, WM6.1
Radio Ver 03.34.90
With Basic4ppc V6.80


http://www.taximania.co.uk
Reply With Quote
  #8 (permalink)  
Old 11-25-2009, 07:55 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,734
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

I'll just add that the idea behind it (in Basic4ppc) is to avoid the memory and time involving in copying large arrays. Especially when you have libraries that get or return arrays.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On


All times are GMT. The time now is 10:35 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0