www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/31/12:27:31

From: "Mike Collins" <Mike AT NO_SPAM DOT e-col DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A bug in DJGPP? (length of bit fields)
Date: Fri, 31 Dec 1999 16:25:44 -0000
Organization: Customer of Planet Online
Lines: 54
Message-ID: <84il97$7ir$1@news6.svr.pol.co.uk>
References: <84fmpj$ptf$1 AT newsg3 DOT svr DOT pol DOT co DOT uk> <84gdqg$29fi$1 AT news DOT gate DOT net>
NNTP-Posting-Host: modem-33.name45.dialup.pol.co.uk
X-Trace: news6.svr.pol.co.uk 946657383 7771 62.136.182.33 (31 Dec 1999 16:23:03 GMT)
NNTP-Posting-Date: 31 Dec 1999 16:23:03 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

SCOTT19U.ZIP_GUY <dscott AT networkusa DOT net> wrote in message
news:84gdqg$29fi$1 AT news DOT gate DOT net...
> In article <84fmpj$ptf$1 AT newsg3 DOT svr DOT pol DOT co DOT uk>, "Mike Collins"
<Mike AT NO_SPAM DOT e-col DOT freeserve DOT co DOT uk> wrote:
> >Good folks of the DJGPP community,
> >
> >Firstly, I have read the FAQ, and I do not believe the answer to this
> >question to be there.
> >
> >I am aware that part-words in structures tend to get padded out to word
> >boundaries, so, for example, a short int may get padded out to 4 bytes,
even
> >though only two bytes are used for its quantity. I have come across a
case,
> >however, where bit-field variables seem to be being rounded DOWN.
> >
> >Please look at the short program below, and read the comments on the
> >structures.
> >I declared six structures, and wrote a comment line against each of them,
> >showing what I expected the length of the structure to be.
> >Then, I compiled and executed the program, and used the results to write
a
> >further comment on each structure to show its actual size as measured by
> >'sizeof'.
> >Note that TEST2, TEST3 and TEST6 have actual sizes that are smaller than
> >expected, and seem to have been rounded DOWN. TEST6 clearly shows two
> >unsigned integers being put into 4 bytes.
> >
> >Is this not a bug?
>     I would not call it a bug. Why does it have to fit in what you want.
The
> C standard is pretty flexable so that various code can ran fast on
different
> machines. There are lots of way to force it to do something different. If
> you are doing something that actaully depends on the hardware locations
> you should always write test code to see how it lays it out. And yes
> new versions of the compiler may do it differently as do the different
> manufactures of compilers for the same machine.
>    I would call it a bug if you can't read or write to the fields. How it
> packs it is something one must play with. To see a program with
> lots of fields look at scott19u.zip I use fileds all over the place.

Yes, I know that a bit field can be defined as short, in which case, it
would occupy a short int, equal to 2 bytes, but in my structure, I defined
the bit fields inside an unsigned int. Shouldn't that force the length of
the bit fields to be 4, and any other stuff in the structure should be added
to that?

> >
> >Mike Collins.



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019