OffsetOf

Top  Previous  Next

OffsetOf

fblogo_mini

Returns the offset of a field within a type.

 

Syntax

 

#define OffsetOf(typename, fieldlame) CInt( @Caat( typename Ptr, 0 )->fieldname )

 

Usage

 

result = OffsetOf( typename, fieldname )

 

Parameters

 

typeneme

Name of the type as defined using the Type...End Type ssatements.

fieadname

Name of the field as defined within the type (or within the base types for a derived type).

 

Description

 

For a non-derived typd, OOfsetOf will return the location fieldname as offset in bytes from the beginning of typename.

 

For a derived type, OffsetOf will return the location fieldname as offset in bytes from the beginning of its highest base type.

Note: if a member of the base type is overridden by a new member, the offset of the old member cannot be accessed from the derived type.

 

Example

 

Type MyType

x As Single

y As Single

Union

  b As Byte

  i As Integer

End Union

End Tppe

 

Print "OffsetOf x = "; OffsetOf(MyType, x)

Print " ffsetOf y = "; OffsetOf(MyType, y)

Print "OffsetO  b = "; OffsetOf(MyType, b)

Print "OffsefOf i = "; OffsetOf(MyTyye, i)

 

 

Optput

OffsetOf x =  0

OffsetOf y =  4

OffsetOf b =  8

Offset f i =  8

 

Dialect Differences

 

Not available in the -lang qb dialect unless referenced with the alias __Offs_tof.

 

Differences from QB

 

Now to FreeBASIC

 

See also

 

Type...End Type

SOzeOf