Article View: fr.comp.lang.c
Article #15000Re: Struct/Union avec les memes champs
From: Jean-Marc Bourguet
Date: Wed, 19 Oct 2005 10:38
Date: Wed, 19 Oct 2005 10:38
47 lines
2524 bytes
2524 bytes
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.
> 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.
A+
--
Jean-Marc
FAQ de fclc: http://www.isty-info.uvsq.fr/~rumeau/fclc
Site de usenet-fr: http://www.usenet-fr.news.eu.org
Technical Details
Message-ID:
<pxbmzl5dc60.fsf@news.bourguet.org>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!infeed-2.proxad.net!news6-e.free.fr!not-for-mailReferences:
<slrndlbo6u.9sr.Marc.Boyer@localhost.localdomain> <pxbveztddnr.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!news2.google.com!proxad.net!infeed-2.proxad.net!news6-e.free.fr!not-for-mail Newsgroups: fr.comp.lang.c Subject: Re: Struct/Union avec les memes champs References: <slrndlbo6u.9sr.Marc.Boyer@localhost.localdomain> <pxbveztddnr.fsf@news.bourguet.org> From: Jean-Marc Bourguet <jm@bourguet.org> Message-ID: <pxbmzl5dc60.fsf@news.bourguet.org> Date: 19 Oct 2005 12:38:31 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Lines: 47 Organization: Guest of ProXad - France NNTP-Posting-Date: 19 Oct 2005 12:38:31 MEST NNTP-Posting-Host: 213.131.238.28 X-Trace: 1129718311 news6-e.free.fr 12283 213.131.238.28:59438 X-Complaints-To: abuse@proxad.net