[Dovecot] 1.0.rc27 released - Compiling on AIX - brovke bitfield in mbox-sync-private.h

Timo Sirainen tss at iki.fi
Sun Mar 18 21:18:50 EET 2007


On Sun, 2007-03-18 at 19:01 +0000, John Robinson wrote:
> On 18/03/2007 15:51, Timo Sirainen wrote:
> > On Sat, 2007-03-17 at 01:39 +0100, Václav Haisman wrote:
> [...]
> >> uint32_t flags:8;
> >> uint32_t uid_broken:1;
> >> uint32_t expunged:1;
> >> uint32_t pseudo:1;
> > 
> > Right, I didn't think of that. But that feels a bit ugly :) I don't
> > think it saves much memory anyway, so I'll keep it as uint8_t flags.
> 
> I may be a bit of a novice at this sort of thing, but if you want 
> bitfields, does it matter what you say? In theory at least,
>    unsigned int x:1;
> is all you need, it'll take one bit of storage, there's no point 
> specifying the size of the thing you want truncated to one bit, what 
> you're asking for is precisely one bit to be used as an unsigned 
> integer. By saying e.g.
>    uint8 x:1;
> you're specifying the size twice, and perhaps it's not a surprise if you 
> get errors trying to compile it: which is it to be, 8 bits or 1?

Hmm. Looks like you're almost correct. I thought it worked so that if
you had:

uint8_t foo;
unsigned int bar:1;

That the bar would always allocate 32 bits more to the struct, but looks
like it doesn't at least with gcc.

There is however one difference:

struct a { uint8_t f1; uint8_t f2:1; }
struct b { uint8_t f1; unsigned int f2:1; }

sizeof(struct a) == 2 but sizeof(struct b) == 4

But this doesn't matter much. I don't think there's a single struct in
Dovecot's code that doesn't contain 32bit or 64bit fields.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://dovecot.org/pipermail/dovecot/attachments/20070318/e232518d/attachment.pgp 


More information about the dovecot mailing list