Hi,

Resubmitting the first of my three changes to expr(1) for review.

To recap from my original mail:

+ 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.

+ No longer has the drawback of different semantics on 32/64-bit.

- 32 bit signed integer edge cases will instead be 64 bit signed integer edge cases. Hopefully not a problem. To my knowledge Solaris, Digital Unix/Tru64/whatever and others are also 64-bit capable.

- Have no idea about POSIX compliance, but would be very surprised if they specified 32-bit values only.


/Benny

----8<--------8<--------8<--------8<--------8<---- (cut)
Index: expr.c
===================================================================
RCS file: /cvs/src/bin/expr/expr.c,v
retrieving revision 1.17
diff -u -r1.17 expr.c
--- expr.c      21 Jun 2006 18:28:24 -0000      1.17
+++ expr.c      15 Jan 2011 03:37:40 -0000
@@ -14,11 +14,11 @@
 #include <regex.h>
 #include <err.h>

-struct val     *make_int(int);
+struct val     *make_int(int64_t);
 struct val     *make_str(char *);
 void            free_value(struct val *);
-int             is_integer(struct val *, int *);
-int             to_integer(struct val *);
+int             is_integer(struct val *, int64_t *);
+int64_t                 to_integer(struct val *);
 void            to_string(struct val *);
 int             is_zero_or_null(struct val *);
 void            nexttoken(int);
@@ -44,7 +44,7 @@

        union {
                char           *s;
-               int             i;
+               int64_t         i;
        } u;
 };

@@ -53,7 +53,7 @@
 char         **av;

 struct val *
-make_int(int i)
+make_int(int64_t i)
 {
        struct val     *vp;

@@ -92,11 +92,11 @@

 /* determine if vp is an integer; if so, return it's value in *r */
 int
-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;

        if (vp->type == integer) {
                *r = vp->u.i;
@@ -133,10 +133,10 @@


 /* coerce to vp to an integer */
-int
+int64_t
 to_integer(struct val *vp)
 {
-       int             r;
+       int64_t         r;

        if (vp->type == integer)
                return 1;
@@ -375,7 +375,7 @@
 {
        struct val     *l, *r;
        enum token      op;
-       int             v = 0, li, ri;
+       int64_t         v = 0, li, ri;

        l = eval3();
        while ((op = token) == EQ || op == NE || op == LT || op == GT ||
@@ -509,7 +509,7 @@
        }

        if (vp->type == integer)
-               printf("%d\n", vp->u.i);
+               printf("%ld\n", vp->u.i);
        else
                printf("%s\n", vp->u.s);
 ----8<--------8<--------8<--------8<---- (cut)

--
internetlabbet.se     / work:   +46 8 551 124 80      / "Words must
Benny Lvfgren        /  mobile: +46 70 718 11 90     /   be weighed,
                    /   fax:    +46 8 551 124 89    /    not counted."
                   /    email:  benny -at- internetlabbet.se

Reply via email to