Derived type PARAMETERs 
Author Message
 Derived type PARAMETERs

Is it possible to have a named constant (PARAMETER) of type specified
by a derived type ?

If so, what is the syntax ?

Thanks in advance.

Dave Flower



Sun, 20 Jul 2008 20:54:47 GMT  
 Derived type PARAMETERs
TYPE T1
 character(len=4) :: a
END TYPE T1
TYPE T2
  TYPE(T1) :: a,b
END TYPE T2
TYPE(T2), PARAMETER :: D=T2(T1("abcd"),T1("1234"))
write(6,*) D
END

Joost



Sun, 20 Jul 2008 21:00:49 GMT  
 Derived type PARAMETERs
| Is it possible to have a named constant (PARAMETER) of type specified
| by a derived type ?
|
| If so, what is the syntax ?
|
| Thanks in advance.

    type foo
      integer i
      real r
      integer, pointer:: p
    end type foo

    type(foo), parameter:: f = foo(1,42.,null())

I purposefully added a pointer component to check if it's allowed; I'm still
not positive about it, but it goes by in both CVF and IVF. It seems that only
null() can be possibly allowed there though.

--
 Jugoslav
___________
www.xeffort.com

Please reply to the newsgroup.
You can find my real e-mail on my home page above.



Sun, 20 Jul 2008 21:01:07 GMT  
 Derived type PARAMETERs

Quote:
> It seems that only
> null() can be possibly allowed there though.

yes, that's right.

Joost



Sun, 20 Jul 2008 23:18:03 GMT  
 Derived type PARAMETERs

...

Quote:
>     type(foo), parameter:: f = foo(1,42.,null())

And let me note that there is nothing at all in this syntax that is
actually unique to derived-type parameters. Basically, the syntax for
defining a derived-type parameter is the same as the syntax for
specifying any type of parameter, namely

   type-specification, parameter :: name = expression

(And you can alternatively use forms like the separate parameter
statement if you prefer - I don't.)

The only thing you migt not recognize here is the derived-type
constructor - the foo(1,42,null()) part. But I wanted to point out that
this is not special syntax for parameters. Constructors are just how you
write a derived type value in general, be it in a parameter definition
or anywhere else. If a constructor is in a parameter definition, it
"obviously" has to be constant (technically, an initialization
expression).

So my main message is that if you know how to define parameters at all,
and you know how to write a derived-type value using a constructor, then
you just put those together in the "obvious" way to define a
derived-type parameter; there are no special rules of note.

--
Richard Maine                     | Good judgment comes from experience;
email: my first.last at org.domain| experience comes from bad judgment.
org: nasa, domain: gov            |       -- Mark Twain



Sun, 20 Jul 2008 23:45:21 GMT  
 Derived type PARAMETERs

Quote:

> Is it possible to have a named constant (PARAMETER) of type specified
> by a derived type ?

> If so, what is the syntax ?

> Thanks in advance.

> Dave Flower

Many thanks to all who answered. I couldn't find the point in the
manual, but with your help have got it working.

Thanks again

Dave Flower



Mon, 21 Jul 2008 18:53:28 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Derived types with derived types with allocatables

2. Derived-type subcomponents of derived type

3. parameter statement for derived data type

4. derived types with parameter keyword

5. Type conversions forced by derived type: alternative?

6. Deriving abstract types from abstract types

7. allowed derived type component types

8. Derived types containing components of PRIVATE type

9. Access types vs. Record types as procedure parameters

10. Once-function with type derived from formal generic

11. discriminants and derived types Q

12. Derived Types, RM 3.4(11, 15)

 

 
Powered by phpBB® Forum Software