- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It seems that the current compiler only allows positional fields inside structure constructors when initializing parameters. Variable derived types can be explicitly initialized by structure constructors with named fields as well as positional. See code below for examples. Is this a bug or is this what the standard requires? I haven't found it in the standard (yet).
Compiling with Intel Visual Fortran 11.1.065 [IA-32]...
[fortran]program C4
type :: m
integer :: i = 0
end type
type :: o
integer :: id = 0
type(m) :: cache = m (1)
logical :: multi = .false.
end type o
!OK
type(o) :: x1 = o(1, multi=.true., cache = m(5))
type(o) :: x2 = o(1, cache=m(5), multi=.true.)
type(o) :: x3 = o(1, cache=m(5))
type(o) :: x4 = o(1, multi=.true.)
!error #7747: Invalid parameter expression.
type(o), parameter :: a1 = o(1, multi=.true., cache = m(5))
!error #7747: Invalid parameter expression.
type(o), parameter :: a2 = o(1, multi=.true.)
!OK relying on default initializers as long as you dont name fields
type(o), parameter :: a4 = o(1, m())
!error #7747: Invalid parameter expression.
type(o), parameter :: a3 = o(1, cache=m())
end program C4[/fortran]
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I know we've had some issues with keywords in structure constructors - I'll take a look at this on Monday.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for looking into this Steve. The standard talks of only one sort of structure constructor and my reading is that all of the above code should be valid.
-joe
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Any progress on characterizing this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not yet -sorry. But I will get to it soon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Escalated as issue DPD200157285. Thanks for the nice example.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This will be fixed in an update, probably the first one, to the next major release.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page