Do I always have to declare the variables?

Do I always have to declare the variables?

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

publicaciones de 5 / 0 nuevos
Último envío
Para obtener más información sobre las optimizaciones del compilador, consulte el aviso sobre la optimización.

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.

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

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?

David

Inicie sesión para dejar un comentario.