# PureBasic Forum

 It is currently Wed Apr 01, 2020 7:21 pm

 All times are UTC + 1 hour

 Page 1 of 1 [ 12 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Array parameter in proceduresPosted: Tue Mar 01, 2011 12:31 pm
 Enthusiast

Joined: Fri Jan 29, 2010 1:05 pm
Posts: 221
Location: Brazil
Hi!

I'm just new to Tailbite...
I'm trying to make an userlib from this procedure:

Code:
ProcedureDLL QuickSort(Array a(1), g.l, d.l)

If g < d
v = a(d)
i = g-1
j = d

Repeat
Repeat
i=i+1
Until a(i) >= v

ok = 0
Repeat
If j>0
j=j-1
Else
ok=1
EndIf

If a(j) <= v
ok=1
EndIf
Until ok<>0

tmp.l = a(i)
a(i) = a(j)
a(j) = tmp
Until j <= i

t = a(j)
a(j) = a(i)
a(i) = a(d)
a(d) = t

QuickSort(a(), g, i-1)
QuickSort(a(), i+1, d)
EndIf

EndProcedure

This procedure works fine.. but when I make a lib from it and run something like this:
Code:
Dim teste(50)

teste(0) = 5
teste(1) = 2
teste(2) = 4
teste(3) = 3
teste(4) = 1
teste(5) = 6

QuickSort(teste(), 0,5) ;IMA

For a=0 To 5
Debug teste(a)
Next

Then I get an invalid memory access error...

I'm also too tired, maybe I'm missing something obvious, sorry if thats the case

Top

 Post subject: Re: Array parameter in proceduresPosted: Wed Mar 02, 2011 10:33 pm

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1143
Location: Germany
i don´t know if this ever worked before, but the TailBiten code does not receive the adress to the array instead it points to the adress of the first element

Here is a workaround if you need one :

Code:
Dim teste(50)

teste(0) = 5
teste(1) = 2
teste(2) = 4
teste(3) = 3
teste(4) = 1
teste(5) = 6

temp=@teste()
QuickSort(@temp, 0,5) ;No IMA

For a=0 To 5
Debug teste(a)
Next

Top

 Post subject: Re: Array parameter in proceduresPosted: Wed Mar 02, 2011 11:44 pm
 Enthusiast

Joined: Fri Jan 29, 2010 1:05 pm
Posts: 221
Location: Brazil
Yes. I've just read that DLL's procedures also couldn't have an Array as parameter if it would be changed by the procedure... didn't know about that :/

But that's the kind of workaround I was looking for!
Thank you!

Top

 Post subject: Re: Array parameter in proceduresPosted: Thu Mar 03, 2011 5:04 am

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
@ABB: does the TB code even have checks for Array or List, etc in it?
I'm not sure that it does... Which would mean the Desc doesnt have the Array, etc keyword for the parameter, but the datatype of the array...

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!

Top

 Post subject: Re: Array parameter in proceduresPosted: Thu Mar 03, 2011 10:41 am

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1143
Location: Germany
@lexvictory your are right, the desc file is missing the array keyword.

If renamed to array does not work also !

@Fred / Freak could you investigate if this is a problem of the LibraryMaker.exe / PBCompiler.exe please ?

Code:
ASM
;
1
KERNEL32
;
LIB
;
0
;
Quicksort_Test.chm
;
Quicksort, Long, Long, Long (Array a(1), g.l, d.l) ; <- TB generated : first paramter is wrong
;Quicksort, Array, Long, Long (Array a(1), g.l, d.l) ; <- Renamed : first paramter is Array !
None | StdCall | UNICODE | THREAD
;
Quicksort_Test_Init
InitFunction | StdCall | UNICODE | THREAD
;

Top

 Post subject: Re: Array parameter in proceduresPosted: Thu Mar 03, 2011 2:00 pm

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
The difference appears to be how PB calls the procedure, which was my first thought...

No TB:
Code:
PUSH   dword a_teste

With TB:
Code:
PUSH   dword [a_teste]

So it would appear we need to do something to it when we detect an array is used (and probably for lists and maps! )

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!

Top

 Post subject: Re: Array parameter in proceduresPosted: Thu Mar 03, 2011 3:06 pm

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1143
Location: Germany
lexvictory wrote:
So it would appear we need to do something to it when we detect an array is used

you can´t do anything with PUSH dword [a_teste], because its the content of the first element and in this example is a value of '5' / [05 00 00 00].
lexvictory wrote:
and probably for lists and maps!

Lists are working fine, only maps need to be renamed in the desc to work properly.

Top

 Post subject: Re: Array parameter in proceduresPosted: Fri Mar 04, 2011 11:33 am

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
ah of course...
Perhaps it is a PB problem, unless i made and error when testing...

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!

Top

 Post subject: Re: Array parameter in proceduresPosted: Fri Mar 04, 2011 7:45 pm

Joined: Sat Apr 10, 2004 1:20 pm
Posts: 1143
Location: Germany
ah i was only halfway right, the square-brackets means indirect adressing.

So the TailBiten procedure receives the adress to the first array-element which is normal for externalisation like in a dll.

But we need the pointer to the PB-Object we don´t have, and i guess fred would say this is no bug.

Its more or less a feature request

Top

 Post subject: Re: Array parameter in proceduresPosted: Sat Mar 05, 2011 1:21 pm

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
I thought a PB array was the same as a C array, just the initialisation numbering was different?
They certainly work the same with Vlc anyway...

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!

Top

 Post subject: Re: Array parameter in proceduresPosted: Thu Jul 14, 2011 8:16 am
 Enthusiast

Joined: Tue Jun 21, 2011 10:39 am
Posts: 326
PureLeo wrote:
This procedure works fine.. but when I make a lib from it and run something like this:
Code:
Dim teste(50)
...
QuickSort(teste(), 0,5)
Then I get an invalid memory access error...

Hi guys! Sorry to bump this topic up, but I've just stumbled into this same problem. ABBKlaus has a workaround which passes the address of the address of the array to the procedure in the library:
Code:
...
temp=@teste()
QuickSort(@temp, 0,5)
This works, but I was wondering if there was any other solution to this issue. It's a little inept to expect the user to pass the address of the address of the array, rather than the array itself, to be filled.

Any ideas?

Top

 Post subject: Re: Array parameter in proceduresPosted: Sun Jul 17, 2011 10:14 am

Joined: Sun May 15, 2005 5:15 am
Posts: 1027
Location: Australia
if you can find an ASM solution we can put it in TB, otherwise it's doubtful..

_________________
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 12 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: Taz and 0 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite