Retrieves the offset of a member from the beginning of its parent structure.
% = BitOffsetOf(Type.Member)
% = OffsetOf(Type.Member)
BitOffsetOf and OffsetOf return the start position of an element of a Type by using its name in bits and bytes respectively.
OpenW # 1, 10, 10, 300, 450, $030
// $030 => Window with caption & close box
TitleW # 1, "Demo BitOffsetOf()"
Type atest
- Byte a
- Int b
- Double c
- Byte d
EndType
Dim a As atest
a.a = 1 : a.b = 2
a.c = 3 : a.d = 4
Print " Which element's are used?"
Print "element a = Byte : ", a.a
Print "element b = Int : ", a.b
Print "element c = Double: ", a.c
Print "element d = Byte : ", a.d
Print " start address of an element"
Print "start address ->Type: ", V:a
Print "start address a: ", V:a.a
Print "start address b: ", V:a.b
Print "start address c: ", V:a.c
Print "start address d: ", V:a.d
Print " Where begins an element in" " the Type in byte?"
Print "OffSetOf of a: ", Space$(20), OffsetOf(a.a)
Print "OffSetOf of b: ", Space$(20), OffsetOf(a.b)
Print "OffSetOf of c: ", Space$(20), OffsetOf(a.c)
Print "OffSetOf of d: ", Space$(20), OffsetOf(a.d)
Print " Start of type elements in bit:"
Print "BitOffsetOf of a: ", BitOffsetOf(a.a)
Print "BitOffsetOf of b: ", BitOffsetOf(a.b)
Print "BitOffsetOf of c: ", BitOffsetOf(a.c)
Print "BitOffsetOf of d: ", BitOffsetOf(a.d)
Print " Size of the element's in byte"
Print "SizeOf of a: ", Space$(20), SizeOf(a.a)
Print "SizeOf of b: ", Space$(20), SizeOf(a.b)
Print "SizeOf of c: ", Space$(20), SizeOf(a.c)
Print "SizeOf of d: ", Space$(20), SizeOf(a.d)
Print " Size of the element's in bit"
Print "BitSizeOf of a: ", BitSizeOf(a.a)
Print "BitSizeOf of b: ", BitSizeOf(a.b)
Print "BitSizeOf of c: ", BitSizeOf(a.c)
Print "BitSizeOf of d: ", BitSizeOf(a.d)
Do
Sleep
Until Me Is Nothing
CloseW 1
Also it’s possible to determine the BitOffsetOf an element of an array, or of an array in a Type or of a Type in Type and also of a Type in an array.
{Created by Sjouke Hamstra; Last updated: 24/09/2014 by James Gaite}