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 on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29284 Discussions

Error when overloaded functions differ in passed length of character result

avinashs
New Contributor I
1,721 Views

I am trying to create an overloaded type with the following distinguishing features:

1. The return type is an allocatable character array
2. The first function, MY_CFUNC1, takes a string argument (s) followed by an integer (i) and two optional string arguments (sb, sa).
3. The second function, MY_CFUNC2, takes a string argument (s) followed by two required integers (i,n) and two optional string arguments (sb,sa).
4. n is the length of the returned string in MY_CFUNC2. However, IVF cannot distinguish it from MY_CFUNC1.
5. However, if I define MY_CFUNC3 with n as the first argument followed by s, i, sb, sa, as a replacement for MY_CFUNC2, IVF accepts that as an overloaded case.

The errors are:

error #5286: Ambiguous generic interface MY_CFUNC: previously declared specific procedure MY_CFUNC1 is not distinguishable from this declaration. [MY_CFUNC2]
error #5286: Ambiguous generic interface MY_CFUNC: previously declared specific procedure MY_CFUNC2 is not distinguishable from this declaration. [MY_CFUNC3]

I am attaching a sample code that reproduces the error.

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
1,718 Views

If I have the call:

my_cfunc ('test', 1, 2)

which specific does it get? Is it my_cfunc1(s='test',i=1,sb=2) or my_cfunc2(s='test',i=1,n=2)? See the ambiguity?

The passed length doesn't matter - that is not a distinguishing characteristic. Your replacement works because the first required argument is now integer instead of character.

View solution in original post

0 Kudos
2 Replies
Steve_Lionel
Honored Contributor III
1,719 Views

If I have the call:

my_cfunc ('test', 1, 2)

which specific does it get? Is it my_cfunc1(s='test',i=1,sb=2) or my_cfunc2(s='test',i=1,n=2)? See the ambiguity?

The passed length doesn't matter - that is not a distinguishing characteristic. Your replacement works because the first required argument is now integer instead of character.

0 Kudos
avinashs
New Contributor I
1,700 Views

Thanks, the example makes it clear. I was not considering the fact that optional arguments can render the interfaces of MY_CFUNC1 and MY_CFUNC2 to be the same. In other words, I was treating them as being different because MY_CFUNC1 would always be called with at least 2 arguments and MY_CFUNC2 would always be called with at least 3 arguments. However, if any optional argument of MY_CFUNC1 is set that difference vanishes.

0 Kudos
Reply