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

From: dscott AT networkusa DOT net (SCOTT19U.ZIP_GUY)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: A bug in DJGPP? (length of bit fields)
Date: Fri, 31 Dec 1999 20:55:27 GMT
Organization: Retired Electronic Engineer and Y2K expert
Lines: 80
Message-ID: <84j1nf$22eo$1@news.gate.net>
References: <84fmpj$ptf$1 AT newsg3 DOT svr DOT pol DOT co DOT uk> <84gdqg$29fi$1 AT news DOT gate DOT net> <84il97$7ir$1 AT news6 DOT svr DOT pol DOT co DOT uk>
NNTP-Posting-Host: ppp-57.elpasonet.net
X-Trace: news.gate.net 946670127 68056 216.84.6.86 (31 Dec 1999 19:55:27 GMT)
X-Complaints-To: abuse AT gate DOT net
NNTP-Posting-Date: 31 Dec 1999 19:55:27 GMT
X-Newsreader: News Xpress 2.01
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In article <84il97$7ir$1 AT news6 DOT svr DOT pol DOT co DOT uk>, "Mike Collins" <Mike AT NO_SPAM DOT e-col DOT freeserve DOT co DOT uk> wrote:
>
>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?
>

  But the bit fields did not use all the space so the compiler is free to
add or subtract additional space as it see fit.
Since in thoeory you are not using this extra space. If you are using
the extra space you should define it.





David A. Scott
--

SCOTT19U.ZIP NOW AVAILABLE WORLD WIDE
http://www.jim.com/jamesd/Kong/scott19u.zip
                    
Scott famous encryption website NOT FOR WIMPS
http://members.xoom.com/ecil/index.htm

Scott rejected paper for the ACM
http://members.xoom.com/ecil/dspaper.htm

Scott famous Compression Page WIMPS allowed
http://members.xoom.com/ecil/compress.htm

**NOTE EMAIL address is for SPAMERS***

I leave you with this final thought from President Bill Clinton:

   "The road to tyranny, we must never forget, begins with the destruction of the truth." 

- Raw text -


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