Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: do { quit; } else { } Date: Fri, 11 Apr 2025 14:10:35 -0700 Organization: None to speak of Lines: 33 Message-ID: <87o6x2qu9g.fsf@nosuchdomain.example.com> References: <868qoaeezc.fsf@linuxsc.com> <86mscqcpy1.fsf@linuxsc.com> <86iknecjz8.fsf@linuxsc.com> <86o6x5at05.fsf@linuxsc.com> <20250409170901.947@kylheku.com> <87wmbs45oa.fsf@nosuchdomain.example.com> <87semf4pw5.fsf@nosuchdomain.example.com> <87zfgn344c.fsf@nosuchdomain.example.com> <20250411142636.00006c00@yahoo.com> <20250411102119.431@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Fri, 11 Apr 2025 23:10:39 +0200 (CEST) Injection-Info: dont-email.me; posting-host="c7132c9dc01e9da84b004e8ef39b7407"; logging-data="2761812"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ds8axgc84hbqRxvUWTrUi" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:J6pGB/XQL5OIncQanVA3wZ1hMYE= sha1:sAhqbrKhBepJcvrNcJAjxIe268Y= Bytes: 3073 bart 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.com void Void(void) { Void(); } /* The recursive call of the void */