Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
2 Views

initialization in type

 

I just tried to put a variable initialization in a type body.

Type myobj

  integer :: check = -1

end type myobj

 

there was no compiler warning for this syntax, which may ort may not be standard conforming.

When I checked the initial value of the variable in an allocated array of this type, its value was 0, not the -1 in the initialization field.

The /Qsave option was on but initialized saved variables to zero was off.

I am not sure if this ought to work or not.  If not, perhaps there should be a compiler message indicating it will not be used.

thanks,

scott

 

 

0 Kudos
4 Replies
Highlighted
Valued Contributor II
2 Views

I just ran the following

I just ran the following program:

module mytypes
    type myobj
        integer :: check = -1
    end type myobj
end module mytypes

program test_mytypes
    use mytypes

    type(myobj) :: somevar

    write(*,*) somevar
end program test_mytypes

compiled with all default compile options and it gave "-1" as the output.

The feature you are trying to use is indeed standard Fortran. So, here are a few questions:

  • Do you have a complete small program that exhibits the behaviour you report?
  • What version of the compiler are you using?

 

 

0 Kudos
Highlighted
New Contributor I
2 Views

I don't have a small version

I don't have a small version of this.  The only difference I see is somevar in my case is an allocatable array.  

 

Intel® Parallel Studio XE 2015 Composer Edition for Fortran Windows* Integration for Microsoft Visual Studio* 2012, Version 15.0.0107.11, Copyright © 2002-2014 Intel Corporation. All rights reserved.

 

glad to know this is standard conforming;  thanks.

0 Kudos
Highlighted
2 Views

I modified Arjen's program to

I modified Arjen's program to this:

module mytypes
    type myobj
        integer :: check = -1
    end type myobj
end module mytypes

program test_mytypes
    use mytypes

    type(myobj), allocatable :: somevar
    type(myobj), allocatable :: somearray(:)
    allocate(somevar)

    write(*,*) somevar
    allocate(somearray(5))
    write(*,*) somearray
end program test_mytypes

and tried it with a 15.0 compiler, and it worked (by "worked", I mean displayed -1)

      I'm guessing there's something else going on?

                                       --Lorri

0 Kudos
Highlighted
New Contributor I
2 Views

Yep, I see what you get for

Yep, I see what you get for your example code.

the compiler options I have for my real application are:

/nologo /O1 /Oy- /heap-arrays0 /I"../string/Win32/Release" /I"../geometry/Win32/Release" /I"../math/Win32/Release" /I"../parser/Win32/Release" /I"../Includes" /I"G:\HSE_house\acsys\v6.1\src\solutions\math\Win32/Debug" /I"G:\HSE_house\acsys\v6.1\src\solutions\string\Win32\Debug\/" /I"G:\HSE_house\acsys\v6.1\src\solutions\parser\Win32/Debug/" /I"G:\HSE_house\acsys\v6.1\src\solutions\xmlparser\Win32/Debug" /assume:nosource_include /warn:declarations /warn:unused /Qsave /fp:precise /fpconstant /Qfp-speculation=strict /module:"Win32/Release/" /object:"Win32/Release/" /Fd"Win32/Release\vc110.pdb" /traceback /libs:static /threads /c

 

Not sure I know ahy the initialization doesn't work in my real code or what I might be missing.

thanks for testing this so quickly!

scott

 

0 Kudos