Deutsch English Français Italiano |
<vtbffi$1tc7n$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: do { quit; } else { } Date: Fri, 11 Apr 2025 12:20:00 -0400 Organization: A noiseless patient Spider Lines: 47 Message-ID: <vtbffi$1tc7n$1@dont-email.me> References: <vspbjh$8dvd$1@dont-email.me> <8634enhcui.fsf@linuxsc.com> <vsph6b$ce6m$5@dont-email.me> <86ldsdfocs.fsf@linuxsc.com> <20250406161323.00005809@yahoo.com> <86ecy5fjin.fsf@linuxsc.com> <20250406190321.000001dc@yahoo.com> <86plhodtsw.fsf@linuxsc.com> <20250407210248.00006457@yahoo.com> <vt15lq$bjs0$3@dont-email.me> <vt2lp6$1qtjd$1@dont-email.me> <vt31m5$2513i$1@dont-email.me> <vt3d4g$2djqe$1@dont-email.me> <vt3iqh$2ka99$1@dont-email.me> <vt5fed$ccri$1@dont-email.me> <vt5jfo$e5qu$4@dont-email.me> <vt5pjv$inuo$5@dont-email.me> <vt5rot$lgvv$1@dont-email.me> <vt9od9$2m6n$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 11 Apr 2025 18:20:03 +0200 (CEST) Injection-Info: dont-email.me; posting-host="1101d58e927cb82f23597a7452dea8af"; logging-data="2011383"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bqEVO5S+q9e+uVQ8049xiNn0inInYJHY=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:/mjtlCjiR5eGB+n5yC2HT2m3wys= In-Reply-To: <vt9od9$2m6n$1@dont-email.me> Content-Language: en-US Bytes: 4154 On 4/10/25 20:40, James Kuyper wrote: .... > "Two declarations of structure, union, or enumerated types which ... use > different tags declare distinct types. Each declaration of a structure, > union, or enumerated type which does not include a tag declares a > distinct type." (6.7.2.3p9). .... I get the impression that the reason why the rules for compatible struct, union, and enumerated types were defined the way they are might not be obvious. In C, within a single translation unit, there are three ways to define a struct, union, or enumeration exactly once, and then use that type in multiple locations: 1. Define the type with a tag, and then use that tag anywhere within its scope to refer to the definition. 2. Define the type with a typedef, and then use that typedef anywhere withing it's scope to refer to the definition. 3. Define the type in the "type-specifier" of a declaration with multiple declarators. All of the declarators will share the definition of that type. Because these methods for sharing a type definition exist, the type compatibility rules were designed on the assumption that anybody who defines two distinct types must have intended them to be distinct, even if the definitions of those types are identical. It would therefore be a logical error to use one of those types in a context where the other was intended. even though the machine code to read and write those types would be identical. That's the reason such types are not considered compatible. However, none of those techniques would be sufficient to allow use of such a type to communicate between different translation units. Types defined in two different translation units are necessarily distinct types, even if defined identically. That's why there's a special rule that allows distinct types in different translation units to be compatible with each other, but only if their definitions meet certain requirements. They must be essentially identical, except that member types are allowed to be compatible, rather than exactly the same - which is necessary because, for user-defined types, they can't be the same in different translation units. The most significant difference allowed by this rule is that in one definition, a member's type can be an enumerated type, while in the other definition, the same name identifies member with the underlying type of that enumerated type. I don't think that was a desired consequence, just a side-effect of the way the rule had to be worded.