What is the purpose of __builtin_offsetof operator (or _FOFF operator in Symbian) in C++?
In addition what does it return? Pointer? Number of bytes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a builtin provided by the GCC compiler to implement the
offsetofmacro that is specified by the C and C++ Standard:GCC – offsetof
It returns the offset in bytes that a member of a POD struct/union is at.
Sample:
@Jonathan provides a nice example of where you can use it. I remember having seen it used to implement intrusive lists (lists whose data items include next and prev pointers itself), but i can’t remember where it was helpful in implementing it, sadly.