[m-rev.] for review: Fix how large negative integers are written for C89.

Peter Wang novalazy at gmail.com
Thu Sep 3 13:57:28 AEST 2015


On Thu, 3 Sep 2015 12:12:35 +1000 (AEST), Julien Fischer <jfischer at opturion.com> wrote:
> 
> Hi Peter,
> 
> On Wed, 2 Sep 2015, Peter Wang wrote:
> 
> > C does not have negative integer constants so "(MR_Integer) -nnnn"
> > is the negation of a positive integer constant nnnn, converted to
> > MR_Integer.
> >
> > In C89/C90 an unsuffixed decimal integer constant must be typed
> > `int' or `long int' or `unsigned long int', whichever fits first.
> > The negated result will have the same type. If nnnn > LONG_MAX then
> > it will be typed `unsigned long int'. If MR_Integer is wider than
> > `unsigned long int' then the conversion to MR_Integer yields a positive
> > value, not negative.
> >
> > The solution here is essentially to write "-(MR_Integer) nnnn" so the
> > integer constant is converted to a signed MR_Integer before negation.
> 
> This diff presumably shuts up the warnings we occasionally get from GCC.
> It's probably worth mentioning that in the log message.

Done.

> > +
> > +    ( N >= -2147483647 ->
> > +        % Write integers >= -LONG_MAX in the most readable way.
> > +        % This is the minimum magnitude of LONG_MAX in C.
> 
> I would reword that comment to refer to the constant INT32_MAX rather
> than LONG_MAX, since that avoids the need for asides about the minimum
> magnitude of LONG_MAX etc.

The important part is not exceeding LONG_MAX.  I've changed it to:

    % Write integers in the most readable way as long as the absolute value
    % does not exceed LONG_MAX, otherwise it may be typed `unsigned long'.

Peter



More information about the reviews mailing list