🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

alignements struct/tableaux

#15616
From: Pierre Habouzit
Date: Sat, 17 Sep 2005 17:31
42 lines
2244 bytes
soit le bout de code suivant :

------------------------------------------------------------------------

typedef struct foo foo;

struct my_union {
    union {
        foo *array[2];
        struct {
            foo *first;
            foo *second;
        }
    }
} my_union;

------------------------------------------------------------------------

soit 'bar' du type my_union, en supposant que tous les membres sont allou�s.

est ce que je suis toujours sur que :

  &bar->array[0] == &bar->first
  &bar->array[1] == &bar->second

autrement dit, si j'ai un tableau de N pointeurs, et une structure avec N
membres du m�me type, je suis toujours assur� que les alignements sont les
m�mes, et que je peux du coup utiliser ind�pendemment l'une ou l'autre des
�critures ?


PS: je me doute que je peux faire un #define MY_UNION_FIRST 0 et
    #define MY_UNION_SECOND 1 et utiliser des

        bar->array[MY_UNION_FIRST/SECOND]

    mais la concision d'une telle �criture laisse fortement � d�sirer, et
    j'ai besoin d'acc�der � mes pointeurs via des offsets.
-- 
�O�  Pierre Habouzit
��O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Technical Details
Message-ID: <432c52d5$0$9425$626a14ce@news.free.fr>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-2.proxad.net!news12-e.free.fr!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f9822,2ab126dba8e5e645,start
X-Google-Attributes: gidf9822,public
X-Google-Language: FRENCH,ASCII
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!infeed-2.proxad.net!news12-e.free.fr!not-for-mail
Message-ID: <432c52d5$0$9425$626a14ce@news.free.fr>
From: Pierre Habouzit <madcoder@debian.org>
Subject: alignements struct/tableaux
Newsgroups: fr.comp.lang.c
Date: Sat, 17 Sep 2005 19:31:51 +0200
User-Agent: KNode/0.9.2
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-15
Content-Transfer-Encoding: 8Bit
X-Face: $(^e[V4D-[`f2EmMGz@fgWK!e.B~2g.{08lKPU(nc1J~z\4B>*JEVq:E]7G-\6$Ycr4<;Z!|VY6Grt]+RsS$IMV)f>2)M="tY:ZPcU;&%it2D81X^kNya0=L]"vZmLP+UmKhgq+u*\.dJ8G!N&=EvlD
Lines: 42
Organization: Guest of ProXad - France
NNTP-Posting-Date: 17 Sep 2005 19:31:02 MEST
NNTP-Posting-Host: 82.225.205.10
X-Trace: 1126978262 news12-e.free.fr 9425 82.225.205.10:55710
X-Complaints-To: abuse@proxad.net