Ilya Zakharevich on Fri, 18 Oct 2002 12:43:45 -0700

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

Re: functions returning int with 'l' protocodes.

On Thu, Oct 17, 2002 at 09:40:07PM +0200, Bill Allombert wrote:

> > Sorry, but I can't consider this objection seriously.  Certainly you
> > know how to convert a long to an int in C?  ;-)

> Yes I do. But there is still no functions to do it in GP.

[In PARI.  I find keeping the distinction very useful.]

...And there is no code-letter for integer argument anyway?  What is
your point?  When one adds support for the code-letter, one can the
function as well...

> > And all the error-handling is in
> >   if (l != (long)i)
> > 	err(....)

> Sorry I do not understand what you mean. Should not it be

>   long l=stoi(x);
> #ifdef LONG_IS_64BIT
>   if (l != (int)l)
>     err(talker,"integer too large in stoint");
> #endif

a) There is no need for define;

b) The #if is wrong (should be something like SIZEOF_LONG !=
   SIZEOF_INT), one can rewrite it without #if so that it is
   equivalent with -O;

c) I want to keep my C code free of details of type propagation etc.

   long l = stoi(x);
   int i = l;

   if (sizeof(long) != sizeof(int) && l != (long)i)
	err(talker,"integer too large in stoint");
   return i;

> OK that is not that hard to implement, but there is no need of it currently.

Of course there is.  People may use install() to communicate with
external libraries.

BTW, speaking of (c): I see that a lot of code in PARI is doing
isdigit((int)c) etc.  Apparently, this is to shut down the warning
"char used as index" from gcc.

This shuts down the warning, but not the condition which causes this
(legitimate!) warning.  IIUC, the correct fix should be

  isdigit((unsigned char)c);