Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Fortran > Re: Allocatable...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 6 Topic 8546 of 8908
Post > Topic >>

Re: Allocatable scalar components not allowed in derived types... why?

by nospam@[EMAIL PROTECTED] (Richard Maine) Jul 23, 2008 at 03:17 PM

James Giles <jamesgiles@[EMAIL PROTECTED]
> wrote:

> Rich Townsend wrote:
> > Just out of curiosity, could anyone enlighten me why allocatable
> > scalars aren't allowed in derived types (in F2003 or F95 + TR15581)?
> > It strikes me as this could be a useful way of having a component
> > that either has a well-defined value (ALLOCATED(foo%bar) == .TRUE.)
> > or has no value (ALLOCATED(foo%bar) == .FALSE.).
> 
> I can't find any place that prohibits scalar allocatables in
> derived types.  Do you have a page/line number pair for the
> part of the standard that says so?

I'm quite confident that they are *NOT* prohibitted in f2003.
Allocatable scalars weren't in f95 at all, even with the TR. That has
nothing to do with being a derived type component. The TR added places
where you could put allocatable things, but it didn't change the fact
that allocatable things were always arrays.

F2003 did change that. It allows allocatable scalars. And the change is
quite im****tant for many things. I've mentioned here many times that I
think that allocatable strings are a major improvement. While some
people might think of a string as sort of like an array, the standard
does not. Allocatable scalars are also useful for polymorphism, where
the dynamic type gets assigned by the allocation.

Now there are several f95 compilers that have not yet implemented
allocatable scalars. Is that perhaps what you are talking about? That's
rather majorly different from the f2003 standard not allowing them. The
lack of allocatable scalars in the NAG compiler was one of the things
that kept me from fiddling much with the object-oriented stuff with that
compiler. It had a lot of the object-oriented features implemented quite
early, but I found that pretty much everything I wanted to do with
object orientation ended up with all the polymorphic objects "wanting"
to be allocatable scalars. Thus the lack of allocatable scalars pretty
much killed that. Yes, I could have made them pointers as a workaround,
but that would have introduced extra "issues." But this was all about
the state of implementation of that compiler - not about the standard.

If you found anywhere in the standard that even implies such a
restriction, I'd sure like to know. Perhaps you found a stray occurance
of some mention of "allocatable array" that should have been changed to
"allocatable variable." I recall making that change an awful lot in
working on f2003. We tried to catch al of them, but I suppose one might
have gotten overlooked somewhere. If you've found such a thing, please
let us know.

But if it is just that the compiler griped that you can't have an
allocatable scalar, that probably means that the compiler just hasn;t
implemented them yet.

-- 
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain
 




 6 Posts in Topic:
Allocatable scalar components not allowed in derived types... wh
Rich Townsend <rhdt@[E  2008-07-23 16:00:20 
Re: Allocatable scalar components not allowed in derived types..
Paul van Delst <Paul.v  2008-07-23 17:19:58 
Re: Allocatable scalar components not allowed in derived types..
Rich Townsend <rhdt@[E  2008-07-23 22:05:20 
Re: Allocatable scalar components not allowed in derived types..
"James Giles" &  2008-07-23 21:22:09 
Re: Allocatable scalar components not allowed in derived types..
nospam@[EMAIL PROTECTED]   2008-07-23 15:17:15 
Re: Allocatable scalar components not allowed in derived types..
Rich Townsend <rhdt@[E  2008-07-23 22:02:23 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Nov 19 9:23:48 CST 2008.