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: References: 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 In article , Shao Miller 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 > >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 #include 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 #include 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.