Re: [dev] dwm bit fields conversion

From: Kurt Van Dijck <kurt.van.dijck_AT_eia.be>
Date: Mon, 8 Jul 2013 09:47:10 +0200

Hello,

I just remembered this thing from an embedded 16bit CPU.

Why would you do
        unsigned char XXX :1
and not
        unsigned int XXX :1

I think the latter may benefit code size (a tiny bit)
because it avoids an integer promotion, at least on some platforms.

Kind regards,
Kurt

On Sun, Jul 07, 2013 at 11:07:58AM -0400, Jacob Todd wrote:
> this will be useful for running dwm on my pdp-11.
>
> On Sun, Jul 7, 2013 at 10:49 AM, koneu <koneu93_AT_googlemail.com> wrote:
> > In Xdefs.h, Bool is typedef'd as int (= at least 2 bytes, sometimes more, depending on the implementation), of which we set the last bit to 1 or 0.
> > In the Monitor and Client structures dwm uses, we can instead use char bit fields, storing up to 8 Bool values in 1 byte.
> >
> > diff --git a/dwm.c b/dwm.c
> > index 314adf4..83af1f6 100644
> > --- a/dwm.c
> > +++ b/dwm.c
> > _AT_@ -91,7 +91,7 @@ struct Client {
> > int basew, baseh, incw, inch, maxw, maxh, minw, minh;
> > int bw, oldbw;
> > unsigned int tags;
> > - Bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
> > + unsigned char isfixed :1, isfloating :1, isurgent :1, neverfocus :1, oldstate :1, isfullscreen :1, :2;
> > Client *next;
> > Client *snext;
> > Monitor *mon;
> > _AT_@ -121,8 +121,7 @@ struct Monitor {
> > unsigned int seltags;
> > unsigned int sellt;
> > unsigned int tagset[2];
> > - Bool showbar;
> > - Bool topbar;
> > + unsigned char showbar :1, topbar :1, :6;
> > Client *clients;
> > Client *sel;
> > Client *stack;
> >
> >
>
Received on Mon Jul 08 2013 - 09:47:10 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 08 2013 - 10:00:03 CEST