(j3.2006) DOUBLE PRECISION and C Interoperability

Robert Corbett robert.corbett
Wed Sep 12 02:33:45 EDT 2012


On 09/11/12 15:56, Van Snyder wrote:
> On Tue, 2012-09-11 at 15:37 -0500, Bill Long wrote:
>>
>> On 9/11/12 3:27 PM, Van Snyder wrote:
>>> On Thu, 2012-09-06 at 11:58 +0900, Malcolm Cohen wrote:
>>>> On 09/05/12 18:41, Robert Corbett wrote:
>>>>> If a C companion processor imposes stricter requirements
>>>>> on alignment for objects of type double than a Fortran
>>>>> processor can guarantee for objects of type
>>>>> DOUBLE PRECISION, can C double and Fortran DOUBLE PRECSION
>>>>
>>>> or Fortran REAL with the -double option.
>>>>
>>>>> be considered interoperable types?
>>>>
>>>> I don't think so, at least not entirely.
>>>
>>> This seems to suggest that C_DOUBLE and KIND(0.0d0) aren't necessarily
>>> the same -- depending upon which companion processor the Fortran
>>> processor is instructed to work with.
>>>
>>
>> The Fortran vendor gets to choose what C processors are valid
>> companions. Typically this is the C compiler from the same vendor.
>> Maybe (likely) that's the only one.
>>
>> By default  C_DOUBLE would normally be the same value as KIND(0.0d0).
>> However, if the Fortran code was compiled with switches that promoted
>> "single" to 64-bits reals  and "double" to 128-bit reals then the
>> relationship would fail.   Or course, the use of such switches is
>> strongly discouraged.  Similarly, the use of "d0" is also obsolete.
>>
>> You have a more reliable chance of C_DOUBLE being the same as
>> SELECTED_REAL_KIND(12).
>
> Does this guarantee the same rules for alignment that the C processor
> requires?  If C_DOUBLE is not equal KIND(0.0d0) there is a chance the
> Fortran processor could enforce the companion processor's alignment
> rules.  Of course, where the alignment rules are the same, there's no
> problem for C_DOUBLE to be equal to KIND(0.0d0).
>

One possibility considered by Oracle's Fortran engineering team
is to add a new kind of REAL that corresponds to C double.
Unlike Bill's suggestion, the proposed value of the new kind
type parameter value is 9, which would also be the value of
C_DOUBLE.  The value for DOUBLE PRECISION is 8.  Therefore,
the value of SELECTED_REAL_KINDwill never be 9.

Bob Corbett




More information about the J3 mailing list