Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 03 Apr 1998 18:02:34 -0800
From:      Xiaomin Ye <xiaominy@tuns.ca>
To:        freebsd-questions@FreeBSD.ORG, ifair@newton.ccs.tuns.ca, Larry.Hughes@StMarys.ca
Subject:   bit and byte alignment on FreeBSD?
Message-ID:  <352594BA.2E58B3B8@tuns.ca>

next in thread | raw e-mail | index | archive | help
Dear Sir/Madam,
We encountered a strange problem while using FreeBSD.
The following structure can be compacted to be 8 bytes by means of cc
compiler on Open-VMS platform. But on FreeBSD, 12 bytes will be formed.

#pragma nomember_alignment

struct example_structure
{
unsigned type : 3;
unsigned c : 1;
signed mem1 : 12;
signed mem2 : 24;
signed mem2 : 24;
};

It seems that on FreeBSD  the compiler can only provide one, two or
four  bytes alignment,
"type" occupies 1 byte, "c" occupies 1, "mem1" 2 , "mem2" 4 bytes and
"mem3" 4 bytes, because is no bit alignment and 3-byte alignment.
However, on Open-VMS the compiler can provide the bit alignment,
"type", "c" and "mem1" take 2 byte space, and "mem2", "mem3" will occupy
3 bytes respectively. The total space will be only 8 bytes.
Is there any solution to this problem? Your kind will be very much
appreciated.

Regards,
Xiaomin



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?352594BA.2E58B3B8>