This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: correct fix for aliasing bugs


On Thu, Mar 16, 2006 at 05:17:50PM -0500, Jack Howarth wrote:
> Steve,
>     Xplor-nih has a lot of legacy code from the 80's (I've been trying
> to fix odds and ends like getting rid of arithmetic IF statements).
> Also the program gets lots of donated code from various NMR labs so
> the coding practices vary a lot. 
>    I am wondering however why we can't have a compiler warning for this.
> Is it really that hard for the preprocessor to warn if the same variable
> appears twice in a function or subroutine call? Certainly would make my
> life simplier in trying to find all of these.

subroutine foo(a,b,c)
  c = a * b
end 

program d
  a = 1.
  call foo(a, a, b)
end 

Should a warning be issued?  "a" appears more than once in the
subroutine call.

troutmask:kargl[206] ftnchek bar.f

FTNCHEK Version 3.3 November 2004

File bar.f:
 0 syntax errors detected in file bar.f

Change to "call foo(a,a,a)"

troutmask:kargl[208] ftnchek bar.f

FTNCHEK Version 3.3 November 2004

File bar.f:
 0 syntax errors detected in file bar.f
Warning: Subprogram FOO argument usage mismatch at position 3:
    Dummy arg C in module FOO line 1 file bar.f is modified
    Actual arg A in module D line 7 file bar.f same as arg 2: A

Now, consider what happens if foo() isn't in the same file as
program d.  You can't catch the problem.


Without verifying the history, I suspect INTERFACE and INTENT
were added to Fortran to help catch these problems.   Unfortunately,
it doesn't help with legacy code.




-- 
Steve


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]