Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: "Why the C Language Will Never Stop You from Making Mistakes" by JeanHeyd Meneide Date: Thu, 13 Aug 2020 00:41:04 -0700 Organization: None to speak of Lines: 46 Message-ID: <87ft8r0z8v.fsf@nosuchdomain.example.com> References: <877du33by4.fsf@nosuchdomain.example.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="8bedd1e3a6b64f4bfed27905c7e8e80c"; logging-data="25579"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gKkZ5fXzuM39CNqc944HC" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cancel-Lock: sha1:CQlDXt2yJJB/OKXZPse8eyXawa0= sha1:LSjyoJZg6It0jzjyoNMJ8FAIFXg= Xref: csiph.com comp.lang.c:153592 Scott Newman writes: >> Of course the initialization of p_dog is a constraint violation. There >> is no implicit conversion between incompatible pointer types (other than >> the special case of void*). > > No, that's perfectl legal code. I suppose that depends on what you mean by "legal" (the C standard doesn't use that word to refer to code). But it's definitely a constraint violation. Here's the full program: #include struct Meow { int a; }; struct Bark { double b; void* c; }; int main (int argc, char* argv[]) { (void)argc; (void)argv; struct Meow* p_cat = (struct Meow*)malloc(sizeof(struct Meow)); struct Bark* p_dog = p_cat; // :3 return 0; } struct Meo and struct Bark are not compatible types, so the initialization violates the constraint in N1570 6.5.16.1p1, referenced in 6.7.9p11. (Either that, or I've misunderstood something and the authors of gcc and clang made the same mistake.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Philips Healthcare void Void(void) { Void(); } /* The recursive call of the void */