I have this function in C
void func1 (const int * arg1, const int arg2)
To call the C function in Fortran, I'm not sure which interface is
correct:
subroutine func1 (arg1, arg2)
integer(c_int), intent(IN) :: arg1
integer(c_int), intent(IN), value :: arg2
end
or
subroutine func1 (arg1, arg2)
integer(c_int), intent(IN) :: arg1
integer(c_int), value :: arg2
end
And the final one is how about this situation: const void* and const
void**
How we map these objects in Fortran?
Thanks,
Tuan
|
|
0
|
|
|
|
Reply
|
hoangtrongminhtuan (17)
|
6/11/2010 1:33:04 AM |
|
bio_amateur <hoangtrongminhtuan@gmail.com> wrote:
> I have this function in C
> void func1 (const int * arg1, const int arg2)
> To call the C function in Fortran, I'm not sure which interface is
> correct:
> subroutine func1 (arg1, arg2)
> integer(c_int), intent(IN) :: arg1
> integer(c_int), intent(IN), value :: arg2
> end
> or
> subroutine func1 (arg1, arg2)
> integer(c_int), intent(IN) :: arg1
> integer(c_int), value :: arg2
> end
As I understand const, it restricts what the callee will do
with the specified variable. There is no requirement that
the caller supply an appropriately const value, but it is
allowed to do so.
That said, there is also the difference between const int *
and int * const, and, for that matter, const int * const.
For a non-pointer actual argument, as you show, intent(in)
means that the variable itself won't be modified by the called
routine. That is, as you say, int const *.
For a pointer argument, intent applies to the pointer,
not to the pointee. That is, like int * const.
Note that you could also use
type(c_ptr),value :: arg1
In which case the actual argument would be c_loc() of the
appropriate array.
> And the final one is how about this situation: const void*
> and const void**
Fortran doesn't usually use void**, though it should be
possible to have an array of type(c_ptr).
In that case, intent(in) would correspond to
void**const, and not void *const* or const void**.
-- glen
|
|
0
|
|
|
|
Reply
|
glen
|
6/11/2010 2:53:56 AM
|
|
|
1 Replies
163 Views
(page loaded in 0.038 seconds)
Similiar Articles: Sockets in gfortran? - comp.lang.fortranThis is all from before f2003 C interop (as ... Prog readn_writen} */ ssize_t writen(int, const ... The hidden string-length arguments that some Fortran compilers use ... problem with mixed c and fortran code - comp.lang.fortran ...... printf ((const char * restrict) (char *) "Printing from c before fortran ... but given Fortran-C interop ... dummy argument - comp.lang.fortran ... problem with mixed c and ... intent(out) for pointer dummy argument - comp.lang.fortran ...Fortran 2003 added the ability to specify intent for pointer dummy arguments. I've found this very useful in the intent(in) case and it has some us... Difference between passing a number and a variable to a subroutine ...Hi Ralph, Unlike C, Fortran passes its procedure ... interesting, as I really didn't know how Fortran passes arguments ... > Do you mean that if I use C interop, my code is ... Usage of iso_c_binding - comp.lang.fortran... provide me with the necessary command line arguments ... O, it might be possible to do I/O from both Fortran and C. ... class cx_array_length { template static inline const ... f95 to windows dll - comp.lang.fortran>>> >>> 2. arguments must match in position, type and number ... http://gcc.gnu.org/onlinedocs/gfortran/Interoperability-with-C.html (Should mostly apply to all recent Fortran ... 64-bit byteswapping and legacy programs - comp.lang.fortran ...I was using SWAPR8 (with nominally real >argument) for REAL*8 because at ... some interesting complications in C (which should come through to Fortran's C interoperability ... Bad use of stringstream temporary? - comp.lang.c++Bad use of stringstream temporary? - comp.lang.c++... according to the current standard): std::string s1 ... ... member function taking the const void* as argument is ... Where did Fortran go? - comp.lang.fortran(his arguments: LAPACK is written in F77, therefore ... For example, Interoperability with C appeared relatively quickly ... > > - I/O is not faster from C or Fortran than say Python. Why can not I implicitly convert "Derived **" to "Base * const ...I know to implicitly convert a "char **" to a "const ... an important (read transparent) form of input argument. ... derived type containing pointers... - comp.lang.fortran ... Fortran Programming Language :: Variable number of arguments//void c_function(const char *fmt) // this works ... Sure, C-fortran interoperability may have some gotchas, and that ... > extra arguments in C, even if they are on the end. C strings to Fortran - C / C++ - Bytes - Tech Commmunity ...C strings to Fortran. C / C++ ... > void print_string_(const ... string length argument in many current compilers] [color=blue] > 2. Does F2KV address this issue in C-interop?[/color] 7/26/2012 8:52:21 PM
|