]> www.ginac.de Git - cln.git/blobdiff - autoconf/intparam.c
* Add table of contents in TeX output.
[cln.git] / autoconf / intparam.c
index eb2ae97b4da64af17a854eb1e70d7139eadd2c7c..8879c4d669a0c3a0ad7dd30bdb596c028d1afd71 100644 (file)
@@ -1,11 +1,11 @@
 #line 1 "intparam.d"
-/* Bestimmung einiger Maschinen-Parameter und -Abhängigkeiten */
+/* Bestimmung einiger Maschinen-Parameter und -Abhgigkeiten */
 /* und Ausgabe in ein Include-File */
 /* Bruno Haible 10.9.1991, 12.10.1992, 6.12.1992, 24.10.1993 */
 
 /* Auf einigen Systemen werden in <sys/types.h> die Typen uchar, ushort, uint, */
 /* ulong definiert. Normalerweise reicht _POSIX_SOURCE aus, dies zu verhindern, */
-/* bei AIX 3.2.5 (rs6000-ibm-aix3.2.5) jedoch nicht. Wir müssen Gewalt anwenden. */
+/* bei AIX 3.2.5 (rs6000-ibm-aix3.2.5) jedoch nicht. Wir mssen Gewalt anwenden. */
 #define _POSIX_SOURCE
 #define uchar  os_uchar
 #define ushort os_ushort
@@ -43,7 +43,7 @@ typedef unsigned long long  ulonglong;
 #endif
 typedef int (function)();
 
-static int random_table[256] = /* 2048 zufällige Bits, hier von pi */
+static int random_table[256] = /* 2048 zuflige Bits, hier von pi */
   { 0xC9,0x0F,0xDA,0xA2,0x21,0x68,0xC2,0x34,0xC4,0xC6,0x62,0x8B,
     0x80,0xDC,0x1C,0xD1,0x29,0x02,0x4E,0x08,0x8A,0x67,0xCC,0x74,
     0x02,0x0B,0xBE,0xA6,0x3B,0x13,0x9B,0x22,0x51,0x4A,0x08,0x79,
@@ -108,16 +108,32 @@ static boolean longlong_ulonglong_same;
 #endif
 
 void main1(void) {
-#define get_integer_bitsize(type,where)  \
-  { type x = 1;                                 \
-    int bits = 0;                               \
-    loop                                        \
-      { if (x==0) break;                        \
-        x = x+x;                                \
-        bits++;                                 \
-        if (bits==1000) { bits = -1; break; }   \
-      }                                         \
-    where = bits;                               \
+#define get_unsigned_integer_bitsize(type,where)  \
+  { type x = 1;                               \
+    int bits = 0;                             \
+    loop {                                    \
+      if (x==0) break;                        \
+      x = x+x;                                \
+      bits++;                                 \
+      if (bits==1000) { bits = -1; break; }   \
+    }                                         \
+    where = bits;                             \
+  }
+#define get_signed_integer_bitsize(type,unsigned_type,where)  \
+  { /* Signed integer overflow is "undefined behaviour" in C99, and gcc-4.3    \
+       (without -fwrapv option) actually does weird things when signed integer \
+       overflow occurs. Therefore perform the addition on the unsigned type.   \
+       Drawback: This will not detect cases where the signed type has more bits\
+       than the unsigned type but the same size according to sizeof. Blech. */ \
+    type x = 1;                               \
+    int bits = 0;                             \
+    loop {                                    \
+      if (x==0) break;                        \
+      x = (unsigned_type)x + (unsigned_type)x;\
+      bits++;                                 \
+      if (bits==1000) { bits = -1; break; }   \
+    }                                         \
+    where = bits;                             \
   }
 #define print_integer_bitsize(type,typestr,where)  \
   { if (where >= 0)                                                  \
@@ -131,28 +147,28 @@ void main1(void) {
     if (!(where == char_bitsize * sizeof(type)))                     \
       { printf("#error \"Formula BITSIZE(T) = SIZEOF(T) * BITSPERBYTE does not hold for t%spe %s!!\"\n","y",typestr); } \
   }
-  get_integer_bitsize(schar,char_bitsize);
-  get_integer_bitsize(short,short_bitsize);
-  get_integer_bitsize(int,int_bitsize);
-  get_integer_bitsize(long,long_bitsize);
+  get_signed_integer_bitsize(schar,uchar,char_bitsize);
+  get_signed_integer_bitsize(short,ushort,short_bitsize);
+  get_signed_integer_bitsize(int,uint,int_bitsize);
+  get_signed_integer_bitsize(long,ulong,long_bitsize);
   print_integer_bitsize(schar,"char",char_bitsize);
   print_integer_bitsize(short,"short",short_bitsize);
   print_integer_bitsize(int,"int",int_bitsize);
   print_integer_bitsize(long,"long",long_bitsize);
 #ifdef HAVE_LONGLONG
-  get_integer_bitsize(longlong,longlong_bitsize);
+  get_signed_integer_bitsize(longlong,ulonglong,longlong_bitsize);
   print_integer_bitsize(longlong,"long long",longlong_bitsize);
 #endif
-  get_integer_bitsize(uchar,uchar_bitsize);
-  get_integer_bitsize(ushort,ushort_bitsize);
-  get_integer_bitsize(uint,uint_bitsize);
-  get_integer_bitsize(ulong,ulong_bitsize);
+  get_unsigned_integer_bitsize(uchar,uchar_bitsize);
+  get_unsigned_integer_bitsize(ushort,ushort_bitsize);
+  get_unsigned_integer_bitsize(uint,uint_bitsize);
+  get_unsigned_integer_bitsize(ulong,ulong_bitsize);
   print_integer_bitsize(uchar,"unsigned char",uchar_bitsize);
   print_integer_bitsize(ushort,"unsigned short",ushort_bitsize);
   print_integer_bitsize(uint,"unsigned int",uint_bitsize);
   print_integer_bitsize(ulong,"unsigned long",ulong_bitsize);
 #ifdef HAVE_LONGLONG
-  get_integer_bitsize(ulonglong,ulonglong_bitsize);
+  get_unsigned_integer_bitsize(ulonglong,ulonglong_bitsize);
   print_integer_bitsize(ulonglong,"unsigned long long",ulonglong_bitsize);
 #endif
 }
@@ -347,7 +363,7 @@ void main5(void) {
       if (!sign_extends && !zero_extends)                                                                  \
         printf("#error \"Casts from %s to %s works in an unknown manner!!\"\n",typestr1,typestr2);         \
     }
-  /* erst Casts zwischen Integers vermutlich gleicher Größe: */
+  /* erst Casts zwischen Integers vermutlich gleicher Gre: */
   test_integer_casts(schar,uchar,"char","unsigned char",char_bitsize,uchar_bitsize,0);
   test_integer_casts(short,ushort,"short","unsigned short",short_bitsize,ushort_bitsize,0);
   test_integer_casts(int,uint,"int","unsigned int",int_bitsize,uint_bitsize,0);
@@ -360,7 +376,7 @@ void main5(void) {
   test_integer_casts(longlong,ulonglong,"long long","unsigned long long",longlong_bitsize,ulonglong_bitsize,0);
   test_integer_casts(ulonglong,longlong,"unsigned long long","long long",ulonglong_bitsize,longlong_bitsize,0);
 #endif
-  /* dann Casts zwischen Integers unterschiedlicher Größe, aber gleichen Vorzeichens: */
+  /* dann Casts zwischen Integers unterschiedlicher Gre, aber gleichen Vorzeichens: */
   test_integer_casts(uchar,ushort,"unsigned char","unsigned short",uchar_bitsize,ushort_bitsize,1);
   test_integer_casts(uchar,uint,"unsigned char","unsigned int",uchar_bitsize,uint_bitsize,1);
   test_integer_casts(uchar,ulong,"unsigned char","unsigned long",uchar_bitsize,ulong_bitsize,1);
@@ -385,7 +401,7 @@ void main5(void) {
   test_integer_casts(int,longlong,"int","long long",int_bitsize,longlong_bitsize,2);
   test_integer_casts(long,longlong,"long","long long",long_bitsize,longlong_bitsize,2);
 #endif
-  /* dann Casts zwischen Integers unterschiedlicher Größe und unterschiedlichen Vorzeichens: */
+  /* dann Casts zwischen Integers unterschiedlicher Gre und unterschiedlichen Vorzeichens: */
   test_integer_casts(uchar,short,"unsigned char","short",uchar_bitsize,short_bitsize,1);
   test_integer_casts(uchar,int,"unsigned char","int",uchar_bitsize,int_bitsize,1);
   test_integer_casts(uchar,long,"unsigned char","long",uchar_bitsize,long_bitsize,1);
@@ -578,11 +594,6 @@ int main()
   main8();
   main9();
   main10();
-#if defined(__cplusplus)
   if (ferror(stdout)) return 1;
   return 0;
-#else
-  if (ferror(stdout)) { exit(1); }
-  exit(0);
-#endif
 }