[LCP]#defines to know Endianness

Kumar, Sarath sarath_kumar at mentorg.com
Thu Jul 1 20:27:02 UTC 2004



Hope you have already figured out what the macro can look like, one
suggestion is declare an int, store it in memort extract the bit storage
pattern and u have the endianess exposed!! 

-----Original Message----- 
From: linuxcprogramming-admin at lists.linux.org.au [
mailto:linuxcprogramming-admin at lists.linux.org.au
<mailto:linuxcprogramming-admin at lists.linux.org.au> ] On Behalf Of Greg
Black

Sent: Thursday, July 01, 2004 5:22 PM 
To: linuxcprogramming at lists.linux.org.au 
Subject: Re: [LCP]#defines to know Endianness 

On 2004-07-01, John Navil Joseph wrote: 

> Yes, linux does define the BYTE_ORDER macro, but it may not be defined

> in other operating systems (windows?). 

Who cares?  But if you do care, why not find out? 

> I'm just wondering if C Standard requires this macro to be defined by 
> all compilers, then I can be sure that mine would be a truly portable 
> code. 

The C Standard does not care about stuff like that and there is nothing
it offers for it. 

You have two choices: 

  1. Find something like I suggested that works on all the 
     platforms you care about; or 

  2. Write your own macro and use that -- it's incredibly 
     trivial, after all. 

You might also ask yourself why you're doing this at all.  It's rare for
well-written code to need to know stuff like this.

Cheers, Greg 
_______________________________________________ 
This is the Linux C Programming List 
:  http://lists.linux.org.au/listinfo/linuxcprogramming
<http://lists.linux.org.au/listinfo/linuxcprogramming>  List 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.linux.org.au/pipermail/linuxcprogramming/attachments/20040701/516d2a33/attachment.htm 


More information about the linuxCprogramming mailing list