This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Endian swapping with C code

Etienne Lorrain <> 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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]