From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7344,1555b3aaf4501faf X-Google-Attributes: gidf7344,public X-Google-Thread: 10f8a1,1555b3aaf4501faf X-Google-Attributes: gid10f8a1,public X-Google-Thread: f7cd1,1555b3aaf4501faf X-Google-Attributes: gidf7cd1,public X-Google-Thread: 1164f8,1555b3aaf4501faf X-Google-Attributes: gid1164f8,public X-Google-Thread: 1094ba,1555b3aaf4501faf X-Google-Attributes: gid1094ba,public From: john@iastate.edu (John Hascall) Subject: Re: Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants Date: 1996/12/18 Message-ID: <599qk4$r0v@news.iastate.edu>#1/1 X-Deja-AN: 204812190 references: <1996Dec17.055242.11669@riksun.riken.go.jp> <5974lu$e3d$1@nntpd.lkg.dec.com> organization: Iowa State University, Ames, Iowa USA newsgroups: comp.lang.fortran,comp.os.vms,vmsnet.alpha,vmsnet.misc,comp.sys.dec Steve Lionel 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