🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fr.comp.lang.c
Article #14996

Struct/Union avec les memes champs

#14996
From: Marc Boyer
Date: Wed, 19 Oct 2005 05:57
37 lines
1953 bytes
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 ?
}

B) Union avec les m�me champs
#include <assert.h>
typedef struct  { 
  int i;  
  union {
    char j; 
    char  k;  
  };
} foo;
int main(){  
   foo f;  
   f.j= 'a';  
   assert( f.j == f.k); // Est-ce l�gal ? Si oui, ref ?
   return 0;
}

Merci d'avance,
  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: <slrndlbo6u.9sr.Marc.Boyer@localhost.localdomain>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!news-lond.gip.net!news-raspail.gip.net!news.gsl.net!gip.net!grolier!news.enst.fr!jussieu.fr!crihan.fr!univ-lille1.fr!news.cict.fr!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f9822,eb7f26af12505976,start
X-Google-Attributes: gidf9822,public
X-Google-Language: FRENCH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!news-lond.gip.net!news-raspail.gip.net!news.gsl.net!gip.net!grolier!news.enst.fr!jussieu.fr!crihan.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: Struct/Union avec les memes champs
Date: Wed, 19 Oct 2005 05:57:23 +0000 (UTC)
Organization: CICT
Lines: 37
Message-ID: <slrndlbo6u.9sr.Marc.Boyer@localhost.localdomain>
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 1129701443 8714 147.127.19.155 (19 Oct 2005 05:57:23 GMT)
X-Complaints-To: usenet@news.cict.fr
NNTP-Posting-Date: Wed, 19 Oct 2005 05:57:23 +0000 (UTC)
User-Agent: slrn/0.9.8.1 (Debian)