* Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants
@ 1996-12-17 5:00 Takashi Ichihara
1996-12-17 5:00 ` Steve Lionel
0 siblings, 1 reply; 7+ messages in thread
From: Takashi Ichihara @ 1996-12-17 5:00 UTC (permalink / raw)
Hi folks
I noticed recently that Digital fortran compiler has introduced
incompatibility to the previous DEC fortran compiler and and also
other vender's platforms.
Following is a sample test program to show this incompatibility.
c sample program: test3.for
integer*4 i4a,i4b,i4c
i4a= '120000'O
i4b= '120000'O / 2
i4c= '120000'O / int(2)
write(*,*) i4a,i4b,i4c
end
c
(A) Result using the following environment
o DEC Fortran V6.2-108 (VAX) on Open VMS VAX V6.1
o DEC Fortran V6.3-711 (AXP) on Open VMS AXP V6.2
o Digital Fortran 77 V7.0-6 on Open VMS AXP V6.2
o DEC Fortran V3.8-711 on OSF/1 3.2A
o HP FORTRAN 77 Ver: B.10.20
o IBM AIX XL Fortran Compiler Version 03.02.0002.0000
o IBM AIX XL Fortran Compiler Version 03.02.0004.0000
o Silicon Graphics Fortran 77 version 5.2
o Absoft FORTRAN 77 on Linux
o AND, MANY OTHER PLATFORMS
$run test3
40960 20480 20480
I think this result is normal.
(B) result using the following environment (most recent Digital Fortran)
o DEC Fortran V6.3-155 (VAX) on Open VMS V6.2 VAX,
o Digital Fortran V6.4-165 (VAX) on Open VMS V6.2 VAX,
o AND, ALL FUTURE RELEASE OF DIGITAL FORTRAN (as DEC told us...)
$run tes3
40960 -12288 20480
-----------------------------------------------------------------------
Local DEC support center told us that DEC has changed the
specification of the Fortran Compiler with the release of DEC
Fortran VAX V6.3 (as can be found "sys$help:FORT063.RELEASE_NOTES :
2.1.1.6 Sign Extension of Untyped Bit Constants" ) and hereafter all
the DEC fortman compiler (including AXP and VAX, VMS and UNIX) is
going to be resulted as (B).
I cannot believe why this silly change was introduced. This
change made a lot of confusion for the compatibility with the
previous DEC/VAX fortran. Also this change introduced serious
incompatibility with the other vender's fortran.
Takashi Ichihara
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants 1996-12-17 5:00 Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants Takashi Ichihara @ 1996-12-17 5:00 ` Steve Lionel 1996-12-18 5:00 ` Petrie L M 1996-12-18 5:00 ` John Hascall 0 siblings, 2 replies; 7+ messages in thread From: Steve Lionel @ 1996-12-17 5:00 UTC (permalink / raw) In article <1996Dec17.055242.11669@riksun.riken.go.jp>, ichihara@rikaxp.riken.go.jp (Takashi Ichihara) writes: |> Hi folks |> |> I noticed recently that Digital fortran compiler has introduced |>incompatibility to the previous DEC fortran compiler and and also |>other vender's platforms. |> |> Following is a sample test program to show this incompatibility. |> |>c sample program: test3.for |> integer*4 i4a,i4b,i4c |> i4a= '120000'O |> i4b= '120000'O / 2 |> i4c= '120000'O / int(2) |> write(*,*) i4a,i4b,i4c |> end |>c |> |>(A) Result using the following environment |> |> o DEC Fortran V6.2-108 (VAX) on Open VMS VAX V6.1 |> o DEC Fortran V6.3-711 (AXP) on Open VMS AXP V6.2 |> o Digital Fortran 77 V7.0-6 on Open VMS AXP V6.2 |> o DEC Fortran V3.8-711 on OSF/1 3.2A |> o HP FORTRAN 77 Ver: B.10.20 |> o IBM AIX XL Fortran Compiler Version 03.02.0002.0000 |> o IBM AIX XL Fortran Compiler Version 03.02.0004.0000 |> o Silicon Graphics Fortran 77 version 5.2 |> o Absoft FORTRAN 77 on Linux |> o AND, MANY OTHER PLATFORMS |> |>$run test3 |> |> 40960 20480 20480 |> |> I think this result is normal. |> |>(B) result using the following environment (most recent Digital Fortran) |> |> o DEC Fortran V6.3-155 (VAX) on Open VMS V6.2 VAX, |> o Digital Fortran V6.4-165 (VAX) on Open VMS V6.2 VAX, |> o AND, ALL FUTURE RELEASE OF DIGITAL FORTRAN (as DEC told us...) |> |>$run tes3 |> |> 40960 -12288 20480 |> |>----------------------------------------------------------------------- |> |> Local DEC support center told us that DEC has changed the |>specification of the Fortran Compiler with the release of DEC |>Fortran VAX V6.3 (as can be found "sys$help:FORT063.RELEASE_NOTES : |>2.1.1.6 Sign Extension of Untyped Bit Constants" ) and hereafter all |>the DEC fortman compiler (including AXP and VAX, VMS and UNIX) is |>going to be resulted as (B). |> |> I cannot believe why this silly change was introduced. This |>change made a lot of confusion for the compatibility with the |>previous DEC/VAX fortran. Also this change introduced serious |>incompatibility with the other vender's fortran. We considered the older behavior to be incorrect, but we admit that it relies on a lot of not-well-specified behavior. What is the type of a bit constant? They're not in Fortran 77 at all, and are allowed in Fortran 90 only in initialization (DATA) expressions, so none of that is relevant. Here's what the Digital Fortran 77 Language Reference Manual has to say about bit constants: Bit constants have no data type until they are used. When used, they assume a data type based on their use. When the bit constant is used with a binary operator, including the assignment operator, the datatype of the constant is the data type of the other operand. The case in question concerns the expression: '120000'O / 2 What is its type? Well, what is the type of the constant 2? As has been implemented in Digital Fortran back to VAX-11 FORTRAN-IV-PLUS V1.0 in 1978, it's INTEGER*2: The value of an integer constant is normally INTEGER*2, INTEGER*4 or INTEGER*8 (Alpha only). If a value is within the INTEGER*2 range (-32768:32767 or 0:65535), it is treated as an INTEGER*2 value... Therefore, the bit constant assumes the type INTEGER*2. Since in this representation, the sign bit is on, the constant represents a negative value, and the division has a negative result (Fortran doesn't have unsigned arithmetic.) That negative result is then sign-extended to INTEGER*4 for the assignment. Amusingly, if the expression had been written instead as: '120000'O / '2'O this would be an INTEGER*4 expression because of the other rule that says if there is no other typed operand, INTEGER*4 is assumed. Now I'll be the first to admit that this "typing" of integer constants is not obvious, and it often gets us into trouble, but that's the documented behavior and we wanted to make sure that we were consistent. Other compilers might not have this notion of INTEGER*2 typing for small integer constants and would not run into this problem. But I maintain that the current VAX compiler behavior is reasonable and consistent with the documentation and behavior of the compiler in other areas for the past 19 years. Our Alpha Fortran 77 compiler does not currently do this - it treats the bit constant as a zero-extended INTEGER*4 (or perhaps INTEGER*8) value. To add to the confusion, our Fortran 90 compiler now honors the Fortran 90 integer constant typing rules which say that the constant 2 is "default integer", meaning INTEGER*4 (by default), so there you get the result you seem to expect. It's not clear yet whether or not we'll change the Alpha Fortran 77 compiler to match the VAX behavior - this is something we're still discussing. I'd certainly be interested in observations from others on the issue, keeping in mind our documented treatment of small integer constants. -- Steve Lionel mailto:lionel@quark.zko.dec.com Fortran Development http://www.digital.com/info/slionel.html Digital Equipment Corporation 110 Spit Brook Road, ZKO2-3/N30 Nashua, NH 03062-2698 "Free advice is worth every cent" For information on Digital Fortran, see http://www.digital.com/info/hpc/fortran/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants 1996-12-17 5:00 ` Steve Lionel @ 1996-12-18 5:00 ` Petrie L M 1996-12-18 5:00 ` Ron Shepard 1996-12-19 5:00 ` Steve Lionel 1996-12-18 5:00 ` John Hascall 1 sibling, 2 replies; 7+ messages in thread From: Petrie L M @ 1996-12-18 5:00 UTC (permalink / raw) Does this mean that on the VAX, if I call sub1 ( x, n, 1 ) ^ where sub1 is subroutine sub1 ( x, n, i ) dimension x(n) integer i ... end that "i" is going to be a number > 2**16? This doesn't seem reasonable to me, even if it is 18 year old behavior. -- Lester M. Petrie lmp@ornl.gov ORNL-CPED 423-574-5259 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants 1996-12-18 5:00 ` Petrie L M @ 1996-12-18 5:00 ` Ron Shepard 1996-12-19 5:00 ` Steve Lionel 1 sibling, 0 replies; 7+ messages in thread From: Ron Shepard @ 1996-12-18 5:00 UTC (permalink / raw) In article <5999tu$mn6@stc06.ctd.ornl.gov>, lmp@ornl.gov (Lester Petrie) wrote: >Does this mean that on the VAX, if I > > call sub1 ( x, n, 1 ) > ^ > >where sub1 is > > subroutine sub1 ( x, n, i ) > dimension x(n) > integer i > ... > end > >that "i" is going to be a number > 2**16? >This doesn't seem reasonable to me, even if it is >18 year old behavior. No, default integers on a VAX are INTEGER*4. I'm not sure where the INTEGER*2 value got into this discussion. Was there an implicit statement or something that I missed? $.02 -Ron Shepard ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants 1996-12-18 5:00 ` Petrie L M 1996-12-18 5:00 ` Ron Shepard @ 1996-12-19 5:00 ` Steve Lionel 1 sibling, 0 replies; 7+ messages in thread From: Steve Lionel @ 1996-12-19 5:00 UTC (permalink / raw) In article <5999tu$mn6@stc06.ctd.ornl.gov>, lmp@xncse1.orfs.ornl.gov (Petrie L M) writes: |>Does this mean that on the VAX, if I |> |> call sub1 ( x, n, 1 ) |> ^ |>where sub1 is |> |> subroutine sub1 ( x, n, i ) |> dimension x(n) |> integer i |> ... |> end |> |>that "i" is going to be a number > 2**16? |>This doesn't seem reasonable to me, even if it is |>18 year old behavior. No, it doesn't. The behavior I referred to explicitly relates to use of constants in an expression with a binary operator. In contexts such as an actual argument, the largest integer type is used. -- Steve Lionel mailto:lionel@quark.zko.dec.com Fortran Development http://www.digital.com/info/slionel.html Digital Equipment Corporation 110 Spit Brook Road, ZKO2-3/N30 Nashua, NH 03062-2698 "Free advice is worth every cent" For information on Digital Fortran, see http://www.digital.com/info/hpc/fortran/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants 1996-12-17 5:00 ` Steve Lionel 1996-12-18 5:00 ` Petrie L M @ 1996-12-18 5:00 ` John Hascall 1996-12-19 5:00 ` Steve Lionel 1 sibling, 1 reply; 7+ messages in thread From: John Hascall @ 1996-12-18 5:00 UTC (permalink / raw) Steve Lionel <lionel@quark.zko.dec.com> wrote: }In article <1996Dec17.055242.11669@riksun.riken.go.jp>, }|>c sample program: test3.for }|> integer*4 i4a,i4b,i4c }|> i4a= '120000'O }|> i4b= '120000'O / 2 }|> i4c= '120000'O / int(2) }|> write(*,*) i4a,i4b,i4c }|> end most systems give: }|> 40960 20480 20480 new dec f77 gives: }|> 40960 -12288 20480 }We considered the older behavior to be incorrect, but we admit that it relies }on a lot of not-well-specified behavior. [history on the type of bit constants] }The case in question concerns the expression: } '120000'O / 2 }What is its type? Well, what is the type of the constant 2? As has been }implemented in Digital Fortran back to VAX-11 FORTRAN-IV-PLUS V1.0 in 1978, }it's INTEGER*2: }Therefore, the bit constant assumes the type INTEGER*2. Since in this }representation, the sign bit is on, the constant represents a negative }value, and the division has a negative result (Fortran doesn't have }unsigned arithmetic.) That negative result is then sign-extended to }INTEGER*4 for the assignment. }Our Alpha Fortran 77 compiler does not currently do this - it treats the }bit constant as a zero-extended INTEGER*4 (or perhaps INTEGER*8) value. }To add to the confusion, our Fortran 90 compiler now honors the Fortran 90 }integer constant typing rules which say that the constant 2 is "default }integer", meaning INTEGER*4 (by default), so there you get the result you }seem to expect. It's not clear yet whether or not we'll change the }Alpha Fortran 77 compiler to match the VAX behavior - this is something }we're still discussing. I'd certainly be interested in observations from }others on the issue, keeping in mind our documented treatment of small }integer constants. It seems to me that the careful programmer would write: i4b= '00000120000'O / 2 if that is what they wanted rather than hoping that: i4b= '120000'O / 2 would be sign-extended the way they hoped. However, it isn't clear to me from the explanation above whether or not that would give the expected answer or not. Will the fact that "2" has a type of INTEGER*2 force '00000120000'O to be INTEGER*2 too? And if so, what about '10000120000'O? John -- John Hascall, Software Engr. Shut up, be happy. The conveniences you ISU Computation Center demanded are now mandatory. -Jello Biafra mailto:john@iastate.edu http://www.cc.iastate.edu/staff/systems/john/welcome.html <-- the usual crud ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants 1996-12-18 5:00 ` John Hascall @ 1996-12-19 5:00 ` Steve Lionel 0 siblings, 0 replies; 7+ messages in thread From: Steve Lionel @ 1996-12-19 5:00 UTC (permalink / raw) In article <599qk4$r0v@news.iastate.edu>, john@iastate.edu (John Hascall) writes: ||> |> It seems to me that the careful programmer would write: |> |> i4b= '00000120000'O / 2 |> |> if that is what they wanted rather than hoping that: |> |> i4b= '120000'O / 2 |> |> would be sign-extended the way they hoped. However, it |> isn't clear to me from the explanation above whether or |> not that would give the expected answer or not. Will |> the fact that "2" has a type of INTEGER*2 force |> '00000120000'O to be INTEGER*2 too? And if so, what about |> '10000120000'O? The leading zeroes will be ignored. The larger constant will get an error. Not very pretty... We've been discussing this issue among the Fortran engineering team, and we've concluded that the current VAX behavior isn't what we want. It will take me a while to determine just how it all ought to work without breaking programs that rely on the "small integer constant" behavior. Bit constants, in particular, should assume the largest integer type. The goal will be to match the Alpha compiler's behavior in this regard. -- Steve Lionel mailto:lionel@quark.zko.dec.com Fortran Development http://www.digital.com/info/slionel.html Digital Equipment Corporation 110 Spit Brook Road, ZKO2-3/N30 Nashua, NH 03062-2698 "Free advice is worth every cent" For information on Digital Fortran, see http://www.digital.com/info/hpc/fortran/ ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1996-12-19 5:00 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 1996-12-17 5:00 Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants Takashi Ichihara 1996-12-17 5:00 ` Steve Lionel 1996-12-18 5:00 ` Petrie L M 1996-12-18 5:00 ` Ron Shepard 1996-12-19 5:00 ` Steve Lionel 1996-12-18 5:00 ` John Hascall 1996-12-19 5:00 ` Steve Lionel
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox