From owner-freebsd-hackers Mon Nov 20 8:31:47 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from mail.matriplex.com (ns1.matriplex.com [208.131.42.8]) by hub.freebsd.org (Postfix) with ESMTP id 0643C37B479 for ; Mon, 20 Nov 2000 08:31:44 -0800 (PST) Received: from mail.matriplex.com (mail.matriplex.com [208.131.42.9]) by mail.matriplex.com (8.9.2/8.9.2) with ESMTP id IAA54753; Mon, 20 Nov 2000 08:31:13 -0800 (PST) (envelope-from rh@matriplex.com) Date: Mon, 20 Nov 2000 08:31:13 -0800 (PST) From: Richard Hodges To: Alex Koshterek Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Byte order? In-Reply-To: <00112017175200.47740@pro.lookanswer.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Mon, 20 Nov 2000, Alex Koshterek wrote: > I know, that x86 is big endian architecture > but simple programm like this: > > #include > #include > main () { > /* Are we little or big endian? From Harbison&Steele. */ > union > { > long l; > char c[sizeof (long)]; > } u; > u.l = 1; > printf ("Little endian? %s\n", (u.c[sizeof (long) - 1] == 1) ? "yes" : "no"); > #if BYTE_ORDER == BIG_ENDIAN > printf("Big endian\n"); > #elif BYTE_ORDER == LITTLE_ENDIAN > printf("Little endian\n"); > #else > printf("Unknown\n"); > #endif > } Just to be different, why not use something like: if(htonl(1) == 1) bigendian else littleendian Of course, that spoils the fun of figuring out what the compiler is doing with the union :-) All the best, -Richard ------------------------------------------- Richard Hodges | Matriplex, inc. | 769 Basque Way rh@matriplex.com | Carson City, NV 89706 775-886-6477 | www.matriplex.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message