workaround for duplicate declarations

workaround for duplicate declarations

I am porting programs from IRIX to Linux.
Mipspro compiler allows duplicated declarations but Intel Compiler does not allow them!(I got this comment from the premier support).
Does anyone know a workaround (some good tool or script) for this problem?

[comment from the premier support]
Duplicate declarations is a bug that the Intel Fortran compiler will continue to diagnose. We are aware that some other vendors allow duplicate declarations to appear in source code. We do not - we give an error because it is an error - the user should fix his source code.
I'm closing this as a "user error misunderstanding". Please do not reopen this issue asking to add this as a "feature request". The developers will be rejecting this request again.

[sample code]
program duptest
implicit none
integer i
integer i(20)
i(18)=18
write(6,*) i(18)
stop
end

[error message]
%ifort dup.f
fortcom: Error: dup.f, line 4: This name has already been assigned a data type. [I]
integer i(20)
------------------^
fortcom: Error: dup.f, line 5: A dummy argument of a statement function must be a scalar identifier. [18]
i(18)=18
------------^
fortcom: Error: dup.f, line 6: Statement function argument matching has not occurred since an invalid definition exists. [I]
write(6,*) i(18)
---------------------^
fortcom: Info: dup.f, line 3: This statement function has not been used. [I]
integer i
------------------^
compilation aborted for dup.f (code 1)

7 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Why not just remove the duplicate declaration?

If the use is the way you show it below, with one declaration for the type and the other for array bounds, you could replace the second "integer" with "dimension". I don't know of a tool or script that can fix this for you automatically.

Steve - Intel Developer Support

Thank you for your comments.
Yes, it's a right way.
The programs I am porting belong to my customer and they are written in old style.
I managed to remove the duplicate declaration for some (three) programs.
My customer desires to port their programs as easily as possible.
The duplicate declarations have 2 types.
(1) same declaration type
integer i
integer i
or
integer i(20)
integer i(20)
(2) different declaration type (array and scalar)
integer i
integer i(20)

I hope removing the duplicate declarations automatically
may be difficult when those are different declaration type,
but is possible when those are same delcaration type.

Please understand that these duplicate declarations are not an "old way". They are a "wrong way" and have been wrong all the way back to FORTRAN 66.

Steve - Intel Developer Support

Also note that duplicate declarations may indicate an old bug in the code that is just waiting for the right moment to wakeup and bite you. The usualy way these come into your program is by copy and pasting other code into a working routine. When duplication occures you now have an instance where multiple sections of code in a single routine "think" they own the variable(s). Sometimes this works, some times it doesn't work, and some times it works for a while. It is the last instance you have to worry about.

Additionaly, fixing the declarations such that the compiler does not complain does not fix the potential conflict of ownership. You must examine your code to make sure that there are no adverse interactions.

Jim Dempsey

Thank you for your replies.

I begin to worry about the potential BUGs.
I notice that Mipspro compiler shows optimized code as follows.
There is no duplicate declarations.
I hope this will help me to fix the potential BUGs and to remove duplicate declarations.

[optimized code shown by Mipspro]
yoshimura 40% cat dup.m
C ***********************************************************
C Fortran file translated from WHIRL Wed Nov 9 19:35:53 2005
C ***********************************************************

CSGI$ start 1
PROGRAM MAIN
IMPLICIT NONE
C
C **** Variables and functions ****
C
INTEGER*4 i(20_8)
C
C **** statements ****
C
i(18) = 18
WRITE(6, *) i(19 - 1)
STOP
END ! MAIN
CSGI$ end 1

Thank you
go
------

Thank you for your replies.

I begin to worry about the potential BUGs.
I notice that Mipspro compiler shows optimized code as follows.
There is no duplicate declarations.
I hope this will help me to fix the potential BUGs and to remove duplicate declarations.

[optimized code shown by Mipspro]
yoshimura 40% cat dup.m
C ***********************************************************
C Fortran file translated from WHIRL Wed Nov 9 19:35:53 2005
C ***********************************************************

CSGI$ start 1
PROGRAM MAIN
IMPLICIT NONE
C
C **** Variables and functions ****
C
INTEGER*4 i(20_8)
C
C **** statements ****
C
i(18) = 18
WRITE(6, *) i(19 - 1)
STOP
END ! MAIN
CSGI$ end 1

Thank you
go
------

Leave a Comment

Please sign in to add a comment. Not a member? Join today