This is the mail archive of the
gsl-discuss@sourceware.cygnus.com
mailing list for the GSL project.
Re: gsl 0.5 little_endian_p backwards?
- To: Bill Schottstaedt <bil at ccrma dot stanford dot edu>
- Subject: Re: gsl 0.5 little_endian_p backwards?
- From: Brian Gough <bjg at network-theory dot co dot uk>
- Date: Mon, 20 Mar 2000 20:06:55 +0000 (GMT)
- Cc: gsl-discuss at sourceware dot cygnus dot com
- References: <200003201424.GAA00556@cmn14.stanford.edu>
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.
>