🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9318

structure alignment question

#9318
From: notes
Date: Sat, 13 Sep 1986 21:15
31 lines
1516 bytes
Background:  Our architecture has the following data types and sizes:

               byte   -- 1 byte
	       short  -- 2 bytes
	       int    -- 4 bytes
	       long   -- 4 bytes
	       *ptr   -- 4 bytes

Question:  Should structures and unions always be aligned to 4-byte
           boundaries?

Consider:   Our portable C compiler aligns this structure as follows:

     struct a
     {
        char b ;        ->  byte 0
        union aa
        {
           short bb;    ->  byte 4
           char cc;
        } dd ;
        char c;         ->  byte 8
     } d;

I've been told that on a VAX, however, 'bb' is placed on byte 2 and
'c' is placed on byte 4.  Is this true?  How do other compilers handle
this case?  Which way is "correct"?  If there is sufficient interest,
I will post a summary of responses.

Dave Ray  --  uucp:  {ucf-cs|allegra}!novavax!hrshcx!hcx1!daver
Technical Details
Message-ID: <101@hcx1.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!qantel!hplabs!oblio!nsc!csi!epimass!ucat!pesnta!peora!ucf-cs!novavax!hrshcx!hcx1!notes

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!lll-crg!lll-lcc!qantel!hplabs!oblio!nsc!csi!epimass!ucat!pesnta!peora!ucf-cs!novavax!hrshcx!hcx1!notes
From: notes@hcx1.UUCP
Newsgroups: net.lang.c
Subject: structure alignment question
Message-ID: <101@hcx1.UUCP>
Date: Sat, 13-Sep-86 17:15:33 EDT
Article-I.D.: hcx1.101
Posted: Sat Sep 13 17:15:33 1986
Date-Received: Wed, 17-Sep-86 01:57:06 EDT
Sender: notes@hcx1.UUCP
Organization: Harris CSD, Fort Lauderdale, Florida
Lines: 33
Nf-ID: #N:hcx1:5500003:000:881
Nf-From: hcx1!daver    Sep 12 06:51:00 1986