Sujet : Re: do { quit; } else { }
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 11. Apr 2025, 22:10:35
Autres entêtes
Organisation : None to speak of
Message-ID : <87o6x2qu9g.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:
[...]
What about struct {long x;} and struct {int64_t x;}?
>
Whether they are compatible seems to be depend on platform.
>
Or rather, whether or not int64_t happens to defined on top of 'long'
or 'long long'.
Correct. If long is 32 bits, they're not compatible. If long
is 64 bits and int64_t is a typedef for long, they're compatible.
If long is 64 bits and int64_t is a typedef for long long (or for
a 64-bit extended integer type) they're not compatible.
Again, type compatibility isn't just about representation.
And again, I am describing how C is defined, not advocating or
defending it.
If you're working with code where the compatibility of those two
types matters, it's probably best to modify the code to use a
single type, defined in a shared header if it's used in more than
one translation unit. If that's not practical and you're sure the
types have the same representation, you can probably work around it
with some kind of type-punning (pointer casts, unions, memcpy()),
though some such workarounds might involve undefined behavior.
Or you can just copy the x member from an object of one type to an
object of the other type (there's an implicit conversion between
long and int64_t whether they're compatible or not).
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */