Nuova figura e correzioni di Francesco Poli riguardo l'endianess
[gapil.git] / sources / endian.c
diff --git a/sources/endian.c b/sources/endian.c
new file mode 100644 (file)
index 0000000..1e71896
--- /dev/null
@@ -0,0 +1,50 @@
+/* endian.c
+ *
+ * Copyright (C) 2003 Simone Piccardi
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/***************************************************************
+ *
+ * routine endian: routine to detect endianess
+ *
+ * Author: S. Piccardi
+ * May. 2003
+ *
+ * $Id: endian.c,v 1.1 2003/06/01 21:41:28 piccardi Exp $
+ *
+ ***************************************************************/
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+/*
+ * Variables definition
+ */
+    int i, val;
+    char buf[sizeof(int)];
+    char * char_ptr;
+    int * int_ptr;
+   
+    val = 0xABCDEF01;      /* endianess magic number */
+    int_ptr = (int *) buf; 
+    *int_ptr = val;
+    char_ptr = (char *) &val;
+    for (i=0; i<sizeof(int); i++) {
+       char_ptr[i] = buf[i];
+    }
+    printf("Value %x\n", val);
+    return 0;
+}