Article View: fr.comp.lang.c
Article #15002Re: Struct/Union avec les memes champs
From: Marc Boyer
Date: Wed, 19 Oct 2005 11:56
Date: Wed, 19 Oct 2005 11:56
51 lines
2984 bytes
2984 bytes
Jean-Marc Bourguet <jm@bourguet.org> a �crit�:
> Jean-Marc Bourguet <jm@bourguet.org> writes:
>
>> Marc Boyer <Marc.Boyer@enseeiht.yahoo.fr.invalid> writes:
>>
>> > Bonjour,
>> >
>> > deux questions distinctes mais assez proches sur les structs/union
>> > ayant les m�mes champs. Bien sur, ces codes compilent et fonctionnent
>> > que ma machine. Mais est-ce l�gal ?
>> >
>> > A) Struct qui commencent pareil
>> > Soient
>> > typedef struct { int i; } Si;
>> > typedef struct { int i; char c;} Sic;
>> > int main(){
>> > Sic sic;
>> > Si* psi= (Si*) &sic;
>> > psi->i= 1; // Est-ce l�gal ? Si oui, un ref ?
>> > }
>>
>> J'ai le souvenir qu'il y a une regle pour que ce soit conforme dans le
>> cas ou les deux structs sont dans une union (en faisant une recherche
>> avec X11 hack tu devrais pouvoir arriver a la retrouver).
>
> 6.5.2.3/5
>
> One special guarantee is made in order to simplify the use of unions:
> if a union contains several structures that share a common initial
> sequence (see below), and if the union object currently contains one
> of these structures, it is permitted to inspect the common initial
> part of any of them anywhere that a declaration of the completed type
> of the union is visible. Tw o structures share a common initial
> sequence if corresponding members have compatible types (and, for
> bit-fields, the same widths) for a sequence of one or more initial
> members.
Ce qui est bizarre, c'est que la r�gle existe pour les structures,
mais pas pour les built-in types...
>> Je ne sais pas si c'est redige de telle maniere que ce le soit dans
>> le cas que tu donnes.
>
> Apparemment, non. Sauf si une autre regle intervient.
Les recherches continuent...
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:
<slrndlcd7g.a9d.Marc.Boyer@localhost.localdomain>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!fr.ip.ndsoftware.net!ciril.fr!univ-lille1.fr!news.cict.fr!not-for-mailReferences:
<slrndlbo6u.9sr.Marc.Boyer@localhost.localdomain> <pxbveztddnr.fsf@news.bourguet.org> <pxbmzl5dc60.fsf@news.bourguet.org>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!news4.google.com!news.glorb.com!fr.ip.ndsoftware.net!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 11:56:07 +0000 (UTC) Organization: CICT Lines: 51 Message-ID: <slrndlcd7g.a9d.Marc.Boyer@localhost.localdomain> References: <slrndlbo6u.9sr.Marc.Boyer@localhost.localdomain> <pxbveztddnr.fsf@news.bourguet.org> <pxbmzl5dc60.fsf@news.bourguet.org> 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 1129722967 16282 147.127.19.155 (19 Oct 2005 11:56:07 GMT) X-Complaints-To: usenet@news.cict.fr NNTP-Posting-Date: Wed, 19 Oct 2005 11:56:07 +0000 (UTC) User-Agent: slrn/0.9.8.1 (Debian)