Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: lvalue types Date: Wed, 18 Apr 2018 11:01:57 -0700 Organization: None to speak of Lines: 45 Message-ID: References: <2b687d74-f559-43a9-9aec-8a1067467ce2@googlegroups.com> <83589df8-fa61-4ffb-8fef-09ab50c8fcf4@googlegroups.com> <646ca446-53a3-4006-a476-6f52caacd8c9@googlegroups.com> <108b8472-481e-43b4-9988-2c7e4648449d@googlegroups.com> <2bf95ece-0d26-49aa-8629-87d9c47ef2ad@googlegroups.com> <97b9de3e-f3f8-45c1-8850-a29ca57069d5@googlegroups.com> <0411fdf5-9ca7-48b2-b7d8-23dd874e95d9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="b3081569afdc5f121008704081152326"; logging-data="14773"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KhB2BcfYJvIhGbmW6MdZX" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:tnP0vIrC8xmN0QiuBv9h7+0fZ+w= sha1:jd2u1/MBZyGgQAZ3qGLLY72ENSY= Xref: csiph.com comp.lang.c:129420 supercat@casperkitty.com writes: > On Wednesday, April 18, 2018 at 11:12:49 AM UTC-5, Keith Thompson wrote: >> supercat@casperkitty.com writes: >> [...] >> > The ability to pass the address of an object to functions that can use >> > the object, at least until the next time the object is addressed via other >> > means, is no less fundamental than the ability to use the structure >> > directly. Both clang and gcc, however, *invent* a distinction between >> > direct and indirect use of objects. >> >> I'm probably going to regret asking this, but can you support the >> claim in your last sentence? (I request that you do so without >> asking rhetorical questions.) > > I've posted code many times where both gcc and clang create such a > distinction. > > struct s1 { int x; }; > struct s2 { int x; }; > union u { struct s1 v1; struct s2 v2; } uarr[10]; > > int readS1x(struct s1 *p) { return p->x; } > void writeS2x(struct s2 *p) { p->x = 5; } > > int test(union u *uarr2, int i, int j) > { > if (readS1x(&uarr[i].v1)) > writeS2x(&uarr[j].v2); > return readS1x(&uarr[i].v1); > } > > Both gcc and clang will assume that there's no way an operation on a struct > s2 can affect a struct s1, even if all operations on the storage using > different types are separated by actions which derive pointers of those > types from the same lvalue "uarr". Can you substantiate your claim about what assumptions gcc and clang make, by showing us a self-contained program whose output clearly demonstrates those assumptions? -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"