Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Shao Miller <sha0.miller@gmail.com> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | Re: Description of "." operator |
| Date | 2013-01-18 20:47 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <kdcu00$cu3$1@dont-email.me> (permalink) |
| References | (1 earlier) <kcb58h$s8g$1@dont-email.me> <lnmwwm4umo.fsf@nuthaus.mib.org> <kcch03$i71$1@dont-email.me> <ln4nitttce.fsf@nuthaus.mib.org> <kdaih9$lui$1@dont-email.me> |
On 1/17/2013 23:19, Shao Miller wrote:
> On 1/7/2013 01:12, Keith Thompson wrote:
>> Shao Miller <sha0.miller@gmail.com> writes:
>>> On 1/6/2013 02:51, Keith Thompson wrote:
>> [...]
>>>> Shao Miller <sha0.miller@gmail.com> writes:
>>>>> On 12/7/2012 21:34, Keith Thompson wrote:
>> [...]
>>>>> 3.19:
>>>>>
>>>>> "1 value
>>>>> precise meaning of the contents of an object when
>>>>> interpreted as
>>>>> having a specific type"
>>>>
>>>> Like too many of the standard's "definitions", that's incomplete.
>>>> There
>>>> can be values that have nothing to do with the contents of an object.
>>>>
>>>
>>> Actually, I took it to have emphasis on "meaning." So I agree with you,
>>> values exist independently of objects.
>>
>> Right -- and that should apply to struct types as well as to scalar
>> types. At least, I can't think of any good reason why it shouldn't.
>>
>
> And unions too:
>
> #include <stddef.h>
> #include <stdio.h>
>
> struct A {
> int i;
> int j;
> };
>
> struct B {
> char ca[sizeof (int)];
Oops. I meant some scalar type with the same size as 'int', not an
array type. Oh well.
> int k;
> };
>
> union C {
> struct A a;
> struct B b;
> };
>
> int main(void) {
> union C c1, c2;
>
> if (offsetof(struct A, j) != offsetof(struct B, k))
> return 0;
>
> c1.a.j = 42;
>
> /*
> * Common initial sequence doesn't apply (no object)
> * Effective type doesn't apply (no object)
> * Type-punning applies
> */
> printf("%d\n", (c2 = c1).b.k);
>
> return 0;
> }
>
> Any problems, there?
>
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;
}
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?
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.
--
- 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 | Next in thread | Find similar | Unroll 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