Re: kernel programming - big endian and little endian issues

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am Donnerstag, den 27.07.2006, 23:14 +0530 schrieb Gaurav Dhiman:
> Can someone point me the use of these funtions in kernel, and why we
> use them, does not the compiler handle the machine specific endian
> issues ??

Consider using networking packets. To interpret them in the correct way
they need to be specified for one order. The Bluetooth specification for
example specifies it's packets in little endian order. If you didn't use
functions to convert from one order to another your code would break on
the other machines. And as the Linux kernel is a generic kernel that
supports different architectures with different endianess orders (IA32
x86 machines with little endian or PowerPC with big endian) it needs to
use these functions, e.g. __le16_to_cpu() which compiles to nothing on a
little endian machine, but converts on a big endian machine as expected.

> For example, if we write a small program as follows, will it make any
> difference if we compile and run it on little or big endian or will
> not the compiler create the code accordingly and taking care of this
> endian issue.

First of all you are now mixing userspace with kernel space -- be aware
that this is the kernelnewbies ML ;-)
But beside that a compiled binary on my little endian notebook wouldn't
work on my big endian iMac. You would need to use something like a
universal binary for the current Macs.

Martin


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux