Re: Endianness conversion functions

Krister Walfridsson <[email protected]>
Newsgroups gmane.os.netbsd.devel.general
Message-ID <[email protected]>
On Thu, 18 Jan 2007, Christian Biere wrote:
> Krister Walfridsson wrote:
>> This breaks the C aliasing rules [*],
>
> I know that's not C but since there was prior art and due to the
> alignment check, I assumed it would be fine for this "implementation".
> Also shouldn't the "void *" invalidate any such aliasing assumptions?

No, aliasing is about the type of the memory access, and in a statement
like

    *(uint32_t *)buf = foo;

the memory is accessed as a uint32_t regardless of the type of buf.

Casting to void* makes the analysis harder for the compiler, so it
is often the case that code with aliasing issues start to "work" when
you sprinkle some void* over it, but it is no guarantee that it will
work with other versions of the compiler...
2B2B


> It's a bit sad that GCC doesn't recognize the shift/or construct though because
> I think it's cleanest version - considering that memcpy() might cause a huge
> penalty.

It does recognize some of the shift/or constructs, but that support
need to be improved.  That has been on my TODO list for a long time
now.  But I have not found the time yet... :(

    /Krister
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.