Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29265 ディスカッション

Initial value of Integer in 9.0.019

tropfen
新規コントリビューター I
784件の閲覧回数
Hello

Until now i was used that the initial value of integer is 0. (using CVF 6.6B)

Using IVF 9.0.019 the value looks different. Is this the way IVF works or is this a mistake?

Thanks in advance
Frank
0 件の賞賛
4 返答(返信)
ingo_berg
ビギナー
784件の閲覧回数
The initial value is supposed to be undefined. You should not make any assumptions on it. On most compilers debug mode initializes variables to zero.
tropfen
新規コントリビューター I
784件の閲覧回数
Hello Ingo,
I cannot agree with you. Its is ok to say each variable has to set to an initial value inside the source, but in my view the compiler has to set each integer variable to 0 by definition(initial value).

Frank
TimP
名誉コントリビューター III
784件の閲覧回数
If you depend on default initialization, you must use options provided by individual compilers, such as ifort -Qsave -Qzero, until you have corrected your program.
ingo_berg
ビギナー
784件の閲覧回数
Hi Frank,

it does not matter if you agree or not. According to the standard a fortran compiler does not have to assign an initial value to a variable.

So making assumptions about it is wrong or dangerous at best. If you rely on such a behaviour you need to use a non standard extensions of your compiler. This is probably the primary reason for programs that do not run in release mode but run flawessly in debug mode.

Default Initialization can be an overhead if your function gets called millions of times per second. According to the post by tim18 there is a way to enforce this for IVF. This does not change the fact that it is nonstandard and you will be in trouble again if you ever choose to use another compiler.
返信