The Get Link Object Macro
Open Transport defines a macro (OTGetLinkObject) that you can use to easily cast back to the original object from a pointer to either a LIFO or a FIFO linked list structure.
DataType* OTGetLinkObject(OTLink* linkPtr,
DataType structName,
NameOfLinkPtrField fieldName)
#define OTGetLinkObject(link, struc, field)
- \
((struc*)((char*)(link) - offsetof(struc, field)))
PARAMETERS
linkPtr
- A pointer to the
OTLink structure from which you wish to cast back.
structName
- The name of the structure containing the
OTLink structure.
fieldName
- The
OTLink field in the above structure.
- function result
- The macro results in a pointer to the appropriate data type by offsetting the
linkPtr appropriately and casting the result.