(j3.2006) Did we intend to prevent this?

Robert Corbett robert.corbett
Wed Nov 9 01:29:51 EST 2011


Malcolm Cohen wrote:
>>>>
> So how is
>
>  type T
>    character(len=:), pointer :: P
>  end type T
>
>
>  character(len=42), target :: C2 = 'The value of C2'
>  character(len=24), target :: C3 = 'The value of C3'
>
>  type(t), parameter :: Z(2) = (/ t(c2), t(c3) /)
>
> different from
>
>  character(len=42), save, target :: A
>  character(len=:), pointer :: P => A
>
> which is clearly permitted?
> <<<
>
> This is not defining a compile-time value (a PARAMETER).
>
>>>>
> Why is it not permitted where the pointer association
> applies to a pointer component?
> <<<
>
> It is not a constant expression, and so cannot be used to define a 
> named constant, that has nothing to do with components and everything 
> to do with being (or not being) a constant!
>
>>>>
> How is it different from
>
>  character(len=42), save, target :: X
>  type :: U
>    character(len=:), pointer P => X
>  end type u
>  type(u) :: Y
>
> which is also clearly permitted?
> <<<
>
> Same answer.
>
> This isn't new, this isn't Fortran-specific: exactly the same things 
> apply to other compiled-and-separately-linked languages.  Addresses of 
> statically-linked procedures and saved variables are link-time 
> constants (and the values are indeed stored by the linker at link 
> time) they are not compile-time constants (so cannot be used for 
> compile-time constant expressions).
What about item (3)(b) in the definition of a constant expression, 
Clause 7.1.12, page 151?  The relevant pieces state

     It is an expression in which each operation is intrinsic, and each 
primary is

        (3) a structure constructor where each /component-spec/ 
corresponding to

            (b) a pointer component is an initialization target or a 
reference to the intrinsic function NULL

I could not find a definition of the term "initialization target," but 
it appears to mean an initialization that is an initial-data-target.

Bob Corbett



More information about the J3 mailing list