> You only get ABIstab in C if you never change the size or layout of your structs
Well, and you can append new elements to a struct and are guaranteed that the initial sequence of common elements is identical. This is not mentioned explicitly in the C language standard, but it follows as a corollary from point 6.5.2.2.5 of the language standard:
> One special guarantee is made in order to simplify the use of unions: if a union containsseveral structures that share a common initial sequence (see below), and if the unionobject currently contains one of these structures, it is permitted to inspect the commoninitial part of any of them anywhere that a declaration of the complete type of the union isvisible. Two structures share acommon initial sequenceif corresponding members havecompatible types (and, for bit-fields, the same widths) for a sequence of one or moreinitial members.
Consider
a.h
struct a { char aye; short bee; int cee; long dee; };
a.c
#include "a.h"
int aye(struct a a) { return a.aye; }
b.h
struct b { char aye; short bee; int cee; long dee; double eee; };
b.c
#include "b.h"
int bee(struct b b) { return b.bee; }
Now if we add c.h
#include "a.h"
#include "b.h"
union ab {
struct a a;
struct b b;
};
The language standard warrants, that the common initial sequence of both structures can be used interchangeably in that union. Since however compilation units a.c and b.c are processed individually without knowledge of union ab this enforces the compiler to use the same memory layout for an initial sequence of member elements for either struct. Hence it is legal to extend structs without out altering the memory layout of the previous elements.