named constants (parameter attribute) in derived data type fortran 90 -


it seems fortran 90 not allow named constants in derived data types. true? not work.

program my_prog implicit none    type :: my_type       integer, parameter :: = 1       real(kind(1.d0))   :: b    end type my_type    type (my_type) :: complex_type end programmy_prog 

the compiler says parameter statement not permitted in derived type definitions. when remove parameter keyword works fine. how can make sure 'a' not modified elsewhere?

according standard, not allowed. component attribute specifier may pointer, , dimension fortran 90/95 (section 4.4.1), additionally allocatable in fortran 2003 (section 4.5.3), , additionally codimension, , contiguousfor fortran 2008 (section 4.5.4.1).

you can documents here.

i ran similar problem target specifier, not allowed.

edit: why not try private components?

module typedef   type :: my_type     integer, private :: a_int = 1     real(kind(1.d0)) :: b   contains     procedure ::   end type my_type  contains   function a(complex_type)     class(my_type),intent(in) :: complex_type     integer ::     = complex_type%a_int   end function end module  program my_prog   use typedef   implicit none    type (my_type) :: complex_type    complex_type%b = 2.d0 ! should work   write(*,*) complex_type%a(), complex_type%b  !  complex_type%a_int = 3    ! should fail  end program my_prog 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -