- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I compile the code shown below, I get an error saying that "This is not a valid initialization expression". So, is keyword initialization valid for scalars but not for arrays?Also, is it allowed for PARAMETERs?
!--------------------------------------------------------------------------------------------------
module mod1
implicit none
private
save
type, public :: someType
character(63) :: attrib = ''
integer :: length = 255
integer :: dataType = 0
end type
type(someType) :: scalar = someType(attrib = 'so')
type(someType) :: array(1) = [ someType(attrib = 'something', length = 10) ]
! type(someType), parameter :: fixed = someType(attrib = 'fixed')
end module mod1
!--------------------------------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- 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
Arrays of derived type in an initialization expression don't seem to be the problem ---since the code below compiles just fine, although when the -stand option is given to the compiler, I get a warning (Overlapping storage initializations encountered with ARRAY ...)
Also, in regards to my second question: is there any restriction to creating PARAMETERs using keyword initialization (when the absent keywords are already initialized, of course)? If I uncomment the last module line in the code below, I get an error.
!--------------------------------------------------------------------------------------------------
module mod1
implicit none
private
save
type, public :: someType
character(63) :: attrib = ''
integer :: length = 255
integer :: dataType = 0
end type
type(someType) :: scalar = someType(attrib = 'so')
type(someType) :: array(1) = [ someType('something', 10, 0) ]
! type(someType), parameter :: fixed = someType(attrib = 'fixed')
end module mod1
!--------------------------------------------------------------------------------------------------
- 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

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