Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28543 Discussions

Do I always have to declare the variables?

Seyhan_Emre_G_
Beginner
272 Views

Hello,

 

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,

 

Emre

0 Kudos
4 Replies
mecej4
Honored Contributor III
272 Views

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.

0 Kudos
DavidWhite
Valued Contributor II
272 Views

Emre,

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.

Regards,

David

0 Kudos
Seyhan_Emre_G_
Beginner
272 Views

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.

0 Kudos
DavidWhite
Valued Contributor II
272 Views

Can you upload your code?

David

0 Kudos
Reply