Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable initialization

Status
Not open for further replies.

Pfor

Technical User
Aug 11, 2010
22
IT
Dear all,
I have been wasting some time to understand an error
which was rather trivial, I forgot to initialize
an index in a subroutine. As a result, no compiler gave me
any error but when executed the code gave me
different results for different compilers/computers.

My question is thus: is there a fortran instruction which forces
all the variables (arrays included)
to be zero when first created (or allocated)?

If I am not wrong using the option -zero when compiling with ifort does it but only for scalars, moreover I would prefer to force it in the code
itself.
Do you have any suggestion?
cheers,
Paolo
 
It is better that you initialize all variables yourself. That way you know that they all have legal values before you use them. Zero might not be a legal value for some variables.

Some compilers will warn you if you are using an uninitialized variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top