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

About initial value of variables and !DEC$ ATTRIBUTES

reidar_tyssen
Beginner
326 Views

When starting a program, initially all integer and real are zero,but with IVF this is different compared to CVF. To be correct, som are, some are not, but they are all declared in the same manner. In the example below, "icall" has the initial value 33619979 but should be 0. Is there an simple explanation for this?

Another question, the compiler directives used in CVF were not deleted when I converted the project to IVF. Does this means that also the Intel compiler is using them?

Regards

Reidar

! Trap user command from window hwndUser

if(hWnd==hwndUser)then

icall=icall+1

if(icall.eq.1)then

do j=1,128

filebuff2(J:J)=' '

enddo

bret=SetCaretPos(0,0)

newl=0 ; oldl=0

endif

0 Kudos
3 Replies
TimP
Honored Contributor III
326 Views
ifort doesn't necessarily duplicate CVF initialization, except for standard Fortran explicit initialization (using DATA or declaration with initialization expression). SAVE must be explicit to be safe, if required. You don't show your code, so I can state only generalities.
I would expect the DEC$ ATTRIBUTES to be observed; check the help file to make sure your use conforms to documentation.
0 Kudos
Steven_L_Intel1
Employee
326 Views
Intel Fortran provides default initialization for exactly the same number of variables as CVF - zero. CVF does not have such a feature. What might have you thinking it did was that CVF assumed SAVE semantics for local variables, whereas ifort does not. This means that local scalar variables are much more likely to end up on the stack than statically allocated and thus uninitialized variables will have unpredictable values. You can match the CVF behavior by adding the /Qsave switch or, in Visual Studio, set Fortran > Data > Local Variable Storage > All variables SAVE. In a future update, this will be set by default for projects converted from CVF - we goofed in not doing this from the start.

Actually, Intel Fortran does have a feature to do zero initialization of SOME variables, enabled with the /Qzero option, but this is for static, local variables only (and thus tends to require /Qsave as well.)

As for the !DEC$ directives - all of these from CVF are supported by Intel Fortran. If you look in the manual you'll see them listed in a chapter titled "Directive Enhanced Compilation" (or DEC).
0 Kudos
reidar_tyssen
Beginner
326 Views

Thank you Steve and Tim18,

The Qsave switch solved my problem with initialization.

Best regards

Reidar

0 Kudos
Reply