Do I always have to declare the variables?

Do I always have to declare the variables?



Do I always have to declare the variables with fortran? Is there a way not to declare it such as MATLAB? Do I always have to declare it at the beginning of the subroutine?


Thank you,



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

Fortran has always allowed implicit typing. By default, variables with names starting with 'I' - 'N' are integers and all others are REAL. If you need variables of other types (LOGICAL, CHARACTER, etc.), you must declare them. If you want a variable name to represent an array, you need a suitable declaration, either in a DIMENSION or a type declaration.

Fortran and Matlab are different languages. Do not attempt to draw inferences about one based on what you know about the other.

You should read the Fortran documentation in order to become more effective at using Fortran.


Despite the implicit typing of variables, I would encourage you to always use IMPLICIT NONE in every routine, and define all variables as you need them.

This helps protect you from spelling mistakes which could result in defining new variables separate to the ones you planned to use - if the compiler switch is set to warn for uninitialised and unused variables, you will soon find your mistakes..  It is a good programming practice to adopt, and one which was not available in the older versions of Fortran.



Thank you. I figured implicit typing is possible. However, soon I have noticed its disadvantages. In fact, I am right now having a problem. Some of the vectors and matrices do not pass from one subroutine to another. It says undefined pointer/array. Even though I went back to "implicit none", i am still having this problem.

Can you upload your code?


Leave a Comment

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