>>  print *, -128_int8
> 
> This is a unary minus operator with an operand of 128.
> gfortran does not have negative integers.

To be clear, it’s not gfortran, it’s the standard(s). It’s not exactly true 
either, because there is a "signed-int-literal-constant” which is allowed in 
some contexts:

- as real part or imaginary part of a complex literal constant
- as a data-stmt-constant
- in some edit descriptors (DT and P control-edit-desc)

This is, for example, legal code (and handled by gfortran as expected):

  use iso_fortran_env
  implicit none
  integer(int8) :: j
  data j /-128_int8/
  print *, j
  end

On the other hand, in your code, -128_int8 cannot be a literal constant, 
because integer literal constants cannot have a sign in Fortran. As Steve said, 
“-128_int8” in this context in Fortran is the minus unary operator applied to 
the integer literal constant 128_int8.

We current output this:

    4 |   j = -128_int8
      |               1
Error: Integer too big for its kind at (1). This check can be disabled with the 
option '-fno-range-check’

I think the only better output we could give is to make it clear what the 
integer value is, either by underlining it (but we don’t have a framework to do 
that right now) or by outputting the value in the message (?).


Best,
FX



Reply via email to