- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
is it legal to overload 2 procedures as follows?
the potential ambiguity in the call here is resolved by the use of the keywords (required by construction in this example)
CVF and IVF dont give any compiler warnings and execute fine. However, IVF does crash if debugging by stepping 1 line at a time into len_trim (but not if placing breakpoint inside len_trim2 and F5'ing to it). CVF debugs fine.
!******************************************************************
module strings
implicit none
!---
interface len_trim
module procedure len_trim2
endinterface len_trim
!---
contains
!----------------------------------------------------
elemental function len_trim2(string1,string2)
implicit none
character(*),intent(in),optional::string1
character(*),intent(in)::string2
integer(4)::len_trim2
if(present(string1))then
len_trim2=len_trim(string1)
else
len_trim2=len_trim(string2)
endif
endfunction len_trim2
!----------------------------------------------------
endmodule strings
!******************************************************************
program main
use strings
implicit none
character(*),parameter:: str='string'
write(*,*)len_trim(string=str) ! invokes intrinsic
write(*,*)len_trim(string2=str) ! invokes defined len_trim1
endprogram main
!******************************************************************
the potential ambiguity in the call here is resolved by the use of the keywords (required by construction in this example)
CVF and IVF dont give any compiler warnings and execute fine. However, IVF does crash if debugging by stepping 1 line at a time into len_trim (but not if placing breakpoint inside len_trim2 and F5'ing to it). CVF debugs fine.
!******************************************************************
module strings
implicit none
!---
interface len_trim
module procedure len_trim2
endinterface len_trim
!---
contains
!----------------------------------------------------
elemental function len_trim2(string1,string2)
implicit none
character(*),intent(in),optional::string1
character(*),intent(in)::string2
integer(4)::len_trim2
if(present(string1))then
len_trim2=len_trim(string1)
else
len_trim2=len_trim(string2)
endif
endfunction len_trim2
!----------------------------------------------------
endmodule strings
!******************************************************************
program main
use strings
implicit none
character(*),parameter:: str='string'
write(*,*)len_trim(string=str) ! invokes intrinsic
write(*,*)len_trim(string2=str) ! invokes defined len_trim1
endprogram main
!******************************************************************
Message Edited by forall on 04-20-2005 12:03 PM
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Note that it is the first argument to len_trim2 that is optional. If it were the second, then this would be ambiguous. Because it is the first, and the second non-optional argument does not exist in the intrinsic, then this is ok. Note that there is no way to pass the second argument to len_trim2 without using the keyword.
The code runs ok for me, though I didn't try setting a breakpoint.
The code runs ok for me, though I didn't try setting a breakpoint.

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