Question

While compiling a Fortran program with gfortran (mpif90), I encounter the following error:

Error: Cannot assign to INTENT (IN) variable 'x' at (1)
make[2]: [module.o] Error 1 (ignored)

When I compile this program with PGI, I do not receive this error.

I've got two questions regarding this.

  1. What is the meaning of this error?
  2. How can I make gfortran and mpif90 compile this module file similarly to PGI? Is there a flag that I can pass to tell the gfortran compiler not to worry about this?

Any suggestions would be appreciated.

Was it helpful?

Solution

If you'd shown us the code this might be more than a guess but here goes ...

You have a procedure, either a function or a subroutine, something like

integer function my_func(x)
    real, intent(in) :: x
    ...
    x = a_value
    my_func = 2
end function my_func

The statement real, intent(in) :: x tells the compiler that the function will not attempt to alter the argument x. And then, bang, in x = a_value, the function goes right ahead and attempts to alter the argument.

This behaviour by the compiler is a tremendous aid to safe programming and if the PGI compiler really doesn't raise an error on encountering such code then (a) it is in error, the standard requires that it should and (b) you should not be using an unsafe compiler.

Other compilers are quite right to raise this error and even if I knew a way to tell a compiler not to I wouldn't share it with you. It would be like teaching you how to remove the safety guard from a bacon-slicing machine.

Now, show us your code and one of us can give you a proper diagnosis.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top