Pointer/Structur Casting

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
crackhead
User
User
Posts: 12
Joined: Tue Apr 06, 2010 9:26 pm

Pointer/Structur Casting

Post by crackhead »

Hi, would it be possible to easily implement the following?:

Code: Select all

var.l = $5566
*heh.Long = @var

Structure struc1
	var1.l
EndStructure

Structure struc2
	var2.b
EndStructure

varstruct.struc1\var1 = $6655

;for more comfort when messing with bytes
;Debug *heh.Byte\b    ;shows $55
;Debug varstruct.struc2\var2    ;shows $66
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Re: Pointer/Structur Casting

Post by Rescator »

I'm not entirely sure what you want here but...
I've done a lot of similar things using structureunions which is a brilliant time saver.

Code: Select all

Define var.l
var = $5566

Structure struc1
	StructureUnion
		value.l
		valuebytes.b[4]
	EndStructureUnion
EndStructure

Define *heh.struc1
*heh=@var

Debug Hex(*heh\value)
Debug Hex(*heh\valuebytes[0])
Debug Hex(*heh\valuebytes[1])
Debug Hex(*heh\valuebytes[2])
Debug Hex(*heh\valuebytes[3])
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Pointer/Structur Casting

Post by srod »

Could use something like the following :

Code: Select all

Structure cast
  StructureUnion
    b.b
    w.w
    l.l
    i.i
    q.q
  EndStructureUnion
EndStructure

var.l = $55667788
*heh.cast = @var

Debug Hex(*heh\b, #PB_Byte)
Debug Hex(*heh\w, #PB_Word)
Debug Hex(*heh\l, #pb_long)

I may look like a mule, but I'm not a complete ass.
crackhead
User
User
Posts: 12
Joined: Tue Apr 06, 2010 9:26 pm

Re: Pointer/Structur Casting

Post by crackhead »

yeah, something like this, but couldn't such a temorary cast like '*var.Integer : *var.Byte\b' be native?
Post Reply