{{fbdoc item="title" value="OFFSETOF"}}----
Returns the offset of a field within a type.

{{fbdoc item="syntax"}}##
	[[KeyPgPpdefine #define]] **Offsetof**(//typename//, //fieldname//) [[KeyPgCint cint]]( @[[KeyPgCast cast]]( //typename// [[KeyPgPtr ptr]], 0 )->//fieldname// )	
##
{{fbdoc item="usage"}}##
	//result// = **Offsetof**( //typename//, //fieldname// )
##
{{fbdoc item="param"}}
	##//typename//##
		Name of the type as defined using the ##[[KeyPgType Type...End Type]]## statements.
	##//fieldname//##
		Name of the field as defined within the type (or within the base types for a derived type).

{{fbdoc item="desc"}}
	For a non-derived type, ##**Offsetof**## 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.

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/misc/offsetof.bas"}}%%(freebasic)
Type MyType
  x As Single
  y As Single
  Union
	b As Byte
	i As Integer
  End Union
End Type

Print "OffsetOf x = "; OffsetOf(MyType, x)
Print "OffsetOf y = "; OffsetOf(MyType, y)
Print "OffsetOf b = "; OffsetOf(MyType, b)
Print "OffsetOf i = "; OffsetOf(MyType, i)
%%

**Output**
%%OffsetOf x =  0
OffsetOf y =  4
OffsetOf b =  8
OffsetOf i =  8
%%


{{fbdoc item="lang"}}
	- Not available in the //[[CompilerOptlang -lang qb]]// dialect unless referenced with the alias ##**""__Offsetof""**##.

{{fbdoc item="diff"}}
	- New to ""FreeBASIC""

{{fbdoc item="see"}}
	- ##[[KeyPgType Type...End Type]]##
	- ##[[KeyPgSizeof Sizeof]]##

{{fbdoc item="back" value="CatPgMisc|Miscellaneous"}}