Youjun Hu
Youjun Hu

Reputation: 1334

When using module variables as input variables, is there a way to specify intent(in) property as we do for a subroutine variable?

To remind me that a variable from a module used in a subroutine is an input rather than an output, I usually add comments to indicate this, which provides nothing to compilers.

Upvotes: 3

Views: 450

Answers (1)

There is no such thing in Fortran that would import a module variable as a constant. As roygvib mentioned, you can declare a variable protected inside the module to make it read only for all other modules. But you cannot import a non-protected variable as read-only in Fortran.

I recommend not to treat module variables, which are really just better global variables, as input or output. If something is clearly an input or output of your subroutine, make it an argument explicitly and call it in such a way that is clear what you are doing - with the global variable as an actual argument.

Upvotes: 3

Related Questions