int is_bigendian() { static int i=1; return (int)(*(char *)&i); }

Oh heck, go all the way:
From: Marc W. Mengel [[EMAIL PROTECTED]]
Sent: Tuesday, March 16, 1999 4:25 PM
To: xxxx
Subject: From the dim-and-musty department


Someone wanted this a while back, and I had occasion to find it and touch
it up a bit recently to handle 64-bit stuff.  I'm actually not sure if
I have the pdp-endian right anymore, so if anyone still has one around :-)

- - - - - - - - - - - - - cut here - - - - - - - - - - - - - - - - - 
#include <stdio.h>

/* 
 * note the apparently unneccesary nested switch statements -- this
 * is to prevent "duplicate case in switch" errors on small-word machines.."
 */

void
printbyteorder() {
  int i;
  long l;

  i = *((int *)"01234567");
  l = *((long *)"01234567");
  switch ((long)i) {
    case 0x00010203L:       printf("int 32bit-big-endian\n");break;
    case 0x03020100L:       printf("int 32bit-little-endian\n");break;
    case 0x30313233L:       printf("int 32bit-big-endian\n");   break;
    case 0x33323130L:       printf("int 32bit-little-endian\n");break;
    case 0x32333031L:       printf("int 32bit-pdp-ian\n");  break;
    default: 
      switch((long)i){
    case 0x3031323334353637L:printf("int 64bit-big-endian\n");break;
    case 0x3736353433323130L:printf("int 64bit-little-endian\n");break;
    default:            printf("int bizarre %x-order", i);  break;
      }
      break;
  }
  switch (l) {
    case 0x00010203L:       printf("long 32bit-big-endian\n");break;
    case 0x03020100L:       printf("long 32bit-little-endian\n");break;
    case 0x30313233L:       printf("long 32bit-big-endian\n");  break;
    case 0x33323130L:       printf("long 32bit-little-endian\n");break;
    case 0x32333031L:       printf("long 32bit-pdp-ian\n"); break;
    default: 
      switch(l){
    case 0x3031323334353637L:printf("int 64bit-big-endian\n");break;
    case 0x3736353433323130L:printf("int 64bit-little-endian\n");break;
    default:            printf("int bizarre %x-order", l);break;
      }
      break;
  }
}

main(){
  printbyteorder();
}

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to