logical ops on bit fields
Dennis Wassel
dennis.wassel@googlemail.com
Wed Jan 13 08:37:00 GMT 2010
2010/1/13 David Carr <qqdcqqdc@gmail.com>:
> On my vax port of zork to windows:
>
> uses:
> if((iflag.and.64).ne.0)
> and
> if((iflag.and.64).eq.0)
> to test a bit in iflag.
>
> Won't compile, tried tricking it with EQUIVALANCES between LOGICALs
> and INTEGERs, but ".and." doesn't seem to do bitwise and but rather
> sees if each operand is non-zero.
> I am going to be able test bits in a var?
Please consider using comp.lang.fortran to ask language-related
questions like this one -- this list is for the GNU Fortran compiler.
That being said, grab yourself a copy of Metcalf & Reid and look for
btest, iand, ibset and their friends. Beats messing with deprecated
equivalence cruft. Your example could work like
if (btest (iflag, 6) )
or
integer, parameter :: SOME_FLAG_NAME = ibset(1, 6)
if (iand (iflag, SOME_FLAG_NAME ) /= 0 )
Cheers,
Dennis
More information about the Fortran
mailing list