Article View: fr.comp.lang.c
Article #15007Re: Struct/Union avec les memes champs
From: Marc Boyer
Date: Wed, 19 Oct 2005 13:03
Date: Wed, 19 Oct 2005 13:03
42 lines
2400 bytes
2400 bytes
Pierre Habouzit <madcoder@debian.org> a �crit�:
> Marc Boyer wrote:
>> Le 19-10-2005, Pierre Habouzit <madcoder@debian.org> a �crit�:
>>>> typedef struct {
>>>> int i;
>>>> union {
>>>> char j;
>>>> char k;
>>>> };
>>>> } foo;
>>>
>>>> assert( f.j == f.k); // Est-ce l�gal ? Si oui, ref ?
>>> c'est l�gal, mais :
>>> * vu ton union toujours vrai
>>> * s�mantiquement faux.
>>
>> Non, je suis pas d'accord: soit c'est un UB (acc�s � f.k
>> non initialis�), soit c'est vrai.
>
> non, je maintiens, ca sera toujours vrai. en tout cas sur tout compilo qui
> ne vient pas de mars.
Ca, je l'imaginais bien.
> j et k "d�signent" le meme emplacement m�moire, et ont le meme type.
>
> donc pour toute instance I de ton type foo, I.j == I.k (et meme comme le
> disait je ne sais plus qui &I.j == &I.k, ce qui est l'hypoth�se que je
> prend dans ce post pour mes affirmations).
Si &I.j == &I.k, oui, il y a �galit�.
> initialis� ou non.
Ca, c'est une vieille m�fiance qui me vient de:
unsigned u;
assert( u >= 0 ); // UB
Marc Boyer
--
� v�lo, prendre une rue � contre-sens est moins dangeureux
que prendre un boulevard dans le sens l�gal. � qui la faute ?
Technical Details
Message-ID:
<slrndlch52.a9d.Marc.Boyer@localhost.localdomain>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nocworld.net!u-picardie.fr!news.completel.fr!ciril.fr!univ-lille1.fr!news.cict.fr!not-for-mailReferences:
<slrndlbo6u.9sr.Marc.Boyer@localhost.localdomain> <4355f8d5$0$623$626a14ce@news.free.fr> <slrndlcdoq.a9d.Marc.Boyer@localhost.localdomain> <435642fd$0$21309$626a54ce@news.free.fr>Show Full Headers
Complete Article Headers
X-Google-Thread: f9822,eb7f26af12505976 X-Google-Attributes: gidf9822,public X-Google-Language: FRENCH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!nocworld.net!u-picardie.fr!news.completel.fr!ciril.fr!univ-lille1.fr!news.cict.fr!not-for-mail From: Marc Boyer <Marc.Boyer@enseeiht.yahoo.fr.invalid> Newsgroups: fr.comp.lang.c Subject: Re: Struct/Union avec les memes champs Date: Wed, 19 Oct 2005 13:03:04 +0000 (UTC) Organization: CICT Lines: 42 Message-ID: <slrndlch52.a9d.Marc.Boyer@localhost.localdomain> References: <slrndlbo6u.9sr.Marc.Boyer@localhost.localdomain> <4355f8d5$0$623$626a14ce@news.free.fr> <slrndlcdoq.a9d.Marc.Boyer@localhost.localdomain> <435642fd$0$21309$626a54ce@news.free.fr> Reply-To: Marc.Boyer@enseeiht.yahoo.fr (del yahoo) NNTP-Posting-Host: ubu.enseeiht.fr Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.cict.fr 1129726984 16282 147.127.19.155 (19 Oct 2005 13:03:04 GMT) X-Complaints-To: usenet@news.cict.fr NNTP-Posting-Date: Wed, 19 Oct 2005 13:03:04 +0000 (UTC) User-Agent: slrn/0.9.8.1 (Debian)