From 65dc5d6519c9f5ff39ca02c9f7bb152e19aa08f7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 8 May 2011 12:28:01 -0700 Subject: [PATCH] intprops: Sun C 5.11 supports __typeof__ * lib/intprops.h (_GL_HAVE___TYPEOF__): New macro, which is set for either GCC 2 or later, as before, or for Sun C 5.11 or later, which is new. (_GL_SIGNED_TYPE_OR_EXPR): Use it. --- ChangeLog | 7 +++++++ lib/intprops.h | 24 +++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14772504b6..42bcff3b55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,15 @@ 2011-05-08 Paul Eggert + intprops: Sun C 5.11 supports __typeof__ + * lib/intprops.h (_GL_HAVE___TYPEOF__): New macro, which is set + for either GCC 2 or later, as before, or for Sun C 5.11 or later, + which is new. + (_GL_SIGNED_TYPE_OR_EXPR): Use it. + intprops: switch to usual gnulib indenting and naming * lib/intprops.h (_GL_INTPROPS_H): Rename from GL_INTPROPS_H. (_GL_SIGNED_TYPE_OR_EXPR): Rename from signed_type_or_expr__. + * tests/test-inttostr.c (IS_TIGHT): Adjust to above renaming. 2011-05-08 Jim Meyering diff --git a/lib/intprops.h b/lib/intprops.h index a654333941..529b0fa89a 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -55,12 +55,18 @@ ? (t) -1 \ : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1))) -/* Return zero if T can be determined to be an unsigned type. - Otherwise, return 1. - When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a - tighter bound. Otherwise, it overestimates the true bound by one byte - when applied to unsigned types of size 2, 4, 16, ... bytes. */ -#if __GNUC__ >= 2 +/* Return 1 if the __typeof__ keyword works. This could be done by + 'configure', but for now it's easier to do it by hand. */ +#if 2 <= __GNUC__ || 0x5110 <= __SUNPRO_C +# define _GL_HAVE___TYPEOF__ 1 +#else +# define _GL_HAVE___TYPEOF__ 0 +#endif + +/* Return 1 if the integer type or expression T might be signed. Return 0 + if it is definitely unsigned. This macro does not evaluate its argument, + and expands to an integer constant expression. */ +#if _GL_HAVE___TYPEOF__ # define _GL_SIGNED_TYPE_OR_EXPR(t) TYPE_SIGNED (__typeof__ (t)) #else # define _GL_SIGNED_TYPE_OR_EXPR(t) 1 @@ -73,7 +79,11 @@ /* Bound on length of the string representing an integer type or expression T. Subtract 1 for the sign bit if T is signed, and then add 1 more for - a minus sign if needed. */ + a minus sign if needed. + + Because _GL_SIGNED_TYPE_OR_EXPR sometimes returns 0 when its argument is + signed, this macro may overestimate the true bound by one byte when + applied to unsigned types of size 2, 4, 16, ... bytes. */ #define INT_STRLEN_BOUND(t) \ (INT_BITS_STRLEN_BOUND (sizeof (t) * CHAR_BIT \ - _GL_SIGNED_TYPE_OR_EXPR (t)) \ -- 2.30.2