gsl 0.5 little_endian_p backwards?

Bill Schottstaedt bil@ccrma.stanford.edu
Mon Mar 20 06:24:00 GMT 2000


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