From: Jason Blevins on
Is there any way in Fortran 2003 to initialize the components of the
parent type when declaring an extended type? An old version of John
Reid's summary of Fortran 2003 features (N1507) indicates
that something like this might be possible:

type :: base_t
character(len=25) :: name = 'base'
end type base_t

type, extends(base_t = base_t('extension')) :: extension_t
! ...
end type extension_t

That paragraph was removed in the new version (N1579) and since I
cannot find any mention of this in the standard or in the Handbook, it
appears that this feature was dropped. Is there an alternative that
doesn't involve calling an initialization function?

--
Jason Blevins
Ph.D. Candidate, Department of Economics, Duke University
http://jblevins.org/
From: Richard Maine on
Jason Blevins <jrblevin(a)sdf.lonestar.org> wrote:

> Is there any way in Fortran 2003 to initialize the components of the
> parent type when declaring an extended type? An old version of John
> Reid's summary of Fortran 2003 features (N1507) indicates
> that something like this might be possible:
>
> type :: base_t
> character(len=25) :: name = 'base'
> end type base_t
>
> type, extends(base_t = base_t('extension')) :: extension_t
> ! ...
> end type extension_t
>
> That paragraph was removed in the new version (N1579) and since I
> cannot find any mention of this in the standard or in the Handbook, it
> appears that this feature was dropped. Is there an alternative that
> doesn't involve calling an initialization function?

I didn't recall that feature in the first place. I suppose it might have
been in some proposal; must have been a pretty early one.

I know of no way to override the parent default initialization with a
different default initialization. Do note the word "default", which is
important here. I recommend against omitting that word or you will get
confused. Initialization does override default initialization; you can
do that. But initialization isn't something you can specify in a type
declaration; that's default initialization. You can only specify
initialization (without the "default") for a particular object.

Interestingly, you can do simillar overrides for components other than
the parent one, but I don't know of a way to do it for the parent
component. I hadn't thought about this oddity until your post prompted
me to.

I do find the terminology slightly confusing in that default
initialization is not just a default for initialization. It is sort of
like that, which obviously drove the terminology choice, but that's not
all it is. Default initialization happens in contexts where
initialization doesn't apply at all.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain
From: Jason Blevins on
On 2010-04-22, Richard Maine <nospam(a)see.signature> wrote:
> Jason Blevins <jrblevin(a)sdf.lonestar.org> wrote:
>
>> Is there any way in Fortran 2003 to initialize the components of the
>> parent type when declaring an extended type? An old version of John
>> Reid's summary of Fortran 2003 features (N1507) indicates
>> that something like this might be possible:
>>
>> [snip]
>
> I didn't recall that feature in the first place. I suppose it might have
> been in some proposal; must have been a pretty early one.

Probably so: the earlier (N1507) version of that paper was still
referring to "Fortran 2000."

> I know of no way to override the parent default initialization with a
> different default initialization.

I suspected there might not be. Thanks for confirming.

> Do note the word "default", which is important here.

Yes, my question was about _default_ initialization. Although I knew
the difference in practice, the terminology makes much more sense
after your clarification.

--
Jason Blevins
Ph.D. Candidate, Department of Economics, Duke University
http://jblevins.org/