From: Glynn Clements <glynn.clements@virgin.net>
To: Massimiliano Cialdi <cialdi@firenze.net>
Cc: linux-c-programming <linux-c-programming@vger.kernel.org>
Subject: Re: bitfield array
Date: Mon, 12 Jan 2004 21:06:58 +0000 [thread overview]
Message-ID: <16387.3186.943352.155205@cerise.nosuchdomain.co.uk> (raw)
In-Reply-To: <20040112111016.000072cf.cialdi@firenze.net>
Massimiliano Cialdi wrote:
> Is it possible to declare a bitfield array?
No.
> I also tried with
>
> typedef struct
> {
> u8_t busy:1;
> }dummy;
> dummy a[10];
>
> but then a is as large as 10 bytes.
Structures which contain bitfields will be padded to an integral
number of bytes.
> > AFAIK, bitfields are stored in memory block which can only be
> > allocated with 1-byte minimum.. Try to allocate 1 bit in memory,
> > sounds not possible :-).
>
> I know but I don't want to allocate a single bit. Since I need an array
> of binary flag, I thought that the compiler could help me. 10 bits could
> be placed in 2 bytes. Else I need 10 bytes (80% of space lost).
Declare a 16-bit field and set of macros to access the individual
bits, e.g.
typedef struct
{
uint16_t bits;
} dummy;
#define get_flag(s, i) (((s).bits >> (i)) & 1)
#define set_flag(s, i) ((s).bits |= 1 << (i))
#define clear_flag(s, i) ((s).bits &= ~(1 << (i)))
--
Glynn Clements <glynn.clements@virgin.net>
prev parent reply other threads:[~2004-01-12 21:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-12 10:10 bitfield array Massimiliano Cialdi
2004-01-12 10:29 ` wwp
2004-01-12 10:56 ` Massimiliano Cialdi
2004-01-12 13:40 ` Mariano Moreyra
2004-01-13 1:02 ` James Stevenson
2004-01-12 21:06 ` Glynn Clements [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=16387.3186.943352.155205@cerise.nosuchdomain.co.uk \
--to=glynn.clements@virgin.net \
--cc=cialdi@firenze.net \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).