On Fri, Jan 14, 2011 at 8:08 PM, Benny Lofgren <bl-li...@lofgren.biz> wrote:
> + Makes it 64-bit capable on both 32- and 64-bit architectures by changing
> relevant int:s to int64_t:s. I often use expr as a quick calculator for
> example when partitioning disks and such, and frequently find myself up
> against the 32 bit signed integer limits.
...
> - Have no idea about POSIX compliance, but would be very surprised if they
> specified 32-bit values only.

In my opinion, the requirement that POSIX states is not violated by this.

(The precise requirement can be found in section 1.1.2.1 of the XCU
section of POSIX 2008, where it says:
        Integer variables and constants, including the values of operands and
        option-arguments, used by the standard utilities listed in this
volume
        of POSIX.1-2008 shall be implemented as equivalent to the ISO C
        standard signed long data type; <...>

...but I don't see a requirement for the compilation environment used
by the standard utilities to match any of the provided environments,
so as long as its a signed arithmetic with at least 31value bits (to
meet the ISO C requirements for "signed long"), it would appear to
comply.)

> Index: expr.c
> ===================================================================
> RCS file: /cvs/src/bin/expr/expr.c,v
> retrieving revision 1.17
> diff -u -r1.17 expr.c

If you're going to email diffs, you MUST turn off 'format=flowed', as
Thunderbird munged the whitespace on your diffs enough to make them
break with "patch -l".  Thunderbird has an option for that; find it
and use it.

...
> -is_integer(struct val *vp, int *r)
> +is_integer(struct val *vp, int64_t *r)
>  {
>        char           *s;
> -       int             neg;
> -       int             i;
> +       int64_t         neg;
> +       int64_t         i;

You make 'neg' int64_t why?


...
> @@ -509,7 +509,7 @@
>        }
>
>        if (vp->type == integer)
> -               printf("%d\n", vp->u.i);
> +               printf("%ld\n", vp->u.i);

My crystal ball says you use amd64 platform and not i386, as the above
works on LP64 and fails on ILP32LL64.  The format string should be
"%lld\n".  Related: try this with your version:

expr 42949673000 : '.*'

Your diff will have that return 2, when the correct answer is 11: the
format string in the asprintf() call in to_string() needs to be
updated:

-       if (asprintf(&tmp, "%d", vp->u.i) == -1)
+       if (asprintf(&tmp, "%lld", vp->u.i) == -1)


Philip Guenther

Reply via email to