Question

That's what I want to do:

  type dataframe
     integer::a,d
     integer,dimension(:),allocatable::n
  end type dataframe

  type,extends(dataframe):: datafilled
     double precision,dimension(sum(n),d)::x
  end type datafilled

So the dataframe should be able to store the size information for its child datafilled. gfortran wants to know the type of n for compilation, but in my opinion it's already inherited. (Proof: If I define n in datafilled again, gfortran complains about the duplication.) How can I get it working?

Note: I declare n to be allocatable according to this question and because gfortran obviously doesn't yet support the len attribute of Fortran2003.

EDIT: OK, I admit I can do it with the allocatable attribute and allocate at each initialisation step later on.

Was it helpful?

Solution

There are constraints on what can be in a component array specification, that for non-allocatable/non-pointer components allow the specification to be evaluated at compile time (at the point that a type declaration for an object of the type being defined is encountered). Specifically, the value of a bound in the specification must not depend on the value of a variable - see C446 in F2008 for the details.

The component n in some object of type dataframe is a variable; calculating sum(n) requires its value; you are violating the constraint.

Length type parameters, even if your compiler supported them, can only be scalar.

As you've concluded - using an allocatable component, and allocating things correctly in some sort of construction procedure is the way to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top