This is the mail archive of the
mailing list for the GCC project.
Re: Two suggestions for gcc C compiler to extend C language (by WD Smith)
- From: Oleg Endo <oleg dot endo at t-online dot de>
- To: Warren D Smith <warren dot wds at gmail dot com>, gcc at gcc dot gnu dot org
- Date: Wed, 27 Jul 2016 00:40:30 +0900
- Subject: Re: Two suggestions for gcc C compiler to extend C language (by WD Smith)
- Authentication-results: sourceware.org; auth=none
- References: <CAAJP7Y3cHYEOpdhZUXF1PZAJ=vkKoozRiPgwm2V_jH_T63XTKw@mail.gmail.com> <CAH6eHdRrmRWARhbcqWbqV07Y=SZp+Hsiv5-42y2k28CHqP4+UQ@mail.gmail.com> <CAAJP7Y0oRZmE4qS=shs4m7EWjWK2RfZdK2NSe1Kx1ZUT6W=QZw@mail.gmail.com>
On Tue, 2016-07-26 at 10:37 -0400, Warren D Smith wrote:
> Also, I know on some machines to access a byte you have to get a word
> (larger than 8 bits)
> from memory, do shifts and masks. So clearly you already do that
> inside gcc.
> It therefore is trivial for you to do uint4_t also, because it would
> be that exact same code you already have, just change some numbers.
You should try to do that yourself once. Get the GCC source code and
just "change some numbers here and there" and see how far it goes...
Build instructions can be found here: https://gcc.gnu.org/install/
What you are suggesting looks like a generic way of "doing bitfields",
essentially making every integer a bitfield and things like int8_t,
int16_t turn into exceptions that happen to align with what the
So instead of ..
int a : 6;
int b : 3;
.. we get ...
and then sizeof (bleh) = ???
Surely, the compiler can be taught that kind of stuff, it's just a
question of effort.
Alternatively, you can implement an N-bit drop-in integer type in C++11
yourself with container specializations of std::array and std::vector
to get tightly packed e.g. int7_t (still with some padding bits). This
will allow you to evaluate the usefulness and effectiveness of your
proposed extensions in some real-world applications as a start.