Re: ibits order. Was: Hollerith constants on a little endian machine



In article <eomp3j$gum$1@xxxxxxxxxxxxxxxxxxxxxxx>,
Steven G. Kargl <kargl@xxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

Looks like a quality of implementation issue with those compilers
because they are silently converted from one integer kind type
to another and ignoring the out-of-range value.

Apologies! I thought I had written a program to test ibits, but
Steven found that I had written one to test a bad DATA statement.

Do these compiler silent compile the following:

integer i
i = huge(i) + 1
print *, i
end

When I asked for no compiler options, all four f95 compilers (g95,
Sun, NAG, Compaq) objected to line 2 at compile time. But that error
is easy for compilers to find because huge(i) + 1 is a constant. The
following program tests what happens with integer overflow in a way
that's impossible to detect at compile time, and all four compilers
compiled and ran it with no error messages (again, no compiler options
were asked for):

INTEGER:: input, itested, iloop
PRINT *, "Enter an integer e.g. 1"
READ *, input
itested = huge(input) - input
DO iloop = 1,3
itested = itested + 1
PRINT "(1X,SP,I0)", itested
END DO
END

The result was the same in all four cases with input 1 :

Enter an integer e.g. 1
1
+2147483647
-2147483648
-2147483647

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@xxxxxxxxx phone (+64)(4)463 5341 fax (+64)(4)463 5045
.