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 3 of 6 Topic 8546 of 8908
Post > Topic >>

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

by Rich Townsend <rhdt@[EMAIL PROTECTED] > Jul 23, 2008 at 10:05 PM

Paul van Delst 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.).
> 
> Probably because what you want to use them for is a bad idea? :o)
> 
> What wrong with using an actual component that you explicitly set? E.g.
> 
> type mytype
>   logical :: bar = .false.
>   ...other stuff
> end type mytype
> 
> ?
> 
> Why would you want to use an ALLOCATABLE component for simply checking 
> true/false? If there is a good reason (which I doubt) what about,
> 
> type mytype
>   integer,allocatable :: bar(:)
>   ...other stuff
> end type mytype
> ....
> type(mytype) :: foo
> 
> You can still use that for your test:
> 
> if( allocated(foo%bar) ) then
>    ....
> end if
> 
> ?

Well, suppose I wanted a scalar integer that had the standard range of
values 
[-HUGE(0) -> +HUGE(0), plus the non-model numbers], but could also be
'unset'. 
Having the scalar be unallocated is a nice way to implement the 'unset'
feature. 
Plain old Fortran 'undefined' won't cut the mustard in this respect, since
to 
reference an undefined variable in any manner is WWIII-causer.

> 
> 
> cheers,
> 
> paulv
> 
> p.s. Welcome back.

Thanks!
 




 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 7:52:44 CST 2008.