Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #127353
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: lvalue types |
| Date | 2018-03-04 13:03 -0800 |
| Organization | None to speak of |
| Message-ID | <lna7vnft8l.fsf@kst-u.example.com> (permalink) |
| References | <2b687d74-f559-43a9-9aec-8a1067467ce2@googlegroups.com> <ln4llzgsus.fsf@kst-u.example.com> <kfn7eqtsfgk.fsf@x-alumni2.alumni.caltech.edu> <lnefl0g9gs.fsf@kst-u.example.com> <kfnh8pwqgwn.fsf@x-alumni2.alumni.caltech.edu> |
Tim Rentsch <txr@alumni.caltech.edu> writes:
> Keith Thompson <kst-u@mib.org> writes:
>> Tim Rentsch <txr@alumni.caltech.edu> writes:
>>> Keith Thompson <kst-u@mib.org> 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
>>
>> <execution-time action> 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 <stdio.h>
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 <http://www.ghoti.net/~kst>
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"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
lvalue types supercat@casperkitty.com - 2018-03-01 16:38 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-01 17:17 -0800
Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-03-01 17:37 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-01 22:00 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-01 23:49 -0800
Re: lvalue types asetofsymbols@gmail.com - 2018-03-05 06:56 -0800
Re: lvalue types supercat@casperkitty.com - 2018-03-02 00:22 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-02 01:23 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-02 05:04 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-02 06:06 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-02 08:12 -0800
Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-03-02 09:50 -0800
Re: lvalue types supercat@casperkitty.com - 2018-03-02 11:33 -0800
Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-03-02 11:45 -0800
Re: lvalue types supercat@casperkitty.com - 2018-03-02 16:28 -0800
Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-03-02 16:54 -0800
Re: lvalue types supercat@casperkitty.com - 2018-03-02 17:50 -0800
Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-03-02 19:43 -0800
Re: lvalue types Tim Rentsch <txr@alumni.caltech.edu> - 2018-03-02 22:51 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-02 23:07 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-03 01:44 -0800
Re: lvalue types supercat@casperkitty.com - 2018-03-03 13:01 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-02 22:21 -0800
Re: lvalue types supercat@casperkitty.com - 2018-03-02 09:24 -0800
Re: lvalue types Tim Rentsch <txr@alumni.caltech.edu> - 2018-03-03 00:58 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-03 01:13 -0800
Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-03-03 13:01 -0800
Re: lvalue types supercat <flatfinger@casperkitty.com> - 2018-03-03 17:43 -0800
Re: lvalue types Tim Rentsch <txr@alumni.caltech.edu> - 2018-03-04 02:22 -0800
Re: lvalue types supercat@casperkitty.com - 2018-03-04 13:03 -0800
Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-03-04 13:03 -0800
Re: lvalue types bartc <bc@freeuk.com> - 2018-03-04 22:32 +0000
Re: lvalue types supercat@casperkitty.com - 2018-03-05 09:45 -0800
Re: lvalue types supercat@casperkitty.com - 2018-03-03 14:19 -0800
Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-01 18:03 -0800
csiph-web