On 2016-04-13 13:32:13 -0700, Kevin J. McCarthy wrote:
> Is casting a size_t to a (signed) implementation defined or undefined?

implementation defined

> Is it a problem to then divide that by an int and assign the result to
> an int?

Note that "signed" is just a synonymous for "int".

> Are we forced to write something like:
> 
>      /* try to consume as many columns as we can, if we don't have
>       * memory for that, use as much memory as possible */
>      if (wlen + (pad * pl) + len > destlen)
>        if (wlen + len > destlen)
>          pad = 0;
>        else
>          pad = (destlen - wlen - len) / pl;
>      else

You could write it:

  if (wlen + (pad * pl) + len > destlen)
    pad = wlen + len > destlen ? 0 : (destlen - wlen - len) / pl;
  else

to avoid the not so readable nested if's.

> > And the division with a negative argument is only defined in C99,
> > so that may be another problem (it is known that some compilers may
> > still deviate from C99, including GCC unless -std=c99 is provided).
> 
> Fortunately, we do have AC_PROG_CC_C99 in our configure.ac now.

So, division with negative arguments should be OK.

Note that instead of using the type size_t, you can probably use the
type long, to avoid the problem with the cast.

-- 
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

Reply via email to