Sujet : Re: do { quit; } else { }
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 10. Apr 2025, 23:23:38
Autres entêtes
Organisation : None to speak of
Message-ID : <87semf4pw5.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
bart <
bc@freeuk.com> writes:
On 10/04/2025 12:28, Keith Thompson wrote:
bart <bc@freeuk.com> writes:
[...]
Someone, not anyone but the all-knowing Tim, said: "and those types
are not compatible, because the two struct tags are different."
>
Do you agree with that? Or is there something more to making two types
be incompatible?
I don't recall the exact discussion
>
It stems from this, a reply from DB dated: "Tue, 8 Apr 2025 16:50:56
+0200". (About half way down there is some quoted code of mine.)
>
It concerned two struct types in different translations units, which
needed to be compatible for the test program to work corectly.
>
I said they were compatible enough. David said they were entirely
compatible. Tim said "No they are not". Three different opinions.
Either David or Tim was right; I don't much care which. You were
wrong. There is no such thing as "compatible enough"; two types
either are compatible or are not compatible. I won't speculate on what
you might have meant by "compatible enough".
The most reliable way to determine whether two types are compatible
is to read the standard see whether they satisfy the requirements.
If you have not done so, nothing you say about C type compatibility
is of any interest.
A good way to determine whether a compiler treats two types as
compatible is to define pointers to both of them and try assigning
them, then compiling the code in conforming mode. For example :
type1 *ptr1 = NULL;
type2 *ptr2;
ptr2 = type1;
If type1 and type2 are compatible, then type1* and type2* are
compatible, and there should be no diagnostic for the assignment.
If they're not compatible, then type1* and type2* are not compatible
*and* there is no implicit conversion betwen them, and a conforming
compiler must give a diagnostic. Don't forget to run the compiler
in conforming mode.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */