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


Groups > comp.std.c > #1862

Re: Description of "." operator

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.std.c
Subject Re: Description of "." operator
Date 2013-01-18 20:14 -0800
Organization None to speak of
Message-ID <lnwqv995c4.fsf@nuthaus.mib.org> (permalink)
References (2 earlier) <lnmwwm4umo.fsf@nuthaus.mib.org> <kcch03$i71$1@dont-email.me> <ln4nitttce.fsf@nuthaus.mib.org> <kdaih9$lui$1@dont-email.me> <kdcu00$cu3$1@dont-email.me>

Show all headers | View raw


Shao Miller <sha0.miller@gmail.com> writes:
[...]
> Speaking of "temporary lifetime," I noticed that the following program 
> yielded the same pointer value, but I would've expected them to be 
> different:
>
> #include <stdio.h>
>
> int main(void) {
>      struct { char ca[6]; } foo;
>
>      printf("%p, ", (void *) foo.ca);
>      printf("%p\n", (void *) (foo = foo).ca);
>      return 0;
>    }

That's interesting.  For some reason, it hadn't occur to me that an
assignment, not just a function return, could create an object with
temporary lifetime.

> It seems to me that the array member of the rvalue should be different 
> than the array member of 'foo', since they're different objects; one is 
> 'foo' and one is an object with temporary lifetime.  Am I missing something?

I think you're right.

> gcc version 4.7.2 20120921 (Red Hat 4.7.2-2):
>
>    gcc -std=c11 -pedantic -Wall -Wextra -Werror -o rvalobj rvalobj.c
>
> clang seems to give the expected results.
>
> clang version 3.0 (tags/RELEASE_30/final):
>
>    clang -std=c1x -pedantic -Wall -Wextra -Werror -Wno-self-assign -o 
> rvalobj rvalobj.c
>
> Maybe it's just a GCC bug, but I'm wondering if another interpretation 
> is possible.

Plenty of other interpretations are possible, but I agree with yours.

Another data point: gcc does the same thing with "-std=c99"; C99 didn't
have temporary lifetime.  I'd argue that the program's behavior is
undefined by omission in C99, so "gcc -std=c99" can do anything it
likes.  It looks like they didn't change it for "-std=c11".

-- 
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.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Description of "." operator Keith Thompson <kst-u@mib.org> - 2012-12-07 18:34 -0800
  Re: Description of "." operator Keith Thompson <kst-u@mib.org> - 2012-12-08 10:43 -0800
    Re: Description of "." operator Jens Gustedt <jens.gustedt@loria.fr> - 2012-12-10 00:35 +0100
      Re: Description of "." operator Keith Thompson <kst-u@mib.org> - 2012-12-09 20:02 -0800
  Re: Description of "." operator jgk@panix.com (Joe keane) - 2012-12-09 23:34 +0000
    Re: Description of "." operator Keith Thompson <kst-u@mib.org> - 2012-12-09 20:00 -0800
  Re: Description of "." operator Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-20 23:32 -0800
    Re: Description of "." operator Keith Thompson <kst-u@mib.org> - 2012-12-21 02:08 -0800
      Re: Description of "." operator Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-12-21 09:18 -0500
        Re: Description of "." operator Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-21 08:45 -0800
      Re: Description of "." operator Tim Rentsch <txr@alumni.caltech.edu> - 2012-12-21 08:37 -0800
  Re: Description of "." operator Shao Miller <sha0.miller@gmail.com> - 2013-01-06 01:23 -0500
    Re: Description of "." operator Keith Thompson <kst-u@mib.org> - 2013-01-05 23:51 -0800
      Re: Description of "." operator Shao Miller <sha0.miller@gmail.com> - 2013-01-06 13:49 -0500
        Re: Description of "." operator Keith Thompson <kst-u@mib.org> - 2013-01-06 22:12 -0800
          Re: Description of "." operator Shao Miller <sha0.miller@gmail.com> - 2013-01-17 23:19 -0500
            Re: Description of "." operator Shao Miller <sha0.miller@gmail.com> - 2013-01-18 20:47 -0500
              Re: Description of "." operator Keith Thompson <kst-u@mib.org> - 2013-01-18 20:14 -0800
              Re: Description of "." operator jgk@panix.com (Joe keane) - 2013-01-20 20:07 +0000
                Re: Description of "." operator Shao Miller <sha0.miller@gmail.com> - 2013-01-20 15:36 -0500

csiph-web