Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news.misty.com!news.iecc.com!.POSTED.gal.iecc.com!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: lvalue types Date: Sun, 04 Mar 2018 13:03:54 -0800 Organization: None to speak of Lines: 98 Message-ID: References: <2b687d74-f559-43a9-9aec-8a1067467ce2@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: gal.iecc.com; posting-host="gal.iecc.com:64.57.183.53"; logging-data="31528"; mail-complaints-to="abuse@iecc.com" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Funky-Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail Funky-Injection-Info: reader02.eternal-september.org; posting-host="a7a5048c88f1a4443b71761f2662b22e"; logging-data="20649"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181v99UKsFmXGLAVD2/txlW" Cancel-Lock: sha1:CBLg99xelBT/WAsFs9CV2WPCKs0= sha1:UeKV8BdOFBIB8ZWFeEkF0DNQoYw= Funky-Xref: reader02.eternal-september.org comp.lang.c:206300 Xref: csiph.com comp.lang.c:127353 Tim Rentsch writes: > Keith Thompson writes: >> 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? > > I would say no. It does change some, or in this particular case > maybe all, of the bytes that hold the object representation of > obj, but that's not the same thing. I truly do not understand what you're saying here. Consider this program: #include int main(void) { struct s { int m; }; struct s obj = { 0 }; printf("obj.m = %d\n", obj.m); obj.m = 42; printf("obj.m = %d\n", obj.m); } The output is: obj.m = 0 obj.m = 42 Assume, for simplicity, that struct s has no padding bytes (sizeof (struct s) == sizeof (int)) and int has no padding bits (the latter probably doesn't matter). Before the assignment, obj has one value. After the assignment, obj has a different value. The value changed because of the assignment. To "access" is, by definition, "to read or modify the value of an object". And you're saying that that assignment, which caused the value of obj to change, did not modify the value of obj? Are you using a different meaning than I am for some seemingly straighforward word? (value? object? modify?) > Instead of being used in an assignment, suppose we have obj.m being > used to get the value of member m. No, let's concentrate for now on the assignment. [...] >> 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? > > It isn't quite right to say the two assignments have equivalent > effect. The effects are allowed to be equivalent, but they are > not guaranteed to be equivalent. (In fact I believe there are > compilers for which the effects are different, and deliberately > so, if not for this exact case then for similar ones.) Can you provide a concrete example? If you're talking about padding bytes, then sure, there can be a difference. Does your statement apply only when there are padding bytes? (I note that the particular struct type I used in the example is very unlikely to have padding bytes.) [...] -- 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"