Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
1 View

Data initialisation in module

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
Highlighted
Valued Contributor II
1 View

No, you should not assume

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
Highlighted
1 View

I agree and i liked the warn

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
Highlighted
New Contributor I
1 View

The question is sort of the

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
Highlighted
Valued Contributor II
1 View

You would have to use the

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

0 Kudos
Highlighted
New Contributor I
1 View

I tried, it doesn't work. I

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