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


Groups > comp.std.c > #1869

Re: Description of "." operator

From Shao Miller <sha0.miller@gmail.com>
Newsgroups comp.std.c
Subject Re: Description of "." operator
Date 2013-01-20 15:36 -0500
Organization A noiseless patient Spider
Message-ID <kdhkg4$oa$1@dont-email.me> (permalink)
References <lntxrxnufa.fsf@nuthaus.mib.org> <ln4nitttce.fsf@nuthaus.mib.org> <kdaih9$lui$1@dont-email.me> <kdcu00$cu3$1@dont-email.me> <kdhipc$2ep$1@reader1.panix.com>

Show all headers | View raw


On 1/20/2013 15:07, Joe keane wrote:
> In article <kdcu00$cu3$1@dont-email.me>,
> Shao Miller  <sha0.miller@gmail.com> wrote:
>> 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;
>>    }
>
> I guess... the 'object' of the 'value' of an assignment expression is
> the left-hand side?
>

In which C?  I would've said the "object" was one with temporary 
lifetime, and is not the object designated by the LHS lvalue, in C11.

Of course, assignment and function calls aren't the only way to yield 
rvalues.  Another simple way is the comma operator.  '(0, foo).ca'. 
Conditional '?:' is another one.

> % cat bar.c
> #include <stdio.h>
> #include <string.h>
>
> struct bar
> {
>      char a[5];
> };
>
>
> int main(int argc, char **argv)
> {
>      struct bar x;
>      struct bar y;
>      struct bar *p;
>      int res;
>
>      memcpy((void *) &y, "FFFF", sizeof y);
>      p = &(x = y);
>      res = p == &x;
>      printf("%d\n", res);
>      return 0;
> }
> % diff bar.c bar2.cc
> % gcc -o bar bar.c
> bar.c: In function 'main':
> bar.c:18: error: invalid lvalue in unary '&'
> % g++ -o bar2 bar2.cc
> % ./bar2
> 1
> % cat barx.c
> #include <stdio.h>
> #include <string.h>
>
> struct bar
> {
>      char a[5];
> };
>
>
> int main(int argc, char **argv)
> {
>      struct bar x;
>      struct bar y;
>      char *p;
>      int res;
>
>      memcpy((void *) &y, "FFFF", sizeof y);
>      p = &(x = y).a[0];
>      res = p == &x.a[0];
>      printf("%d\n", res);
>      return 0;
> }
> % diff barx.c barx2.cc
> % gcc -o barx barx.c
> % ./barx
> 1
> % g++ -o barx2 barx2.cc
> % ./barx2
> 1
>
> This doesn't work with the function call example.
>

In C11?  This doesn't work in C11, either.  'p' becomes indeterminate at 
the semi-colon before the 'res' assignment, due to the temporary 
lifetime of the object it had been assigned to point into.

-- 
- Shao Miller
--
"Thank you for the kind words; those are the kind of words I like to hear.

Cheerily,"  -- Richard Harter

Back to comp.std.c | Previous | Next — Previous 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