- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, all
I got some problem to use the external function.
I tested it with a simple integer argument, and it worked.
----------------------------------------------------------------------
program PassArg
implicit none
! Variables
integer::i,ret
interface
integer function passtest(d)
integer::d
end function passtest
end interface
! Body of PassArg
i=1
ret=passtest(i)
print *,ret
end program PassArg
integer function passtest(d)
implicit none
integer::d
passtest=d+6
end function passtest
----------------------------------------------------------------
After then, I tested the program with the TYPE argument.
It's almost same, but it didn't work.
--------------------------------------------------------------------
program PassArg
implicit none
! Variables
integer::ret
type pass
integer::i
integer::j
end type pass
type(pass)::pp
interface
integer function passtest(d)
type pass
integer::i
integer::j
end type pass
type(pass)::d
end function passtest
end interface
! Body of PassArg
pp%i=1
pp%j=1
ret=passtest(pp)
print *,ret
end program PassArg
integer function passtest(d)
implicit none
type pass
integer::i
integer::j
end type pass
type(pass)::d
passtest=d%i+d%j
end function passtest
-----------------------------------------------------------------------------------
It has two errors like below.
1. error #8000: There is a conflict between local interface block and external interface block. F:\My Projects\PassArg\PassArg\PassArg.f90 27
2. error #6633: The type of the actual argument differs from the type of the dummy argument. [PP] F:\My Projects\PassArg\PassArg\PassArg.f90 40
I'm a newbie of FORTRAN, so I don't know what's wrong here.
Is there some special rule to use TYPE as an argument?
Please tell me some solutions...
Thank you so much
I got some problem to use the external function.
I tested it with a simple integer argument, and it worked.
----------------------------------------------------------------------
program PassArg
implicit none
! Variables
integer::i,ret
interface
integer function passtest(d)
integer::d
end function passtest
end interface
! Body of PassArg
i=1
ret=passtest(i)
print *,ret
end program PassArg
integer function passtest(d)
implicit none
integer::d
passtest=d+6
end function passtest
----------------------------------------------------------------
After then, I tested the program with the TYPE argument.
It's almost same, but it didn't work.
--------------------------------------------------------------------
program PassArg
implicit none
! Variables
integer::ret
type pass
integer::i
integer::j
end type pass
type(pass)::pp
interface
integer function passtest(d)
type pass
integer::i
integer::j
end type pass
type(pass)::d
end function passtest
end interface
! Body of PassArg
pp%i=1
pp%j=1
ret=passtest(pp)
print *,ret
end program PassArg
integer function passtest(d)
implicit none
type pass
integer::i
integer::j
end type pass
type(pass)::d
passtest=d%i+d%j
end function passtest
-----------------------------------------------------------------------------------
It has two errors like below.
1. error #8000: There is a conflict between local interface block and external interface block.
2. error #6633: The type of the actual argument differs from the type of the dummy argument. [PP] F:\My Projects\PassArg\PassArg\PassArg.f90 40
I'm a newbie of FORTRAN, so I don't know what's wrong here.
Is there some special rule to use TYPE as an argument?
Please tell me some solutions...
Thank you so much
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you put the declaration of pass into a module it works.
I think that your mistake was declaring pass twice. Im not sure why this dont work, maybe someone else can explain it to us :-)
Markus
I think that your mistake was declaring pass twice. Im not sure why this dont work, maybe someone else can explain it to us :-)
Markus
[cpp]module passDeclaration type pass integer::i integer::j end type pass end module passDeclaration ! *********************** program PassArg use passDeclaration implicit none ! Variables integer::ret, passtest type(pass)::pp ! Body of PassArg pp%i=1 pp%j=1 ret=passtest(pp) print *,ret end program PassArg ! *********************** integer function passtest(d) use passDeclaration implicit none type(pass)::d passtest=d%i+d%j end function passtest[/cpp]
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When you put the declaration of pass into a module it works.
I think that your mistake was declaring pass twice. Im not sure why this dont work, maybe someone else can explain it to us :-)
Markus
I think that your mistake was declaring pass twice. Im not sure why this dont work, maybe someone else can explain it to us :-)
Markus
[cpp]module passDeclaration type pass integer::i integer::j end type pass end module passDeclaration ! *********************** program PassArg use passDeclaration implicit none ! Variables integer::ret, passtest type(pass)::pp ! Body of PassArg pp%i=1 pp%j=1 ret=passtest(pp) print *,ret end program PassArg ! *********************** integer function passtest(d) use passDeclaration implicit none type(pass)::d passtest=d%i+d%j end function passtest[/cpp]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You have two different definitions of type PASS, as far as the Fortran language is concerned, even though they have the same name and components. You probably inserted the declaration inside the INTERFACE block because if you didn't, you got an error that the type was not declared. What you should have done was add IMPORT to the interface, like this:
Using a module is one approach, another is to make passtest a contained routine, like this:
For further reading, see my Doctor Fortran articles Doctor Fortran Gets Explicit and Domestic or Imported?
[cpp]interface integer function passtest(d) import type(pass)::d end function passtest end interface[/cpp]But this would still give you an error if you built this in Visual Studio because generated interface checking would note again that the type as declared in passtest was a different declaration of PASS than the one in the caller.
Using a module is one approach, another is to make passtest a contained routine, like this:
[cpp]program PassArg implicit none ! Variables integer::ret type pass integer::i integer::j end type pass type(pass)::pp ! Body of PassArg pp%i=1 pp%j=1 ret=passtest(pp) print *,ret contains integer function passtest(d) implicit none type(pass)::d passtest=d%i+d%j end function passtest end program PassArg [/cpp]Now you don't need an INTERFACE block and don't need to redeclare the type.
For further reading, see my Doctor Fortran articles Doctor Fortran Gets Explicit and Domestic or Imported?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot.
I'll try this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried it with the module, but still got the error
error 1 error #6633: The type of the actual argument differs from the type of the dummy argument. [PP] F:My ProjectsPassArgPassArgPassArg.f90 34
Can someone let me know what the problem is?
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do a Build > Rebuild of your project. If you still have problems, post the code you are using.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
Do a Build > Rebuild of your project. If you still have problems, post the code you are using.
I forgot to rebuild. Thank you so much.
Now it works well!!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page