Two struct objects hold identical member values but were filled separately. Why can memcmp on them be unreliable?
Correct answer
B. Padding bytes may hold indeterminate values, so a byte comparison can report differences
13 views
B. Padding bytes may hold indeterminate values, so a byte comparison can report differences
13 views
Structure padding is not part of any member's value, and the standard leaves those bytes unspecified after assignment, so two objects with equal members may differ bytewise. Comparing structs with memcmp is safe only after zeroing them or when the type has no padding. Comparing member by member also avoids the trap of -0.0 differing from 0.0 for floating members.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is B? Ask here and get an explanation.