News for hackers. Stuff that matters.
Re:A review of endianness bugs in Qt, and how they were fixed by messe on Saturday January 02, 2021 @08:01AM (#25612557)
> But that code isn't portable for a different endian machine.

Except it is. On x86, which is little endian, compilers are smart enough to convert it to a mov.

> These functions will either swap, or not, depending on the endianness of the target machine

So will the above. Here's the MIPS little endian version:

    read_int32(unsigned char*):
        lwl     $2,3($4)
        j       $31
        lwr     $2,0($4)
This doesn't swap. The MIPS big endian version:

    read_int32(unsigned char*):
        lbu     $3,1($4)
        lbu     $2,2($4)
        sll     $5,$3,8
        lbu     $6,0($4)
        sll     $3,$2,16
        lbu     $2,3($4)
        or      $3,$5,$3
        or      $3,$3,$6
        sll     $2,$2,24
        j       $31
        or      $2,$3,$2
This swaps and ors. What part of this do you not consider portable between different-endian machines?

There are no comments on this comment yet.