This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: 3 byte variables [feature request]
- From: Miles Bader <miles at gnu dot org>
- To: Rob <robpilling at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 06 Jun 2013 09:08:53 +0900
- 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> <20130605201145 dot GA18839 at jeffraw>
If you're using C++ and are willing to use gcc (and clang) extensions,
you can do a bit better, e.g.:
class __attribute__((packed)) int24_t
{
public:
operator int () const { return b; }
int24_t (int v) : b (v) {}
int24_t () {}
private:
int b : 24;
};
Then an array like "int24_t a[1000]" will only take 3000 bytes, and
you can kinda/sorta mix int24_t types with integers...
Of course the generated code is not so efficient, so don't use such
types in inner loops if you can help it!
[Dunno if C++11 has any more portable replacement for the
__attribute__((packed))...]
-miles
--
éäããããæãããéãæããã