gsl 0.5 little_endian_p backwards?

Brian Gough bjg@network-theory.co.uk
Mon Mar 20 12:58:00 GMT 2000


Thanks. That function has been removed from the version in CVS. It's
true that the numbers were the wrong way round.

Bill Schottstaedt writes:
 > I think the endian-ness functions in gsl-0.5/ieee-utils/endian.c
 > are backwards.  This test program:
 > 
 > #include <stdio.h>
 > #include <stdlib.h>
 > 
 > int
 > little_endian_p (void) {
 >   /* Are we little or big endian?  From Harbison & Steele.  */
 >   union
 >   {
 >     long l;
 >     char c[sizeof (long)];
 >   } u;
 >   u.l = 1;
 >   return (u.c[sizeof (long) - 1] == 1);
 > }
 > 
 > int
 > endianness (void) {
 >   /* Determine true endianness, big endian 4321, little endian 1234. */
 >   union
 >   {
 >     long l;
 >     char c[sizeof (long)];
 >   } u;
 >   u.l = 0x04030201;
 >   return (u.c[0]+10*(u.c[1]+10*(u.c[2]+10*u.c[3])));
 > }
 > 
 > int main(int argc, char **argv)
 > {
 >   fprintf(stdout,"%d %d ",little_endian_p(),endianness());
 > }
 > 
 > prints 0 4321 on a (little-endian) PC (running redhat linux), but
 > 1 1234 on a (big-endian) SGI.
 > 


More information about the Gsl-discuss mailing list