Problem with VarPtr not working

Started by imaginaryhuman, April 04, 2019, 22:51:44

Previous topic - Next topic

imaginaryhuman

I'm struggling to get 'compress' to work (from zlib).

I am doing: compress2 BankBuf(b),r,Varptr(code[0]),codeoff,9

The variables are set up right. Everything is normal except the VarPtr seems not to be working. Blitz reports that there is no overload for having a variable of the type inside the bracket of VarPtr... e.g. if I put code[0] in there, it says there's no overload with a byte in that position (its a byte array). If I put "code" ie the array itself it says there's no overload with a byte array in that position. It's almost like it isn't actually returning a byteptr at all, it's just returning the contents of the brackets.

I know the syntax is right cus I've been using this for years on the old blitzmax (pre NG). It does the same when I try with lzmacompress2 (imported)... same syntax, same parameters... the varptr isn't returning a byte pointer.

Also it seems BytePtr and IntPtr don't register as valid commands any more, are they not part of NG? Was pointer support removed entirely? I tried also a bankbuf(bank)[0] but it says you can't get an array of bankbufs, rather than using it as a byte pointer. How am I supposed to pass a pointer to the compress function if there are no pointers?

TomToad

Arrays are already pointers.  Instead of passing VarPtr(code[0]), just pass code.
Code (blitzmax) Select
SuperStrict
Local n:UInt = 100
Local r:UInt = 100
Local a:Byte[n]
Local s:String = ""
'fill a with numbers 1 through 9
For Local i:Int = 0 Until n
a[i] = i/10
s :+ a[i] + " "
Next

'create a bank and compres the data to it
Local bank:TBank = CreateBank(n)
compress2(BankBuf(bank),r,a,n,9)

'print the contents of the buffer
s :+ "~n~n"
For Local i:Int = 0 Until r
s :+ PeekByte(bank,i) + " "
Next

'clear the contents of the array
For Local i:Int = 0 Until n
a[i] = 0
Next

'uncompress the buffer to the array
uncompress(a,n,BankBuf(bank),r)
s :+ "~n~n"
For Local i:Int = 0 Until n
s :+ a[i] + " "
Next
Print s

------------------------------------------------
8 rabbits equals 1 rabbyte.

markcwm

BytePtr and IntPtr have always been separated by a space, Bye Ptr and Int Ptr.

I believe BRL Blitzmax code should run in 32-bit NG without modification.

imaginaryhuman

#3
@TomToad ... but VarPtr(code[0]) has always worked in pre-NG versions. Thanks for example though.

@markcwm .... will try that, thanks.

Derron

If nothing speaks "against" it maybe VarPtr should return the pointer itself if you pass it a pointer.


bye
Ron

imaginaryhuman

Managed to get it working with

Local r:ULong=codeoff*4
compress2 BankBuf(b),r,VarPtr(code[0]),ULong(codeoff),9

the lengths had to be ULong types, whereas in the past they used to be Int. And using Byte Ptr(code) is the only way I could work with the array. Strangely once this was changed to ULong, the VarPtr started working.

imaginaryhuman

Good to know pointers are still in (phew) .... I use them often. Thanks guys.