- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a f90 c interface which has the following structure
interface atachfsubroutine ATACHF ( filecode, filename, iprm, istat ) bind(C, name='ATACHF')implicit noneinteger :: filecodecharacter(len=*), intent(in) :: filenameinteger, intent(in) :: iprminteger, intent(out) :: istat(2)endsubroutine ATACHFendinterface atachf
It would then be called as
integer :: lu,iperm,integer :: istat(2)character(len=*) hnamecall atachf(lu,hname,iperm,istat)
How do I get around this error? This code compiled with IVF 10 but seems to not work with IVF 12.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You misunderstand. Your declaration of the interface is generic because you said:
INTERFACE ATACHF
If you simply wote:
INTERFACE
then it would not be generic and the call would succeed.
With a name on the INTERFACE statement you are creating a generic interface which can have multiple procedures inside it - a reference to the generic name can then select the one specific procedure that match the argument.
I have escalated the generic error as issue DPD200168439.
INTERFACE ATACHF
If you simply wote:
INTERFACE
then it would not be generic and the call would succeed.
With a name on the INTERFACE statement you are creating a generic interface which can have multiple procedures inside it - a reference to the generic name can then select the one specific procedure that match the argument.
I have escalated the generic error as issue DPD200168439.
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The standard requires an array of single characters under the interface. You can take your choice whether to append a nul character, making it literally the same as a C string (which is an array of char). On the Fortran side, it's interoperable with a scalar character string, so correcting the interface alone should give the same effect you got with the non-standard compiler. There have been posts on this on these Fortran forums, may be difficult to find.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tim correctly explains that the Fortran standard says that the only character declaration interoperable with C is an array of single characters. Version 10 of the compiler did not detect this error.
All you need to do is change the declaration of filename in the interface as:
character, dimension(*), intent(in) :: filename
It IS allowed to pass a character string to this - a special exemption in the language. (Unfortunately, the language has no good way to declare a Fortran routine to which a char* would be passed and still allow you to access it as a character string. There are workarounds, but they're clumsy.)
As Tim also notes, you'll probably want to be sure that the string you pass contains a terminating NUL.
All you need to do is change the declaration of filename in the interface as:
character, dimension(*), intent(in) :: filename
It IS allowed to pass a character string to this - a special exemption in the language. (Unfortunately, the language has no good way to declare a Fortran routine to which a char* would be passed and still allow you to access it as a character string. There are workarounds, but they're clumsy.)
As Tim also notes, you'll probably want to be sure that the string you pass contains a terminating NUL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This allowed the module file to compile however now at the actual subroutine call I'm recieving:
error #6285: There is no matching specific subroutine for this generic subroutine call. [ATACHF]
Again the call to this is given as
use attachf_modimplicit noneinteger :: lu,iperminteger :: istat(2)character(len=*) hnamecall atachf(lu,hname,iperm,istat)
Am I in a catch 22 here? I could remove the USE statement at the beginning but I'm losing the whole point of keeping the explicit interface...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I assume that "iistat" is just a typo when you posted here.
I can confirm that if you have a generic, then hname doesn't match. If the interface was not generic (do you have a second routine in that interface?), it works. I think this may be a compiler bug and will report it.
I can confirm that if you have a generic, then hname doesn't match. If the interface was not generic (do you have a second routine in that interface?), it works. I think this may be a compiler bug and will report it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Indeed, "iistat" was a typo. I've edited the post.
Actually "ATACHF" it is not generic. There is only one subroutine definition of "ATACHF" which takes only the aforementioned arguments. What I have in the inital post is the entire interface. I'm using IVF Composer XE 2011. Is there some compiler flags that I have incorrect, since it's working for you?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You misunderstand. Your declaration of the interface is generic because you said:
INTERFACE ATACHF
If you simply wote:
INTERFACE
then it would not be generic and the call would succeed.
With a name on the INTERFACE statement you are creating a generic interface which can have multiple procedures inside it - a reference to the generic name can then select the one specific procedure that match the argument.
I have escalated the generic error as issue DPD200168439.
INTERFACE ATACHF
If you simply wote:
INTERFACE
then it would not be generic and the call would succeed.
With a name on the INTERFACE statement you are creating a generic interface which can have multiple procedures inside it - a reference to the generic name can then select the one specific procedure that match the argument.
I have escalated the generic error as issue DPD200168439.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was mistaken in thinking that the compiler rejecting the generic reference was a bug.
12.5.2.5.4 p13 (page295) says:
"If the procedure is nonelemental and is referenced by a generic name or as a defined operator or defined assignment, the ranks of the actual arguments and corresponding dummy arguments shall agree."
This means that the generic call here is NOT valid since the ranks do not agree, even though it would be ok to call the specific.
12.5.2.5.4 p13 (page295) says:
"If the procedure is nonelemental and is referenced by a generic name or as a defined operator or defined assignment, the ranks of the actual arguments and corresponding dummy arguments shall agree."
This means that the generic call here is NOT valid since the ranks do not agree, even though it would be ok to call the specific.
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