Jan van Oosterwijk wrote:
> At 14:03 24-08-2004 -0400, Aleks wrote:
...
>> The way to set bit patterns in Fortran (for now) is to use BOZ constants
>> (starting with letter B, O or Z for binary, octal and hexadecimal), and
>> also, you can use IEOR to get bitwise or and use the same mechanism you
>> do in the C header file:
>>
>> INTEGER, PARAMETER :: PAPI_L1_DCM = Z'80000000'
>> ! Is -2147483648
>> INTEGER, PARAMETER :: PAPI_L1_ICM = IOR(PAPI_L1_DCM,1)
>> ! Is -2147483647
>
> Sorry, Aleks, this is non-standard.
> BOZ (upto F95) can, regrettably, be used only in DATA statements
> and consequently only for variables.
INTEGER, PARAMETER :: PAPI_L1_DCM = ISHFT(1,BIT_SIZE(1)-1)
BIT_SIZE is explicitly permitted in an initialization expression.
ISHFT is a elemental function with integer arguments and result,
hence also legal in an initialization. ISHFT use is legal here, but
with implementation specified result since it leaves the sign-bit
set. This whole exercise assumes 2's complement though. So,
this should work fine given that assumption.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
|