From -1040010702452402558
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,738ae3371beb3408
X-Google-Attributes: gidf78e5,public
From: Francis Glassborow <francis@robinton.demon.co.uk>
Subject: Re: portable method of determining endianness byte order.
Date: 1999/11/19
Message-ID: <m5PMyMAN8aN4EwXX@robinton.demon.co.uk>#1/1
X-Deja-AN: 550689446
Approved: stephen.clamage@sun.com (comp.std.c++)
References: <38329967.470B6CED@hqs.mid.gmeds.com>
X-UID: 0000000001
X-Status: $$$T
Organization: Southfield Microcomputer SS
Mime-Version: 1.0
Reply-To: Francis Glassborow <francisG@robinton.demon.co.uk>
Newsgroups: comp.std.c++
Originator: clamage@taumet


In article <38329967.470B6CED@hqs.mid.gmeds.com>, Pukalo Boyd
810-492-3661 <qz3fwd@hqs.mid.gmeds.com> writes
>I have been trying to find a portable method of determining the
>endianness byte order at compile time
>to produce code that will work properly on both windows and unix
>machines. I have searched the documentation
>i have ( the books on the C Standard Library and the C++ Standard
>Library) and havent found anything. Please help. Any pointers or
>suggestions would be very helpful. Thanks.

Having checked that the executing system has the same number of
bits/byte that you expect, that it has the same size int (long, float
etc) you could try something such as:

union {
        int sample;
        char bytes[sizeof(int)];
} test;
if(sizeof(int) == 2){
 test.sample = Ox0102;  
        if (test.bytes[0] == 1) ...
and so on.

but there are so many variations that it hardly seems worth the effort.




Francis Glassborow      Journal Editor, Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]




