5. Is there a way to compare structures automatically?
Ans:
No. There is no single, good way for a compiler to implement implicit structure comparison (i.e. to support the == operator for structures) which is consistent with C's low-level flavor.
A simple byte-by-byte comparison could founder on random bits present in unused "holes" in the structure (such padding is used to keep the alignment of later fields correct; A field-by-field comparison might require unacceptable amounts of repetitive code for large structures.
If you need to compare two structures, you'll have to write your own function to do so, field by field.
|