Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!utah-cs!BEEBE@SCIENCE From: Beebe@SCIENCE (Nelson H.F. Beebe) Newsgroups: comp.lang.fortran Subject: Re: Re:FORTRAN-77 XLA PLUS BITWISE OPERATORS Message-ID: <12296045502.17.BEEBE@SCIENCE.UTAH.EDU> Date: Mon, 20-Apr-87 11:35:16 EST Article-I.D.: SCIENCE.12296045502.17.BEEBE Posted: Mon Apr 20 11:35:16 1987 Date-Received: Fri, 24-Apr-87 03:23:31 EST Lines: 36 In-Reply-To: <1731@imag.UUCP> X-Us-Mail: "Center for Scientific Computation, South Physics, University of Utah, Salt Lake City, UT 84112" X-Telephone: (801) 581-5254 Regarding this subterfuge for fullword bit twiddling: >> integer function AND(i1,i2) >> integer k1, k2,k3 >> logical j1,j2,j3 >> equivalence (k1,j1), (k2,j2), (k3,j3) >> >> k1=i1 >> k2=i2 >> j3=j1.and.j2 >> AND=k3 >> end >> IT WON'T WORK ON MANY MACHINES. First, a compiler is free to implement FORTRAN LOGICAL data as any object of size at least one bit. I have seen compilers that tested the sign bit, others that test the right-most bit, others that test either the right-most or left-most byte, and still others that test for zero/non-zero. The LOGICAL .OP. operators will rarely work on fullword data. Second, there may be no guarantee that a LOGICAL is of the same size as an INTEGER, and I could name one compiler where they are not (apparently in violation of ANSI F77, Section 4.7, p. 4-4 "A logical datum has one numeric storage unit in a storage sequence"). The code above will work on some machines, but comments should definitely flag it as non-portable. It is regrettable that ANSI never included a standard set of integer bit operations (.AND., .OR., .NOT., .XOR.), since almost all compilers (IBM notably excepted) have implemented them in some fashion. -------