This is an interview question. I have no idea how to solve it.
could anybody help me:?
Given a pointer to member a within a
structure, write a routine that
returns a pointer to the structure.
Thank you!
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.
Firstly, in order to pull that off you need to know the type of the enclosing struct
StructTypeand the name of the membermember. That must be a given. Without it, the problem has no solution.Secondly, I don’t know why other answers insist on reinventing the wheel (and engage into undefined and non-portable hacks on top of that) instead of using the standard
offsetofmacro. Withoffsetofthe answer is