Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #128736

Re: lvalue types

From Tim Rentsch <txr@alumni.caltech.edu>
Newsgroups comp.lang.c
Subject Re: lvalue types
Date 2018-04-04 16:38 -0700
Organization A noiseless patient Spider
Message-ID <kfnbmeyilum.fsf@x-alumni2.alumni.caltech.edu> (permalink)
References (7 earlier) <lnin9rrj8u.fsf@kst-u.example.com> <kfno9jam2zw.fsf@x-alumni2.alumni.caltech.edu> <ln370lwl52.fsf@kst-u.example.com> <kfnd0zllgtf.fsf@x-alumni2.alumni.caltech.edu> <lnmuypttsx.fsf@kst-u.example.com>

Show all headers | View raw


Keith Thompson <kst-u@mib.org> writes:

> Tim Rentsch <txr@alumni.caltech.edu> writes:
>
>> [... lots ...]

I'm trying a different mode of responding in hopes that it
may help the conversation.

> Let me ask two direct yes/no questions.  I think I know what your
> answers will be, but I'd like to get your answers explicitly.
>
> Given this program:
>
> #include <stdio.h>
> int main(void) {
>     struct s { int m; };
>     struct s obj = { 0 };
>     obj.m = 42;
>     printf("%d\n", obj.m);
> }
>
> Does the assignment `obj.m = 42;` modify the value of the object `obj.m`?

Yes.

> Does the assignment `obj.m = 42;` modify the value of the object `obj`?
> (The phrase "modify the value of [the] object" is from the standard's
> definition of "access".)

No, not in the sense that the phrase is used in the definition of
access, in particular in the way "access" is used in 6.5 p{6,7}.

> If your answers are "yes" and "no", respectively, then that's the
> clearest statement I can think of that your worldview is one that
> I do not understand.
>
> If you think you can explain what the word "modify" means, preferably
> in a manner that would clarify your answers to these two questions,
> feel free to do so.

I think the key point is that the definition of access is not
bi-directional.  If something is accessed then it is read or
modified;  but if a memory location is inspected ("read") or
stored into ("modified"), that does not necessarily mean an
object that overlaps that memory location has been accessed.

> Again, obj has a value before the assignment, it has a different
> value after the assignment, and you say the assignment did not
> modify obj.

Your focus seems to be on "modify".  Mine is on "access".  What
is being modified is not the object 'obj' but some bytes of
memory that happen to be part of the object 'obj'.  I guess you
don't distinguish between those two.  I do.

If you don't mind I would like to ask some questions.  Given the
following program, and assuming 'unsigned' has the same size as
'float', with no padding bits (disclaimer: not compiled, just
typed in):

    #include <stdio.h>

    int main(void) {
        union u { unsigned u; float f; };
        union u obj = { 0 };
        obj.f = 42;
        printf( "%u\n", obj.u );
        return  0;
    }

Does the program have any undefined behavior?

Does the assignment to obj.f access the object obj.u?

If the assignment to obj.f does access the object obj.u, is
that a violation of effective type rules?

My answers are no, no, and not applicable.  I welcome any
comments or comparisons that you think would be helpful.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: lvalue types Tim Rentsch <txr@alumni.caltech.edu> - 2018-03-26 23:44 -0700
  Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-03-27 09:14 -0700
    Re: lvalue types supercat@casperkitty.com - 2018-03-27 12:21 -0700
      Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-28 17:01 -0700
      Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-29 01:54 -0700
    Re: lvalue types Tim Rentsch <txr@alumni.caltech.edu> - 2018-03-30 08:32 -0700
      Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-03-30 09:25 -0700
        Re: lvalue types jameskuyper@verizon.net - 2018-03-30 10:58 -0700
        Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-31 00:52 -0700
        Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-04-02 15:19 -0700
          Re: lvalue types supercat@casperkitty.com - 2018-04-03 10:06 -0700
            Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-04-03 11:33 -0700
              Re: lvalue types supercat@casperkitty.com - 2018-04-03 12:19 -0700
                Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-04-03 12:48 -0700
              Re: lvalue types supercat@casperkitty.com - 2018-04-05 10:17 -0700
                Re: lvalue types Keith Thompson <kst-u@mib.org> - 2018-04-05 10:52 -0700
                Re: lvalue types supercat@casperkitty.com - 2018-04-05 12:39 -0700
                Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-04-06 06:13 -0700
        Re: lvalue types Tim Rentsch <txr@alumni.caltech.edu> - 2018-04-04 16:38 -0700
  Re: lvalue types supercat@casperkitty.com - 2018-03-27 12:09 -0700
    Re: lvalue types Steven Petruzzellis <frelwizzen@gmail.com> - 2018-03-28 10:48 -0700

csiph-web