This is the mail archive of the gsl-discuss@sourceware.cygnus.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gsl 0.5 little_endian_p backwards?


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.
 > 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]