[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Macro to obtain kind parameter value in F90?
From: |
Rhys Ulerich |
Subject: |
Re: Macro to obtain kind parameter value in F90? |
Date: |
Fri, 15 Oct 2010 10:55:02 -0500 |
Hi Ralf,
>> Can anyone recommend a macro for obtaining a kind parameter value in
>> Fortran 90?
> Have you looked at the Autoconf Macro Archive?
Nothing there jumped out as a good starting point.
>> The check would be like AC_SIZEOF, but instead of returning the size
>> it would return the kind parameter value (an integer).
> Well, I for one wouldn't know how to do a cross-compile version of
> AC_COMPUTE_INT.
Me neither. :)
> Does Fortran have a sizeof equivalent?
Some vendors do but there isn't (to my shoddy knowledge) something
standard in F2003 that's fits the sizeof concept. Even sizeof
wouldn't be enough technically since I don't believe the standard
requires kind parameters to match storage sizes.
> Does it have the notion of types that can differ
> although their internal representation may be the same.
See above about kind parameters not necessarily matching storage sizes.
>> For the curious, I want the value so that I can wrap a C
>> implementation with a public Fortran API that exposes types like
>> REAL(4) instead of REAL(C_FLOAT). The latter "leaks" ISO_C_BINDING
>> information to clients while the former does not.
> May I ask why the leaking would be a problem?
Hmm.. I though the use of REAL(C_FLOAT) in a function signature would
require the caller to have C_FLOAT in scope to use the function (hence
leaking). I was mistaken and a simple test case (following signature)
compiles just fine (on systems where C_FLOAT = 4).
Since there's no need for leakage, I don't need such a macro after
all. It's nice when the problem boils down to just my poor
understanding of the language.
Thank you for your time,
Rhys
! Leakage test case
module testing
use, intrinsic :: iso_c_binding, only: c_float
private :: c_float
contains
real(c_float) function test (x)
real(c_float), intent(in) :: x(*)
test = 2 * x(1)
end function test
end module testing
program main
use testing
implicit none
real(4) :: s(1)
s = 2.0
write (*,*) test(s)
end program main