warning about redundant lines of code
Sometimes I inadvertently set the value of a variable but do not use it
before it is reset to another value, so that the initial statement
setting the variable is redundant. A trivial example is below.
implicit none
integer :: i
i = 1 ! line has no effect
i = 2
print*,i
end
Are there any compilers that warn about such a redundant line? Do you
think it would be useful to get such warnings? In a realistic example,
there may be many lines of code separating the statements setting 'i',
so the redundant code may be hard for the programmer to spot.
One difficulty is that it may be impossible to say if a statement
setting a variable to an expression involving a non-PURE function is
redundant.
|