- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page