Arrays as parameters for procedures

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by VeKem.

Hi,

coming from PowerBASIC and meeting PureBasic now, I'm wondering we can't set arrays as parameters to procedures. Maybe this will be possible in 3.x, Fred?

Until this, can I set for example a pointer to the first element of an array and accessing its data inside a procedure. Has PureBasic an array-descriptor (espacially intersting for string arrays)? How are Arrays managed from PureBasic?

Thanks for any help and informations!

Markus Vedder-Kemnitzer

Markus Vedder-Kemnitzer, Germany
Registered PureBasic-User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Arrays as parameters for procedures

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by tinman.

Code: Select all

Structure wptr
  w.w[0]
EndStructure

If OpenConsole()
  Dim foo.w(5)
  *ptr.wptr = @foo(0)
  For i = 0 To 4
    foo(i) = i * 3
    PrintN(Str(*ptr\w[i]))
  Next
  Print("Press >RETURN< to end...")
  Input()
EndIf
Sorry Tinman, wrong Manipulation..

Edited by - fred on 02 May 2002 23:10:29
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by VeKem.

Hi tinman,

thanks for your tip!

...but your code ends in V3.0 with a windows GPF while accessing *ptr\w.
:-(

Markus Vedder-Kemnitzer, Germany
Registered PureBasic-User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Enable the debugger and you will see the error..

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Sorry Tinman, wrong Manipulation..
What does that mean? And why did you edit my message?

This works fine (I should not have been so lazy with the first example), and I use this trick in a lot of other places without any problems (it has been tested on Win95, Win98 and WinXP).

Code: Select all

Structure wptr
  w.w[0]
EndStructure

Dim foo.w(5)
*ptr.wptr = @foo(0)
If OpenConsole()
    For i=0 To 4
        foo(i)=i*3
        PrintN(Str(*ptr\w[i]))
    Next
    Input()
    CloseConsole()
EndIf
End


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by VeKem.

tinman,

>What does that mean? And why did you edit my message?

>Sorry Tinman, wrong Manipulation..
>Edited by - fred on 02 May 2002 23:10:29

Fred was here...

Fred,

thanks, sorry, until now I didn't use the console and looked not in the right way to the debugger window - oh, oh, programmers....

Thanks to both for your help!

Markus Vedder-Kemnitzer, Germany
Registered PureBasic-User
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
Sorry Tinman, wrong Manipulation..
What does that mean? And why did you edit my message?

Code: Select all


I've edited your message to copy/paste the code correctty and test it.. And I replied directly in your window by mistake. So I've overriden your text (and no way to go back).

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
I've edited your message to copy/paste the code correctty and test it.. And I replied directly in your window by mistake. So I've overriden your text (and no way to go back).
Ah, OK. No problem. I've posted a (hopefully) working version now anyway :wink:


--
It's not minimalist - I'm increasing efficiency by reducing input effort.
Post Reply