PDA

View Full Version : union-extends-bug?



ReneMiner
04-10-2014, 14:02
What's going on here?

This is a small testscript. As far as i know it should print out 4 times 8...



Uses "console"

Alias Quad As t_DataHandle

Type t_DecodeDataHandle
pData As DWord
pType As DWord
End Type

Union u_DataHandle
hndl As t_DataHandle
my As t_DecodeDataHandle
End Union


Type any_Data Extends u_DataHandle
Be As Function
Is As Function
End Type
Function any_Data.Be(ByVal s As String)
If HEAP_Size(Me.my.pData) Then HEAP_Free(Me.my.pData)
Me.my.pData = HEAP_AllocByStr(s)
End Function
Function any_Data.Is() As String
Function = HEAP_Get(Me.my.pData)
End Function


PrintL "quad: " & SizeOf(Quad)
PrintL "t_DecodeDataHandle " & SizeOf(t_DecodeDataHandle)
PrintL "u_DataHandle " & SizeOf(u_DataHandle)
PrintL "any_Data " & SizeOf(any_Data)

'PrintL
'Dim foo As any_Data
'foo.Be("some data")
'PrintL foo.is

PrintL " -- key to end --"
WaitKey

now what surprise... the extended type is double the size but has no additional subelements...

but now becomes weird:
goto line 12 that says:


my As t_DecodeDataHandle


and remove "my As" so it just says:


t_DecodeDataHandle


now the union becomes larger but the extended type equals the unions size... strange...