Article View: comp.std.c
Article #4167Re: Union access
From: Christopher R. Volpe
Date: Tue, 03 Oct 1995 21:06
Date: Tue, 03 Oct 1995 21:06
35 lines
1722 bytes
1722 bytes
In article <812736828snz@soliton.demon.co.uk>, Ian Cargill <ian@soliton.demon.co.uk> writes:
>It has been asserted elsewhere by someone that:
>
>> "The only guarantee that C gives is that the following data
>> structure can be written one way and read another."
>>
>> union {
>> unsigned char a[4];
>> int b;
>> }
>
>I replied with my opinion that this is actually implementation defined
>behavior, and that the only guarantee the standard gives is regarding
>access to common initial sequences of structs in a union.
>
>Since there is still some dispute, I would welcome comment from the
>assembled multitude, particularly those who know what they are talking
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>about. A majority verdict will do. :-)
^^^^^
Well, that never stopped me before, so here goes:
I don't think the person who said that was talking specifically about
properties of unions, but rather about the general rule that you can access
the storage of any object (e.g. "int b;") using an lvalue of type unsigned
char.
--
Chris Volpe Phone: (518) 387-7766 (Dial Comm 8*833
GE Corporate R&D Fax: (518) 387-6560
PO Box 8, Schenectady, NY 12301 Email: volpecr@crd.ge.com
Technical Details
Message-ID:
<44s8l7$ma7@rdsunx.crd.ge.com>Path:
arc1-ca.pugleaf.net!bart.crd.ge.com!volpeReferences:
<812736828snz@soliton.demon.co.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!bart.crd.ge.com!volpe From: volpe@bart.crd.ge.com (Christopher R. Volpe) Newsgroups: comp.std.c Subject: Re: Union access Date: 3 Oct 1995 21:06:47 GMT Organization: GE Corporate Research & Development Sender: volpe@bart (Christopher R. Volpe) Distribution: world Message-ID: <44s8l7$ma7@rdsunx.crd.ge.com> References: <812736828snz@soliton.demon.co.uk> Reply-To: volpe@ausable.crd.ge.com NNTP-Posting-Host: bart.crd.ge.com