Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: john@iastate.edu (John Hascall)
Subject: Re: Recent Digital Fortan incompatibility for Sign Extension of Untyped Bit Constants
Date: 1996/12/18	[thread overview]
Message-ID: <599qk4$r0v@news.iastate.edu> (raw)
In-Reply-To: 5974lu$e3d$1@nntpd.lkg.dec.com


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



  reply	other threads:[~1996-12-18  5:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` John Hascall [this message]
1996-12-19  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
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox