- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I am new user of this forum... I am sorry for my lack of experience.
I would like to have your point of view on this strange (at least for me) behaviour of intel compiler and its warings with a simple test of interface block; the code of the test is reported at the end of this post. In a few words there are 2 functions for initializing a structured type (named Type_Test) that share the same interface; the first function initialize a scalar of the structured type while the second initialize a vector. The 2 functions don't have the same type/rank/keyword signature because the second function have the input "n" that first doesn't have (the other inputs of the functions are optional). But with the code reported I get the following warning:
fortcom: Warning: test-interface.f90, line 37: The type/rank/keyword signature for this specific procedure matches another specific procedure that shares the same generic-name. [INIT_TYPE_TEST_VECTORIAL]
function Init_Type_Test_Vectorial(n,a,b,c,d) result(test)
But if I move the input "n" after the "a,b,c,d" inputs (so the signature becomes function Init_Type_Test_Vectorial(a,b,c,d,n)) the warning disappears. This is strange for me. The optional inputs would not have relavance for the signature and so the position of "n" would be insignificant.
Can anyone open my mind?
Thank you very much.
Stefano
Code bugged:
module Module_Test_Interface
implicit none
private
public:: Type_Test
public:: init
type Type_Test
integer a
integer b
integer c
integer d
endtype Type_Test
interface init
module procedure Init_Type_Test_Scalar, &
Init_Type_Test_Vectorial
endinterface
contains
function Init_Type_Test_Scalar(a,b,c,d) result(test)
implicit none
integer, intent(IN), optional:: a,b,c,d
type(Type_Test):: test
test=Type_Test(0,0,0,0)
if (present(a)) test%a = a
if (present(b)) test%b = b
if (present(c)) test%c = c
if (present(d)) test%d = d
return
endfunction Init_Type_Test_Scalar
function Init_Type_Test_Vectorial(n,a,b,c,d) result(test)
implicit none
integer, intent(IN):: n
integer, intent(IN), optional:: a,b,c,d
type(Type_Test):: test(1:n)
test=Type_Test(0,0,0,0)
if (present(a)) test%a = a
if (present(b)) test%b = b
if (present(c)) test%c = c
if (present(d)) test%d = d
return
endfunction Init_Type_Test_Vectorial
endmodule Module_Test_Interface
I am new user of this forum... I am sorry for my lack of experience.
I would like to have your point of view on this strange (at least for me) behaviour of intel compiler and its warings with a simple test of interface block; the code of the test is reported at the end of this post. In a few words there are 2 functions for initializing a structured type (named Type_Test) that share the same interface; the first function initialize a scalar of the structured type while the second initialize a vector. The 2 functions don't have the same type/rank/keyword signature because the second function have the input "n" that first doesn't have (the other inputs of the functions are optional). But with the code reported I get the following warning:
fortcom: Warning: test-interface.f90, line 37: The type/rank/keyword signature for this specific procedure matches another specific procedure that shares the same generic-name. [INIT_TYPE_TEST_VECTORIAL]
function Init_Type_Test_Vectorial(n,a,b,c,d) result(test)
But if I move the input "n" after the "a,b,c,d" inputs (so the signature becomes function Init_Type_Test_Vectorial(a,b,c,d,n)) the warning disappears. This is strange for me. The optional inputs would not have relavance for the signature and so the position of "n" would be insignificant.
Can anyone open my mind?
Thank you very much.
Stefano
Code bugged:
module Module_Test_Interface
implicit none
private
public:: Type_Test
public:: init
type Type_Test
integer a
integer b
integer c
integer d
endtype Type_Test
interface init
module procedure Init_Type_Test_Scalar, &
Init_Type_Test_Vectorial
endinterface
contains
function Init_Type_Test_Scalar(a,b,c,d) result(test)
implicit none
integer, intent(IN), optional:: a,b,c,d
type(Type_Test):: test
test=Type_Test(0,0,0,0)
if (present(a)) test%a = a
if (present(b)) test%b = b
if (present(c)) test%c = c
if (present(d)) test%d = d
return
endfunction Init_Type_Test_Scalar
function Init_Type_Test_Vectorial(n,a,b,c,d) result(test)
implicit none
integer, intent(IN):: n
integer, intent(IN), optional:: a,b,c,d
type(Type_Test):: test(1:n)
test=Type_Test(0,0,0,0)
if (present(a)) test%a = a
if (present(b)) test%b = b
if (present(c)) test%c = c
if (present(d)) test%d = d
return
endfunction Init_Type_Test_Vectorial
endmodule Module_Test_Interface
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Which function would be called if you wrote this?
var = init(1,2,3,4)
This matches both signatures. When you move N to the end, you'd have to pass all five arguments or use the N= keyword in the call, and that is then not ambiguous.
var = init(1,2,3,4)
This matches both signatures. When you move N to the end, you'd have to pass all five arguments or use the N= keyword in the call, and that is then not ambiguous.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are right! I went in a wrong way thinking that the optional inputs don't affect the signature, when the correct starting point is to keep in mind the ambiguity of the calls... thank you very much!!!!!!!!
Stefano
Stefano

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