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.
29282 Discussions

not undestood warning with interface block

szaghi
Beginner
420 Views
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

0 Kudos
2 Replies
Steven_L_Intel1
Employee
420 Views
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.
0 Kudos
szaghi
Beginner
420 Views
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
0 Kudos
Reply