On Wed, Jun 05, 2013 at 01:49:28PM -0400, Ed Smith-Rowland wrote:
> On 06/05/2013 10:43 AM, kuldeep dhaka wrote:
> >Hello,
> >
> >while working on a program i faced a problem.
> >i need only 20 bit , and having a 32 bit only waste more memory(12
> >byte), 24bit would much be better.
> >i need a uint24_t variable but gcc dont support it so i have to start
> >with uint32_t.
> >it would be very nice if gcc support such variables.
> >i made a little program and found that gcc (on i686) returned error.
> >
> >http://embeddedgurus.com/stack-overflow/2009/06/three-byte-integers/
> >
> >--
> >Kuldeep Singh Dhaka
> >Sakul
> >+91-8791676237
> >kuldeepdha...@gmail.com
> >Programmer, Open Source, Web Developer, System Administrator,
> >Entrepreneur, Animal Lover, Student, Reverse Engineer, Embedded
> >System, Learning.
> >
> >Bitcoins Accepted.
> >My GnuPG Public Key
> >Fork Me
> >
> Even if gcc had such a type I bet they would get aligned to 4-bytes
> on most any target.

Precisely this. And in fact gcc / C can support this, using bitfields.

typedef struct { int      bits : 24; }  int24_t;
typedef struct { unsigned bits : 24; } uint24_t;

This is as close as you can get, and these structs will be 4-byte
aligned.

Cheers,
Rob

Reply via email to