Why can the offsetof macro not be applied to a bit-field member of a structure?
Correct answer
C. Bit-fields need not start on a byte boundary, so no byte offset exists
16 views
C. Bit-fields need not start on a byte boundary, so no byte offset exists
16 views
offsetof yields a size_t byte offset, but a bit-field may begin at any bit position and has no address, so it cannot satisfy the macro's requirement that the member be addressable. Applying offsetof to a bit-field is a constraint violation, not merely an unspecified result. The same lack of an address is why &s.flag is illegal for a bit-field, while &s.whole is perfectly valid.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.