| Let me tell you - I have programmed for twenty years without
    | knowing the meaning of little-endian and big-endian. Yes,
    | they had something to do with the order of bytes in an integer,
    | but there are many strange architectures and mixed versions,
    | and there is no need at all to know such things.
    | Yes, knowing such things is directly harmful.

    I can only see this if you don't do hardware interface programming
    or if you do but it's all on one $ARCH.
    There are places (like USB host controller drivers) that using
    endian swapping is necessary.

As indeed was necessary here. And the code that was there did the
job fine. And did not need the concept of endianness or swapping.
It just did what was to be done.

Let me give another example.
When reading DOS-type partition tables, one encounters four bytes
that give the start of a partition. Least significant byte first.

So everybody who does not want to know how integers are represented
on the current architecture writes
        start = p[0] + (p[1] << 8) + (p[2] << 16) + (p[3] << 24);
And it just works.

But smart people write
        start = *(int *) p;
And it fails on big-endian architectures.

Then even smarter people write
        start = le32_to_cpu(*(int *) p);
And it fails on a DEC Alpha because the alignment is wrong.

The current kernel writes
    #include <asm/unaligned.h>
    #define START_SECT(p)   ({ __typeof__(p->start_sect) __a =      \
                                get_unaligned(&p->start_sect);  \
                                le32_to_cpu(__a); \
                            })
Look what progress!
We need an additional include file, an additional define,
compiler magic, lots of ugliness.

No, never use a cast and just magically the code will work.

If you ever notice that using a cast produces better code
then most likely the compiler must be improved.

Andries


-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to