This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: autoconf for type sizes


On Mon, Mar 12, 2001 at 03:38:17PM -0500, Kaveh R. Ghazi wrote:
> Zack, looks good.  Some comments:
> 
> 1.  (Optional) is the gcc_AC_C_CHAR_BIT test necessary?  Why not just
>     default to 8 if it doesn't appear in limits.h?  I notice that
>     gcc/glimits.h unconditionally sets it to 8 anyway, so its unlikely
>     that we'll encounter a *host* which sets it to a different value.

I don't personally think it's necessary - the PDP-10 port should have
a sane system limits.h.  (We will have to do something about
glimits.h.)

I suppose the question is whether there ever was a K+R C
implementation on a machine with 9- or 7-bit bytes.

> 3.  (More serious) regarding:
> 
>  > #ifdef HAVE_LONG_LONG
>  > #define HOST_BITS_PER_LONGLONG (CHAR_BIT * SIZEOF_LONG_LONG)
>  > #endif
> 
> I think that this will fail when using a K&R stage1 bootstrap cc and
> leave HOST_BITS_PER_LONGLONG undefined.  That it turn leaves
> HOST_WIDEST_INT undefined, which renders cpp uncompilable.  You should
> add a #else #define HOST_BITS_PER_LONGLONG 64 clause to handle older
> compilers.

Feh, you're right.  What do you think of this patch for hwint.h
instead?

zw

===================================================================
Index: hwint.h
--- hwint.h	2001/03/06 14:32:57	1.5
+++ hwint.h	2001/03/13 04:11:17
@@ -9,24 +9,21 @@
 #ifndef __HWINT_H__
 #define __HWINT_H__
 
-/* This describes the machine the compiler is hosted on.  The defaults
-   we provide describe the standard 32 bit host since that is the most
-   common type supported in gcc.  */
-#ifndef HOST_BITS_PER_CHAR
-# define HOST_BITS_PER_CHAR 8
-#endif
-#ifndef HOST_BITS_PER_SHORT
-# define HOST_BITS_PER_SHORT 16
-#endif
-#ifndef HOST_BITS_PER_INT
-# define HOST_BITS_PER_INT 32
-#endif
-#ifndef HOST_BITS_PER_LONG
-# define HOST_BITS_PER_LONG 32
-#endif
-#ifndef HOST_BITS_PER_LONGLONG
-# define HOST_BITS_PER_LONGLONG 64
-#endif
+/* This describes the machine the compiler is hosted on.  */
+#define HOST_BITS_PER_CHAR  CHAR_BIT
+#define HOST_BITS_PER_SHORT (CHAR_BIT * SIZEOF_SHORT)
+#define HOST_BITS_PER_INT   (CHAR_BIT * SIZEOF_INT)
+#define HOST_BITS_PER_LONG  (CHAR_BIT * SIZEOF_LONG)
+
+#ifdef HAVE_LONG_LONG
+# define HOST_BITS_PER_LONGLONG (CHAR_BIT * SIZEOF_LONG_LONG)
+#else
+/* If we're here and we're GCC, assume this is stage 2+ of a bootstrap
+   and 'long long' has the width of the *target*'s long long.  */
+# if GCC_VERSION > 3000
+#  define HOST_BITS_PER_LONGLONG LONG_LONG_TYPE_SIZE
+# endif /* gcc */
+#endif /* no long long */
 
 /* Find the largest host integer type and set its size and type.  */
 
@@ -42,7 +39,6 @@
 
 #endif /* ! HOST_BITS_PER_WIDE_INT */
 
-
 /* Provide defaults for the way to print a HOST_WIDE_INT
    in various manners.  */
 
@@ -105,5 +101,26 @@
 #  endif
 # endif
 #endif /* ! HOST_WIDE_INT_PRINT_DOUBLE_HEX */
+
+/* Find HOST_WIDEST_INT and set its bit size, type and print macros.
+   It will be the largest integer mode supported by the host which may
+   (or may not) be larger than HOST_WIDE_INT.  */
+
+#ifndef HOST_WIDEST_INT
+#if defined HOST_BITS_PER_LONGLONG \
+    && HOST_BITS_PER_LONGLONG > HOST_BITS_PER_LONG
+#   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONGLONG
+#   define HOST_WIDEST_INT long long
+#   define HOST_WIDEST_INT_PRINT_DEC "%lld"
+#   define HOST_WIDEST_INT_PRINT_UNSIGNED "%llu"
+#   define HOST_WIDEST_INT_PRINT_HEX "0x%llx"
+#  else
+#   define HOST_BITS_PER_WIDEST_INT HOST_BITS_PER_LONG
+#   define HOST_WIDEST_INT long
+#   define HOST_WIDEST_INT_PRINT_DEC "%ld"
+#   define HOST_WIDEST_INT_PRINT_UNSIGNED "%lu"
+#   define HOST_WIDEST_INT_PRINT_HEX "0x%lx"
+# endif /* long long wider than long */
+#endif /* ! HOST_WIDEST_INT */
 
 #endif /* __HWINT_H__ */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]