Re: why doesn't this compile ?



Ken Fairfield wrote:

<snip>

> I looks to me like your attempt to define a generic function
interface
> within the main program is running afoul of the contained
proccedures.
>
> This would have worked pretty transparently if the interface and
> the contained procedures were in a separate module, but the attempt
> to put them altogether in a single procedure isn't working so well...

The following code demonstrates Ken Fairfield's suggestion of putting
the functions in a separate module.

module f_mod
implicit none
public :: f
private :: f_1,f_2
interface f
module procedure f_1,f_2
end interface f
contains
! The function that takes a rank 2
! array as its argument.
function f_2(x) result (y)
integer, intent(in), dimension(:,:) :: x
integer, dimension(size(x,2)) :: y
y = sum(x, dim=1)
end function f_2
! The function that takes a rank 1
! array as its argument.
function f_1(x) result (y)
integer, intent(in), dimension(:) :: x
integer :: y
y = sum(x)
end function f_1
end module f_mod
!
program test_array_arguments
use f_mod, only: f
implicit none
integer, dimension(2,3) :: x
! Create a 3x2 array
x(:,1) = (/ 1, 1 /)
x(:,2) = (/ 2, 2 /)
x(:,3) = (/ 3, 3 /)
! Call f on an array argument
print *, f(x)
! Call f on a vector argument
print *, f(x(:,1))
end program test_array_arguments

.



Relevant Pages

  • Re: passing a NULL pointer from vb6 to an ATL method
    ... COBJINTERFACES and use the C macro for calling into the interface. ... local/call_as is necessary fior marshaling. ... Dim array as Double ... Then you need to write two shim functions in C to link with the ...
    (microsoft.public.vc.atl)
  • Re: Anders Hejlsberg comment on immutable objects
    ... > example of a situation where a read interface does help out. ... > able to read the byte array, ... > and trust the server method, you simply pass the full blown object. ... what is a violation of a const contract. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: .NET and COM Interop
    ... > I added a function that sets the array and it worked, ... To implement the interface properly you have to be a bit sneaky. ... try to implement the property properly, the compiler will complain. ... AssemblyInfo file whereas C# does not. ...
    (microsoft.public.dotnet.framework.interop)
  • ptrace API extensions for BTS
    ... I would like to discuss the ptrace user interface for the BTS extension. ... we need to provide access to an array of BTS records ...
    (Linux-Kernel)
  • Re: Can this be automation compatible?
    ... the interface is probably marshaled ... and it cannot be the Automation interface of an ActiveX ... > according to his question it's part of a dual interface. ... > Chapters Pointer to an array of chapters per title. ...
    (microsoft.public.win32.programmer.ole)