Community
cancel
Showing results for 
Search instead for 
Did you mean: 
avinashs
New Contributor I
144 Views

Error when overloaded functions differ in passed length of character result

Jump to solution

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
Black Belt Retired Employee
141 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

2 Replies
Steve_Lionel
Black Belt Retired Employee
142 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

avinashs
New Contributor I
123 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.

Reply