From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,889e505ce067252c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-02-08 13:29:53 PST Path: nntp.gmd.de!news.rwth-aachen.de!newsserver.rrzn.uni-hannover.de!aix11.hrz.uni-oldenburg.de!uniol!zib-berlin.de!Germany.EU.net!EU.net!sun4nl!news.nic.surfnet.nl!tudelft.nl!liberator.et.tudelft.nl!zen.et.tudelft.nl!rooi From: rooi@zen.et.tudelft.nl (Mark de Rooi) Newsgroups: comp.lang.ada Subject: Re: Ada95 - Determining Machine Byte Order Date: 8 Feb 1995 12:36:51 GMT Organization: Delft University of Technology, Dept. of Electrical Engineering Message-ID: <3hadt3$44p@liberator.et.tudelft.nl> References: <3gpo58$g48@ixnews3.ix.netcom.com> <3gvudv$k4b@liberator.et.tudelft.nl> <3h45bq$fev@gnat.cs.nyu.edu> NNTP-Posting-Host: zen.et.tudelft.nl X-Newsreader: NN version 6.5.0 #2 (NOV) Date: 1995-02-08T12:36:51+00:00 List-Id: dewar@cs.nyu.edu (Robert Dewar) writes: >Not only is Mark's solution: > int n = 1, little_endian = (*((char *)&n) == n); >not very clear (though if you study it for a second and can find your >way around * and & in C, you can see how it works), but more significantly >there is no guarantee that this will work, it is equivalent to the use of >unchecked conversion in Ada, and equally problematic. Mark if you don't >believe me, try seeing what this gives on a Cray, or if you want to take >the theoretical approach, tell me where in the ANSI standard it is written >that this will do something well defined. Unfortunately, I don't have a Cray handy, but I will take your word for it that my suggestion won't work on one. As I mentioned in my followup, it is required that sizeof(char) < sizeof(int) for this to work. Is sizeof(char) == sizeof(int) for the compiler you use on your Cray? I am curious as to the reason my (admittedly not very clear) solution doesn't work on a Cray. As for the ANSI C standard, well, _of course_ casting a pointer-to-int to a pointer-to-char and then dereferencing it is machine- and compiler- dependent. If it weren't, there would be no point to my obscure piece of code! Note that I specifically mentioned that it wouldn't work on *every* machine. It works on every PC, Mac and Unix workstation I ever used, but not on some DSPs, and apparently, on a Cray. I wasn't aware of the Ada Way (tm) to handle this, so I just gave a quick fix to the guy who asked, so he could get on with his work. >All in all I think that the Ada way of doing things: > Little_Endian : constant Boolean := > System.Default_Bit_Order = System.Low_Order_First; >maybe just a *little* bit clearer :-) No argument there ;-) Regards, Mark