[Asterisk-Dev] ast_flags question

Mike M no-linux-support at earthlink.net
Sat Jan 8 10:14:16 MST 2005


On Sat, Jan 08, 2005 at 08:06:41AM -0700, Kevin P. Fleming wrote:
> Holger Schurig wrote:
> 
> >struct bitstruct {
> >        int b : 1;
> >};
> 
> >That saves bytes and is very clear. 
> 
> This does not save any bytes; this struct will still require 32 bits 
> (four bytes) for storage (see the "int" specified there?).

You can control the storage somewhat with:

#define PACKED __attribute__ ((packed))

struct bitstruct {
        int b  : 1 PACKED;
        int bx : 7 PACKED;
};

This type of structure makes sense when you are dealing with old
bit-oriented protocol like SS7.  Even TCP has its flags fields where
bit definitions can be used effectively.

Octet parsimony is wasted effort now except when handling old
bit-oriented protocols.  Memory words are cheap compared
to the cluttered appearance of code, additional complexity, and extra
CPU cycles required.  If you examine SCTP, a recently developed cousion
to TCP and UDP, you will see no bit definitions.  Examine SIP for an
even further departure from bit-oriented protocols.

Election to avoid bit definition on new design is correct.

-- 
Mike



More information about the asterisk-dev mailing list