Karim BELABAS on Wed, 2 Oct 2002 20:21:31 +0200 (MEST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: functions returning int with 'l' protocodes.


On Tue, 10 Sep 2002, Bill Allombert wrote:
> Comparison functions usually return an `int' not a `long'.
> This is correct since they always returns 0, 1 or -1.
>
> However some of them are available from GP, but there is
> not protoype letter for int, so we use l instead.
>
> But this is wrong, since on 64bit mechines, int is 32 bit and
> long 64bit.
>
> On ia64 PARI compiled with gcc -g (for all versions) do not pass
> the bench, because in some cases, (int) -1 became (long) 2^32-1,
> which is correct, since we have hid the cast from the compiler.
>
> FIx involves either add a new letter code for integers, or
> `upgrade' all functions return int to long.
> The second option seems better.

Why not tell the compiler about the cast ?

I.e, does the following patch fix the problem ?

Index: src/language/anal.c
===================================================================
RCS file: /home/megrez/cvsroot/pari/src/language/anal.c,v
retrieving revision 1.116
diff -u -b -r1.116 anal.c
--- src/language/anal.c 2002/09/15 15:43:45     1.116
+++ src/language/anal.c 2002/10/02 18:19:54
@@ -1947,7 +1947,7 @@
        break;

       case RET_INT:
-       m = ((long (*)(ANYARG))call)(_ARGS_);
+       m = (long) ((long (*)(ANYARG))call)(_ARGS_);
        res = stoi(m); break;

       case RET_VOID:

    Karim.
-- 
Karim Belabas                    Tel: (+33) (0)1 69 15 57 48
Dép. de Mathematiques, Bat. 425  Fax: (+33) (0)1 69 15 60 19
Université Paris-Sud             Email: Karim.Belabas@math.u-psud.fr
F-91405 Orsay (France)           http://www.math.u-psud.fr/~belabas/
--
PARI/GP Home Page: http://www.parigp-home.de/