stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r373017 - /incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp
Date Fri, 27 Jan 2006 22:49:38 GMT
Author: sebor
Date: Fri Jan 27 14:49:34 2006
New Revision: 373017

URL: http://svn.apache.org/viewcvs?rev=373017&view=rev
Log:
2006-01-27  Martin Sebor  <sebor@roguewave.com>

	* LIMITS.cpp: Determined whether the architecture uses one's or two's
	complement integer representation and adjusted the values of integral
	limits correspondingly. Lined up output for better readability.


Modified:
    incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp

Modified: incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp?rev=373017&r1=373016&r2=373017&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp Fri Jan 27 14:49:34 2006
@@ -20,6 +20,7 @@
 
      // prevent the propriterary gcc __extension__ from
      // throwing the vanilla EDG demo for a loop
+
 #    undef LDBL_EPSILON
 #    undef LDBL_MIN
 #    undef LDBL_MAX
@@ -102,6 +103,10 @@
 #endif   // _RWSTD_NO_HONOR_STD
 
 
+// set to 1 if this is not a two's complement architecture
+int no_twos_complement = 0;
+
+
 template<class T>
 void print_limit (T n, const char *pfx, const char *sfx,
                   bool is_max, const char *type)
@@ -143,20 +148,31 @@
         *--pnstr = '0';
     }
 
+    char macro_name [64];
+    char macro_value [64];
+
     if (is_max) {
-        printf ("#define _RWSTD_%s_MAX %s%s", pfx, pnstr, sfx);
+        sprintf (macro_name, "_RWSTD_%s_MAX", pfx);
+        sprintf (macro_value, "%s%s", pnstr, sfx);
+
     }
     else {
+        sprintf (macro_name, "_RWSTD_%s_MIN ", pfx);
+
         if (n < zero) {
-            printf ("#define _RWSTD_%s_MIN (-_RWSTD_%s_MAX - 1%s)",
-                    pfx, pfx, sfx);
+            if (no_twos_complement) {
+                sprintf (macro_value, "-_RWSTD_%s_MAX", pfx);
+            }
+            else {
+                sprintf (macro_value, "(-_RWSTD_%s_MAX - 1%s)", pfx, sfx);
+            }
         }
         else {
-            printf ("#define _RWSTD_%s_MIN %s%s", pfx, pnstr, sfx);
+            sprintf (macro_value, "%s%s", pnstr, sfx);
         }
     }
 
-    printf ("\n");
+    printf ("#define %-18s %s\n", macro_name, macro_value);
 }
 
 
@@ -275,7 +291,7 @@
 
     for (unsigned char c = '\01'; c; c <<= 1, ++bits);
 
-    printf ("#define _RWSTD_CHAR_BIT %u\n", bits);
+    printf ("#define _RWSTD_CHAR_BIT    %u\n", bits);
 
     return bits;
 }
@@ -313,6 +329,12 @@
 #define SIZEOF(T)   unsigned (sizeof (T))
 
 
+volatile int zero = 0;
+volatile int one  = zero + 1;
+volatile int two  = one + 1;
+volatile int zero_complement = ~zero;
+
+
 int main ()
 {
 #if !defined (_RWSTD_USE_CONFIG)
@@ -321,6 +343,11 @@
 
 #endif   // _RWSTD_USE_CONFIG
 
+    // determine whether this is a two's complement architecture
+    // and set the no_twos_complement global variable to 1 if not
+    if (two + zero_complement != one)
+        no_twos_complement = 1;
+
     // compute sizes of fundamental types
 
 #ifndef _RWSTD_NO_BOOL
@@ -366,10 +393,17 @@
 
 #ifndef _RWSTD_NO_BOOL
 
-    printf ("#define _RWSTD_BOOL_MIN !!0\n");
-    printf ("#define _RWSTD_BOOL_MAX !0\n");
+    printf ("#define _RWSTD_BOOL_MIN    !!0\n");
+    printf ("#define _RWSTD_BOOL_MAX    !0\n");
 
 #endif   // _RWSTD_NO_BOOL
+
+    if (0 == no_twos_complement) {
+        // comment out the next #define (this is two's complement
+        // architecture)
+        printf ("%s", "// ");
+    }
+    printf ("#define _RWSTD_NO_TWOS_COMPLEMENT\n");
 
     compute_limits ((char)0, "CHAR", "", "char");
     compute_limits ((signed char)0, "SCHAR", "", "signed char");



Mime
View raw message