- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You would have to use the compiler option /check:uninit to do this, but it may not be 100% proof.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page