Liste des Groupes | Revenir à cl c |
James Kuyper <jameskuyper@alumni.caltech.edu> writes:Yes, exactly. If the C standard did not use the word "compatible", then programmers might consider two types to be "compatible" for a whole range of situations. That could include "can be assigned to each other", "can be assigned, possibly with casts", "can be converted back and forth to get back the original value", "can be mixed with each other's pointer types", "can be used to access each other", "can be used in the same code", and no doubt many others.On 5/13/25 05:40, David Brown wrote:I suggest that the phrase "work together" is too vague. It'sOn 12/05/2025 22:25, Keith Thompson wrote:...>I think that a lot of C programmers misunderstand what "compatible>
types" means. Many seem to think that two types are compatible if
they have the same representation and can be assigned without a cast.
Yes. Basically, most C programmers are not particularly aware of the
technical definitions of some of the terms in C standards where they
differ from common usage. The word "compatible" in English means that
the things in question can work together or fit together.
That's pretty much what it means in C. Two C types are compatible in C
if the C standard *guarantees* that they can work together - that you
can use the types interchangeably. The tricky part is the definition of
which pairs of types the C standard makes those guarantees for.
The key point is that the undefined behavior of code which treats
incompatible types as if they were compatible could also be that they
work together, too, depending upon the implementation.
perfectly reasonable to say that two types that can be assigned to
each other without casts can "work together", and I might even call
them "compatible" if the standard didn't already define the term.
>
To a first approximation, two types are compatible if they're theI think the solution for this kind of thing would be hyphenated terms - "pointer-compatible", "assignment-compatible", and the like. That would, IMHO, make it a clearer and there would be no risk of mixup between normal English language usage and technical terms. (For some technical terms, made-up works like "lvalue" are appropriate, but not in this case I think.)
same type. The standard's section on compatible types points to
additional rules for some cases. IMHO the English word "compatible"
suggests a much looser relationship, but we're stuck with the
standard's terminology (and I'm not sure what would be better).
Les messages affichés proviennent d'usenet.