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

Data initialisation in module

Le_Callet__Morgan_M
645 Views

I am sure this has been asked many time, but are data maybe simple type like integer initialised at run time?

I have a feeling they are set to 0.0.

I am using: Visual Fortran Compiler XE 14.0.1.139 [Intel(R) 64

0 Kudos
5 Replies
Arjen_Markus
Honored Contributor II
645 Views

No, you should not assume anything about a default initialisation. Only if you explicitly set the value via a DATA statement or via an assignment in the declaration, can you be sure that the variable will have a particular value at start-up.

Even if it seems so nonetheless, it may be that one day there is rubbish left in the memory location that does not represent zero and that rubbish causes your program to fail.

0 Kudos
Le_Callet__Morgan_M
645 Views

I agree and i liked the warning for un initialised variable in debug as it helped me weed out lots ofissues but i do not know why the attached data such warning is not given out.

0 Kudos
Simon_Geard
New Contributor I
645 Views

The question is sort of the other way round. In the example as it stands both itest and rtest are assigned a value of 0 and the program runs to completion. The real variable rtest can be managed by initializing it to snan but there is no equivalent for integers. Is it possible to detect whether or not an integer module variable has been initialized?

0 Kudos
Arjen_Markus
Honored Contributor II
645 Views

You would have to use the compiler option /check:uninit to do this, but it may not be 100% proof.

0 Kudos
Simon_Geard
New Contributor I
645 Views

I tried, it doesn't work. I suspect that the problem is that any bit-pattern in an integer represents a valid integer so there isn't an equivalent of snan. In theory it should be possible to keep a flag behind the scenes that carries the initialization state but in practice that might be just too unwieldy.

0 Kudos
Reply