Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29324 Discussions

C interface yields error #8532: A character dummy argument with length other than 1 is not interoperable

Brian_Triplett
2,396 Views
I have a f90 c interface which has the following structure

interface atachf
subroutine ATACHF ( filecode, filename, iprm, istat ) bind(C, name='ATACHF')
implicit none
integer :: filecode
character(len=*), intent(in) :: filename
integer, intent(in) :: iprm
integer, intent(out) :: istat(2)
endsubroutine ATACHF
endinterface atachf
It would then be called as
integer :: lu,iperm,
integer :: istat(2)
character(len=*) hname
call 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
Steven_L_Intel1
Employee
2,396 Views
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.

View solution in original post

7 Replies
TimP
Honored Contributor III
2,396 Views
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.
0 Kudos
Steven_L_Intel1
Employee
2,396 Views
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.
0 Kudos
Brian_Triplett
2,396 Views
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_mod
implicit none
integer :: lu,iperm
integer :: istat(2)
character(len=*) hname
call 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...
0 Kudos
Steven_L_Intel1
Employee
2,396 Views
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.
0 Kudos
Brian_Triplett
2,396 Views
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?
0 Kudos
Steven_L_Intel1
Employee
2,397 Views
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.
Steven_L_Intel1
Employee
2,396 Views
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.
0 Kudos
Reply