Sujet : Re: do { quit; } else { }
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.cDate : 10. Apr 2025, 19:36:21
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vt9334$3hhr8$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 24 25
User-Agent : Mozilla Thunderbird
On 10/04/2025 17:51, Kaz Kylheku wrote:
On 2025-04-10, bart <bc@freeuk.com> wrote:
Do you agree with that? Or is there something more to making two types
be incompatible?
Tim: two fingerprints from the left hand index finger are from different
humans if they are different.
You: do you agree with this, or is there more that can make
two humans different?
Struct compatibility is determined by tag and content.
This is more nuanced. There is two structs being the same type or not, which a compiler can determine if they are in the same translation unit; no need to analyse tags or anything to figure that out, it's either the exact same type or not.
And there is two structs in two translation units which have separate definitions, which the compiler cannot compare, and which have to be compatible for the program to be valid. But the compiler cannot check that.
The example was like this:
module A: typedef struct point {float a; float b;} Point;
module B: typedef float length;
typedef struct _tag {length x, y;} vector;
David Brown said: "The two types are entirely compatible."
I said: "Are they?"
Tim Rentsch said: "No, they are not."
So DB and TR are disagreeing, but everyone is ignoring the fact that one of them is likely wrong, and sending /me/ off to read the standard!
TR went on to say: "The type names 'Point' and 'vector' name two
distinct types, and those types are not compatible, because
the two struct tags are different."
That does rather sound like it is the tags that are the sole deciding factor, which is when I started doing experiments.
ATEOTD, to share such a type across two or more translation units, means each one seeing its own definition of it. Nothing stops you having somewhat different versions of it, as I had above, so this part has to be taken on trust. This was part of my broader point that sharing non-linkage named entities across modules in C was ad hoc.