Path: csiph.com!news.swapon.de!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: Sat, 03 Mar 2018 13:01:07 -0800 Organization: None to speak of Lines: 68 Message-ID: References: <2b687d74-f559-43a9-9aec-8a1067467ce2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="bc1147ccc842b73bdba534adacdee29b"; logging-data="25565"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/VBhy3TlkaWIepjliPbBlV" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:XHTswTZuyONfniiYsP4fq5PXxeo= sha1:HqN/+Bo4JSsyOEJHytYJ2gid8D0= Xref: csiph.com comp.lang.c:127337 Tim Rentsch writes: > Keith Thompson writes: > >> [When using . or ->, what is "accessed"?] >> >> Let me make the point more succinctly. >> >> struct s { int m; }; >> struct s obj; >> obj.m = 42; >> >> obj.m is an lvalue of type int. The assignment accesses (specifically >> modifies) the object obj.m, which is of type int; that's perfectly fine >> under 6.5p7. It also accesses (i.e., modifies) the object obj, which >> is of type struct s. > > I don't subscribe to this view, more specifically the last > sentence. Consider a union rather than a struct: [snip] Let's consider the original struct. N1570 3.1 defines "access" as to read or modify the value of an object Wouldn't you agree that `obj.m = 42;` modifies the value of obj? Doesn't it therefore access obj? Are you saying that obj.m = 42; only modifies obj.m, but obj = (struct s){.obj = 42}; (which has an equivalent effect) modifies both obj and obj.m? [...] >> N1570 6.5p7 says that: >> >> An object shall have its stored value accessed only by an lvalue >> expression that has one of the following types: >> >> followed by 6 bullet points, none of which allow an object of type >> struct s to be accessed by an lvalue of type int. >> >> It's obvious that the assignment is meant to be well defined. I'd say >> this is a simple oversight in the wording of the standard (unless >> someone can come up with another interpretation). > > It's highly unlikely it's just an oversight. Among other things, > this clause > > an aggregate or union type that includes one of the > aforementioned types among its members (including, > recursively, a member of a subaggregate or contained union) > > has been present in the Standard since at least 1989. Yes, which means that modifying a struct object modifies its members. I don't understand why the reverse would not also be true. [...] -- 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"