Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: Tim Bartley <bartley@ozy.dec.com>
Subject: Re: Funny alignment with structures ?
Date: 7 Dec 1994 06:56:33 GMT	[thread overview]
Message-ID: <3c3mb1$e64@nntpd.lkg.dec.com> (raw)
In-Reply-To: 3c2dij$268@nntpd2.cxo.dec.com

alan@nabeth.cxo.dec.com writes
> You may be able to override some of the realignment enforced by
> the compiler, using compiler options (-Zp looks likely for the
> OSF C compiler).  But the hardware still won't like it and you're
> likely to get unaligned access trap messages.  You can fix this
> by realigning the data by hand if stuck with that particular data
> format, but it will use some program time to do it.
> 
> I use something like the following:
> 
> convert(char *bytes)
> {
> 	union {
> 		char	bytes[4] ;
> 		int	word ;
> 	} tmp ;
> 
> 	tmp.bytes[0] = bytes[0] ;
> 	tmp.bytes[1] = bytes[1] ;
> 	tmp.bytes[2] = bytes[2] ;
> 	tmp.bytes[3] = bytes[3] ;
> 
> 	return tmp.word ;
> }
> 

You can also use the following construct:

#pragma member_alignment save
#pragma nomember_alignment
struct {
   [definitions for struct you want no padding for]
};
#pragma member_alignment restore

if you use the -migrate option on the C compiler. This gives you
access to the DEC C compiler (you may need to have the
CMPDEVENH200 subset installed). Check out the cc(1) man page for
more information on the -migrate switch.

The compiler will then generate the appropriate instruction sequences
so that unaligned accessed do not occur. The advantage of this
approach is that you can control the padding on a structure by
structure basis.

Hope this helps,

Tim.



  reply	other threads:[~1994-12-07  6:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-12-06  5:28 Funny alignment with structures ? Anthony
1994-12-06 14:32 ` Steve Thompson
1994-12-06 19:20   ` Alan Rollow - Dr. File System's Home for Wayward Inodes.
1994-12-07  6:56     ` Tim Bartley [this message]
1994-12-07 23:58     ` Anthony
1994-12-08  1:31       ` Anthony
1994-12-07 14:50 ` Stefan Monnier
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox