This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 3 byte variables [feature request]
- From: Rob <robpilling at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Wed, 5 Jun 2013 21:11:45 +0100
- Subject: Re: 3 byte variables [feature request]
- References: <CANPwNKUatJmz+G1Jasx_ZUkd+NmGHwf-tpayRecsDxJ--+H4_Q at mail dot gmail dot com> <CANPwNKVdMX7mAFmy5+VZEWK2jQkV6+4r1tVUT+J62zdpFgHbyw at mail dot gmail dot com> <CANPwNKVBaroVrzRLHgutuhbLz+9CCfudnCR0OfetKf=XqPdksA at mail dot gmail dot com> <51AF7A28 dot 3080306 at verizon dot net>
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
> >kuldeepdhaka9@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