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


Groups > comp.std.c > #1868

Re: Description of "." operator

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-xxxfer.readnews.com!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail
From jgk@panix.com (Joe keane)
Newsgroups comp.std.c
Subject Re: Description of "." operator
Date Sun, 20 Jan 2013 20:07:08 +0000 (UTC)
Organization Public Access Networks Corp.
Lines 81
Message-ID <kdhipc$2ep$1@reader1.panix.com> (permalink)
References <lntxrxnufa.fsf@nuthaus.mib.org> <ln4nitttce.fsf@nuthaus.mib.org> <kdaih9$lui$1@dont-email.me> <kdcu00$cu3$1@dont-email.me>
NNTP-Posting-Host panix3.panix.com
X-Trace reader1.panix.com 1358712428 2521 166.84.1.3 (20 Jan 2013 20:07:08 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Sun, 20 Jan 2013 20:07:08 +0000 (UTC)
X-Newsreader trn 4.0-test76 (Apr 2, 2001)
Xref csiph.com comp.std.c:1868

Show key headers only | View raw


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?

% 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.

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