I have a derived-type with pointer (or allocatable) component
type Tmy
real, dimension(:), pointer :: vals
integer :: nVals
end type Tmy
And I want to create a parameter, e.g. to pass it to a subroutine as intent(in):
type (Tmy), parameter, public :: my_missing = Tmy(null(), 0)
Currently a similar code compiles fine to me by GNU Fortran (Spack GCC) 9.4.0, but introduction of the parameter triggers numerous strange errors in another module that uses the current one. The using module has variables of the type, but no reference to the parameter. The first error is triggered in a derived-type declaration with default initialization:
550 | logical, dimension(:,:), pointer :: ifValid => null()
| 1
Error: Cannot change attributes of USE-associated symbol null at (1)
and follows by numerous similar errors and complains about missing members in various structures. If I comment out the parameter declaration the code compiles and runs just fine.
So the questions are:
- How introducing a parameter in one module can trigger compilation errors in another module, given that the name my_missing is unique within the project? Or is it just a bug in the compiler?
- Is introducing such a parameter a valid practice in Fortran?
- If it is valid, what is the effect of assigning this parameter to a structure that has
valsalready allocated (in case if vals is declared as allocatable)?
PS Yes, I know that allocating pointers is a bad idea. I try to turn them to allocatables bit by bit..
UPD: The issue is reproducible with two different versions of gfortran, but only at one specific computer. Also I did not manage to compile any observable MWE so far..
UPD2: Thank you all, who commented so far. It seems clear that there is no breaking of Fortran standards in my examples here. MWE is of little use since the issue is reproducible only at one computer. I'll then ask for help from our HPC staff and come back once something interesting found.
nullin line 550 refers to a symbol use associated from OP's own code, rather than the intrinsic routine. I can't see anything wrong in the declaration statement for the parameter, but I am not a Fortran compiler. Perhaps try with a more recent version of the compiler, or another compiler entirely? It wouldn't surprise me to find that OP is exercising a very dusty, and rarely visited, corner of the language specification, one for which compiler support is hitherto little tested in the field.Null. Is there anything in the code calledNull? But really, a minimal example would help soooo much. And BTW in Fortran we normally call them arguments rather than parameters.parameterconstants need to be determined at compile time, and allocation does not go with that.