Sujet : Re: do { quit; } else { }
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.cDate : 11. Apr 2025, 15:11:32
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vtb7ul$1plb2$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 11/04/2025 13:26, Michael S wrote:
On Thu, 10 Apr 2025 17:59:15 -0700
Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>
An understanding of what "compatible types" means.
Bart didn't say that types are compatible or non-compatible.
He said that they are 'compatible enough'. That is not terminology of C
Standard, but terminology of his own. And he seems to understand it.
In my own translation, 'compatible enough' means that when these structs
are accessed then any sane or even semi-sane compiler will generate code
that will have the same effect as in case of access through structures
with literally identical declarations.
With that kind of thing, you always have to consider future-proofing for more advanced compilers.
With separately compile units that are then linked with a traditional linker, the compiler has no information about the details of struct definitions in different units. Thus you can be sure that it everything will work even if the two different structs are defined with different tags and field names - indeed, as long as you stick to a common prefix with fields with the same representation and alignments, I have great difficulty imagining how it might possible fail to work just as if the struct types had actually been compatible.
However, compilers don't have to work that way. Once you introduce link-time optimisation or other whole-program analysis, or compile the two units in one compile command, or allow more advanced object file formats that pass type details on to the linker, such assumptions don't hold. A compiler with LTO can quite reasonably optimise code on the assumption that a pointer to one type could not alias a pointer to an incompatible type, even if those types were otherwise extremely similar.