------- Comment #9 from kargl at gcc dot gnu dot org  2008-06-13 05:31 -------
(In reply to comment #8)
> So people don't understand that in Fortran types are symmetric?  Hasn't they
> been symmetric for 20 years now?  How can this be for latency programs 
> really? 
> Maybe gfortran is just the first compiler which enforces this :).

It's more complicated than the above.  The standard does not require
symmetry in the range of integers.  One can maintain (and I'll use
integer*1) that -128 is the minimum integer*1 value given the "model
number" representation for integer*1.  Unfortunately, the parser always
sees -128 as a unary minus and an operand of 128.  The 128 overflows the
range of [-128:127].

Here's where programmers run into problems:

  program a
  integer*1 i
  i = -128          ! Unary minus and overflow of 128
  i = - huge(i) - 1 ! (Almost) guaranteed to be legal given base 2.
  i = iabs(i)       ! THIS IS ILLEGAL Fortran.
  end program a

To allow the "i = -128" line of code, gfortran has introduced
the -fno-range-check option, and it lets the middle and back
end deal with possibly out of range values (ie, -129).

Note, you can force gfortran to use a symmetric range for the
integers with the -pedantic options.  From fortran/arith.c

      /* See PRs 13490 and 17912, related to integer ranges.
         The pedantic_min_int exists for range checking when a program
         is compiled with -pedantic, and reflects the belief that
         Standard Fortran requires integers to be symmetrical, i.e.
         every negative integer must have a representable positive
         absolute value, and vice versa.  */

      mpz_init (int_info->pedantic_min_int);
      mpz_neg (int_info->pedantic_min_int, int_info->huge);

I was involved in the discussion long ago, and I now think I may have
been wrong and the pedantic_min_int stuff should be removed.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36515

Reply via email to