In a C library header I have a struct defined like this:
typedef struct
{
int bar;
} foo;
I would like to change the definition so that the struct is tagged, like this:
typedef struct foo
{
int bar;
} foo;
Does this change the ABI for C user of the library? Or even worse, break old sources in some way?
Related question: Unnamed struct ABI (C library, C++ users)
Does this change the ABI for C user of the library?
ABI is not addressed by the C language. It is an implementation detail.
With that said, I am not aware of an ABI that takes struct tags into account in any way. On the other hand, if your headers are ever consumed by C++ compilers then it is conceivable that the difference would affect C++ name mangling. That's not an ABI issue per se, but it's in the same ballpark. If this is a consideration for you then perhaps you could test with the C++ compilers that matter to you.
Or even worse, break old sources in some way?
This is more of a risk, though probably not a major one. A struct type with a tag is not compatible with any tagless struct type, in C's sense of "compatible". If your sources all include the header in question and use only its declaration of the struct in conjunction with accessing external objects and functions, then the change you propose should not break them. However, it is conceivable that some of them provide and use their own local definitions of compatible structure types, and the types defined by any such local definitions would not be compatible with struct foo
. In such a case, a C compiler might well reject the affected sources.
Note that this means that although no ABI I know does take struct tags into account, it would not be inconsistent with C if one did.