Paul Eggert wrote:
> Also, while we're on the subject of size_max.m4, I have a pedantic
> point: its use of ~(size_t)0 isn't portable in general.  For example,
> if size_t is narrower than int, then ~(size_t)0 might evaluate to -1,
> which isn't correct.

Ah, right. I'm changing it to (size_t)~(size_t)0. Although I know that
(size_t)~0 and (size_t)-1 in theory yield the same value. I find it
more confusing to cast a negative number to an unsigned type, than to
use two casts.

2005-07-10  Bruno Haible  <[EMAIL PROTECTED]>

        * size_max.m4 (gl_SIZE_MAX): Cast ~(size_t)0 back to size_t.
        Needed when size_t is smaller than 'unsigned int'.
        Reported by Paul Eggert.

*** size_max.m4.bak     2005-01-18 13:58:29.000000000 +0100
--- size_max.m4 2005-07-10 14:58:24.000000000 +0200
***************
*** 1,5 ****
! # size_max.m4 serial 2
! dnl Copyright (C) 2003 Free Software Foundation, Inc.
  dnl This file is free software; the Free Software Foundation
  dnl gives unlimited permission to copy and/or distribute it,
  dnl with or without modifications, as long as this notice is preserved.
--- 1,5 ----
! # size_max.m4 serial 3
! dnl Copyright (C) 2003, 2005 Free Software Foundation, Inc.
  dnl This file is free software; the Free Software Foundation
  dnl gives unlimited permission to copy and/or distribute it,
  dnl with or without modifications, as long as this notice is preserved.
***************
*** 26,34 ****
      dnl than the type 'unsigned long'.
      dnl The _AC_COMPUTE_INT macro works up to LONG_MAX, since it uses 'expr',
      dnl which is guaranteed to work from LONG_MIN to LONG_MAX.
!     _AC_COMPUTE_INT([~(size_t)0 / 10], res_hi,
        [#include <stddef.h>], result=?)
!     _AC_COMPUTE_INT([~(size_t)0 % 10], res_lo,
        [#include <stddef.h>], result=?)
      _AC_COMPUTE_INT([sizeof (size_t) <= sizeof (unsigned int)], fits_in_uint,
        [#include <stddef.h>], result=?)
--- 26,34 ----
      dnl than the type 'unsigned long'.
      dnl The _AC_COMPUTE_INT macro works up to LONG_MAX, since it uses 'expr',
      dnl which is guaranteed to work from LONG_MIN to LONG_MAX.
!     _AC_COMPUTE_INT([(size_t)~(size_t)0 / 10], res_hi,
        [#include <stddef.h>], result=?)
!     _AC_COMPUTE_INT([(size_t)~(size_t)0 % 10], res_lo,
        [#include <stddef.h>], result=?)
      _AC_COMPUTE_INT([sizeof (size_t) <= sizeof (unsigned int)], fits_in_uint,
        [#include <stddef.h>], result=?)
***************
*** 48,54 ****
        fi
      else
        dnl Shouldn't happen, but who knows...
!       result='~(size_t)0'
      fi
    fi
    AC_MSG_RESULT([$result])
--- 48,54 ----
        fi
      else
        dnl Shouldn't happen, but who knows...
!       result='((size_t)~(size_t)0)'
      fi
    fi
    AC_MSG_RESULT([$result])



_______________________________________________
bug-gnulib mailing list
bug-gnulib@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-gnulib

Reply via email to