PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs323] Bit fields followup
Date: Thursday, 12 Nov 2020, 16:53:05


    > Message Posted By: Unknown
    >
    > Can you explain why putting k second rather than third (in
    > the following struct) will make a difference?
    >
    >     > typedef struct
    >     > {
    >     >     unsigned int code : 24;
    >     >     unsigned int prefix : 24;
    >     >     char k : 8;
    >     > } tableEntry;

C bit fields are implementation-dependent.  The most
likely explanation for the struct above requiring 12
bytes is that gcc does not allow any field to span a
multiple-of-four-byte boundary.
=====

    > Also I found that in order to pass test 18 (All storage
    > reachable), all the bits add up together must be a multiple
    > of 8, I was wondering why?

My solution offers a counterexample to the claim above.
What is your basis for making it?  (I suggest that we
take this discussion off the newsgroup since i doubt
that is of interest to most students.)

--Stan-
PREV INDEX NEXT