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
.



Relevant Pages

  • Re: Comparision of C Sharp and C performance
    ...     double dif; ... compile time with runtime operations. ... you assume that all C compilers will do the constant division ... you don't evaluate an invariant in a for loop IF the preprocessor ...
    (comp.lang.c)
  • Re: Strange error msg.
    ... All good compilers have an array subscript bounds check ... to a single precision argument, ... easy to do with constants--pass 1.0 to a subroutine that ... the compiler to make a slew of compile time error checks. ...
    (comp.lang.fortran)
  • Illegal internal write?
    ... as that term is used in those Fortran standards? ... END PROGRAM testnoforall ... Five f95 compilers that I tried accepted the program at compile time. ...
    (comp.lang.fortran)
  • Breakem good and hard...
    ... will fail in as many different C compilers as possible, ... time or compile time. ...
    (comp.lang.c)
  • Re: Another C# critique (major rewrite!)
    ... >> In the case of a const implementation I'd prefer compile time ... >> validation for all languages though. ... > familiarize myself with compilers. ...
    (microsoft.public.dotnet.languages.csharp)