Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #147282

Re: Bit field usage

From Tim Rentsch <tr.17687@z991.linuxsc.com>
Newsgroups comp.lang.c
Subject Re: Bit field usage
Date 2019-10-27 04:54 -0700
Organization A noiseless patient Spider
Message-ID <86o8y2flo5.fsf@linuxsc.com> (permalink)
References <qorerp$af6$1@dont-email.me> <1bo8y6azlw.fsf@pfeifferfamily.net> <86woctfy1g.fsf@linuxsc.com> <1bwocsalcq.fsf@pfeifferfamily.net>

Show all headers | View raw


Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Joe Pfeiffer <pfeiffer@cs.nmsu.edu> writes:
>>
>>> jacobnavia <jacob@jacob.remcomp.fr> writes:
>>>
>>>> 1) To access a bitfield, the compiler generates a sequence of shifts
>>>> that increases execution time.
>>>>
>>>> 2) The instructions sequence of the shifts increases code size.
>>>>
>>>> Obviously, if you have more than 64 flags (in a 64 bit machine) or
>>>> more than 32 flags in a 32 bit machine, bitfields can save a lot of
>>>> data space:  you can fit up to 128 bitfields in 16 bytes, instead of
>>>> 128 bytes if you use a full char for each bit field.
>>>>
>>>> It is important to check two things:
>>>> 1) If a bit field is heavily used, consider transforming it into an
>>>> unsigned char.
>>>> 2) If you have a few bit fields with bitsize less than the word size
>>>> of your machine, consider if the alignment requirements are nullifying
>>>> any space gains obtained by using bit fields.
>>>
>>> I got burned badly enough by bitfields doing unexpected things decades
>>> ago that I abandoned them and do my own shifts and masks.
>>
>> Out of curiosity, what kind of problems did you run into?
>
> It was a long time ago...  if I remember correctly (always a big if!)  I
> was using them to construct things like instruction and floating point
> formats, and things got scrambled in the switch from Motorola 680x0 to
> Sparc.

Do you remember anything else?  This tells me when you ran into
some problems but not what the problems were.  Might the problems
have been not with bitfields per se but just with platform
differences?  Making a guess, maybe you simply found it easier to
get things right (for the two platforms) using shifting and
masking than using two sets of bitfields?  I think bitfields
work pretty well for a single platform, but are sometimes hard to
get right if dealing with multiple platforms.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Bit field usage jacobnavia <jacob@jacob.remcomp.fr> - 2019-10-24 08:03 +0200
  Re: Bit field usage Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-10-24 10:15 -0600
    Re: Bit field usage jacobnavia <jacob@jacob.remcomp.fr> - 2019-10-24 18:55 +0200
      Re: Bit field usage Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-10-24 21:28 -0600
    Re: Bit field usage scott@slp53.sl.home (Scott Lurndal) - 2019-10-24 17:22 +0000
      Re: Bit field usage Bonita Montero <Bonita.Montero@gmail.com> - 2019-10-24 19:45 +0200
        Re: Bit field usage jacobnavia <jacob@jacob.remcomp.fr> - 2019-10-24 19:59 +0200
          Re: Bit field usage Bonita Montero <Bonita.Montero@gmail.com> - 2019-10-24 20:02 +0200
            Re: Bit field usage Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-10-24 21:29 -0600
              Re: Bit field usage Bonita Montero <Bonita.Montero@gmail.com> - 2019-10-25 07:51 +0200
                Re: Bit field usage scott@slp53.sl.home (Scott Lurndal) - 2019-10-25 15:05 +0000
        Re: Bit field usage Bart <bc@freeuk.com> - 2019-10-24 19:13 +0100
          Re: Bit field usage Bonita Montero <Bonita.Montero@gmail.com> - 2019-10-24 20:54 +0200
            Re: Bit field usage Bart <bc@freeuk.com> - 2019-10-24 20:12 +0100
              Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-10-24 23:03 +0200
                Re: Bit field usage Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-10-24 22:50 +0100
                Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-10-25 09:18 +0200
                Re: Bit field usage Reinhardt Behm <rbehm@hushmail.com> - 2019-10-25 15:46 +0800
                Re: Bit field usage Robert Wessel <robertwessel2@yahoo.com> - 2019-10-26 12:36 -0500
                Re: Bit field usage scott@slp53.sl.home (Scott Lurndal) - 2019-10-25 15:04 +0000
                Re: Bit field usage Robert Wessel <robertwessel2@yahoo.com> - 2019-10-26 12:40 -0500
                Re: Bit field usage Philipp Klaus Krause <pkk@spth.de> - 2019-10-26 21:12 +0200
              Re: Bit field usage Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-10-25 09:25 -0600
                Re: Bit field usage Robert Wessel <robertwessel2@yahoo.com> - 2019-10-26 12:52 -0500
      Re: Bit field usage jacobnavia <jacob@jacob.remcomp.fr> - 2019-10-24 19:56 +0200
        Re: Bit field usage already5chosen@yahoo.com - 2019-10-24 12:03 -0700
          Re: Bit field usage scott@slp53.sl.home (Scott Lurndal) - 2019-10-24 19:40 +0000
            Re: Bit field usage jacobnavia <jacob@jacob.remcomp.fr> - 2019-10-24 22:15 +0200
            Re: Bit field usage already5chosen@yahoo.com - 2019-10-24 14:16 -0700
    Re: Bit field usage Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-10-24 17:50 -0700
      Re: Bit field usage Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-10-25 09:36 -0600
        Re: Bit field usage Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-10-27 04:54 -0700
          Re: Bit field usage Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-10-27 10:05 -0600
  Re: Bit field usage Philipp Klaus Krause <pkk@spth.de> - 2019-10-26 20:15 +0200
    Re: Bit field usage Philipp Klaus Krause <pkk@spth.de> - 2019-10-26 20:16 +0200
      Re: Bit field usage jacobnavia <jacob@jacob.remcomp.fr> - 2019-10-26 20:37 +0200
        Re: Bit field usage Robert Wessel <robertwessel2@yahoo.com> - 2019-10-26 13:41 -0500
          Re: Bit field usage jacobnavia <jacob@jacob.remcomp.fr> - 2019-10-26 21:54 +0200
            Re: Bit field usage already5chosen@yahoo.com - 2019-10-27 03:46 -0700
              Re: Bit field usage jacobnavia <jacob@jacob.remcomp.fr> - 2019-10-27 12:50 +0100
                Re: Bit field usage already5chosen@yahoo.com - 2019-10-27 06:37 -0700
              Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-10-27 13:00 +0100
                Re: Bit field usage already5chosen@yahoo.com - 2019-10-27 07:19 -0700
                Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-10-27 22:30 +0100
                Re: Bit field usage Christopher Collins <ccollins476ad@gmail.com> - 2019-11-07 12:36 -0800
                Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-11-08 08:18 +0100
                Re: Bit field usage Christopher Collins <ccollins476ad@gmail.com> - 2019-11-08 10:19 -0800
                Re: Bit field usage Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-11-08 21:47 +0000
                Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-11-10 14:08 +0100
                Re: Bit field usage Christopher Collins <ccollins476ad@gmail.com> - 2019-11-11 09:26 -0800
                Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-11-11 20:31 +0100
                Re: Bit field usage Christopher Collins <ccollins476ad@gmail.com> - 2019-11-11 23:01 -0800
                Re: Bit field usage Christopher Collins <ccollins476ad@gmail.com> - 2019-11-11 23:25 -0800
                Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-11-12 10:54 +0100
                Re: Bit field usage Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-11-12 14:43 +0000
                Re: Bit field usage James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-11-12 10:54 -0500
                Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-11-12 19:37 +0100
              Re: Bit field usage Robert Wessel <robertwessel2@yahoo.com> - 2019-10-27 08:36 -0500
                Re: Bit field usage already5chosen@yahoo.com - 2019-10-27 06:49 -0700
            Re: Bit field usage Bonita Montero <Bonita.Montero@gmail.com> - 2019-10-27 14:23 +0100
            Re: Bit field usage Robert Wessel <robertwessel2@yahoo.com> - 2019-10-27 08:42 -0500
        Re: Bit field usage Philipp Klaus Krause <pkk@spth.de> - 2019-10-26 21:06 +0200
        Re: Bit field usage Bart <bc@freeuk.com> - 2019-10-26 20:41 +0100
          Re: Bit field usage Philipp Klaus Krause <pkk@spth.de> - 2019-10-27 08:29 +0100
            Re: Bit field usage David Brown <david.brown@hesbynett.no> - 2019-10-27 13:05 +0100

csiph-web