On Thu, Mar 2, 2023 at 12:40 PM Tom Lane <t...@sss.pgh.pa.us> wrote: > > I wrote: > > Peter Smith <smithpb2...@gmail.com> writes: > >> On Thu, Mar 2, 2023 at 10:04 AM Tom Lane <t...@sss.pgh.pa.us> wrote: > >>> Sadly, this is almost certainly going to cause bitching on the part of > >>> some compilers, because depending on the order of header inclusions > >>> they are going to see multiple typedefs for the same name. > > >> So does your reply mean there is no way really to be sure if such > >> changes are OK or not, other than to push them and then revert them > >> if/when one of the BF animals complains? > > > We know which compilers don't like that, I believe, but you'd have > > to dig in the commit log or mail archives to find out. > > I looked into the C standard to see what I could find about this. > C99 specifically describes the use of "struct foo" to forward-declare > a struct type whose meaning will be provided later. It also says > > [#8] If a type specifier of the form > struct-or-union identifier > or > enum identifier > occurs other than as part of one of the above forms, and a > declaration of the identifier as a tag is visible, then it > specifies the same type as that other declaration, and does > not redeclare the tag. > > which appears to me to specifically authorize the appearance of > multiple forward declarations. On the other hand, no such wording > appears for typedefs; they're just plain identifiers with the same > scope rules as other identifiers. Maybe later versions of the C > spec clarify this, but I think duplicate typedefs are pretty > clearly not OK per C99. Perhaps with sufficiently tight warning > or language-version options, you could get modern gcc or clang to > complain about it.
I was reading this post [1], and more specifically, this specification note [2] which seems to explain things Apparently, not all C99 compilers can be assumed to work using the strict C99 rules. So I will abandon this idea. Thanks for your replies. ------ [1] https://stackoverflow.com/questions/26240370/why-are-typedef-identifiers-allowed-to-be-declared-multiple-times/26240595#26240595 [2] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1360.htm Kind Regards, Peter Smith. Fujitsu Australia