This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Endian swapping with C code
- From: Falk Hueffner <hueffner at informatik dot uni-tuebingen dot de>
- To: Etienne Lorrain <etienne_lorrain at yahoo dot fr>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 23 Jul 2004 16:23:47 +0200
- Subject: Re: Endian swapping with C code
- References: <20040723132735.21057.qmail@web11806.mail.yahoo.com>
Etienne Lorrain <etienne_lorrain@yahoo.fr> writes:
> Just a small idea, a bit late and not even backed up
> with some real patch:
> instead of having an inline function to byte-swap (and so
> finnishing in a real application to do
> " byte_swapped (byte_swapped (byte_swapped (X)))"
> or
> " if (byte_swapped (X) == byte_swapped (Y)) "
> or
> " byte_swapped (X) = byte_swapped (Y) | byte_swapped (0xFF) "
>
> Then "simply" add a variable attribute:
> int ethernet_integer __attribute__((bigendian));
> int intel_integer __attribute__((littleendian));
> const short int intel_const __attribute__((littleendian)) = 0xFF;
>
> It opens optimisation opportunities, warnings if passing a pointer
> of the wrong endianness, does not clash with integer promotion on
> function parameters...
Firstly, this would add huge amount of complexity to gcc and be pretty
error prone. Secondly, if you remotely care about performance, you
want endian conversion to happen at exactly one clearly defined place,
for which a built-in function will do just fine.
So in summary I think this is a very bad idea.
--
Falk