I have defined a type in a module as:
CHARACTER(LEN=:),ALLOCATABLE :: CA(:)
I then allocate the array as:
THen the string CA as:
Where CLEN, NUMUDCA, and NSIZE are all integers defined at runtime.
Looking at this in the debugger shows CA as an udefined pointer, but ERR=0 and checking ALLOCATED(UDCA(NUMUDCA+1)%CA) don't show any errors. The code seems to be able to set the string and print it out again. But using it as an argument to a subroutine crashes:
Any idea why?
RUnning with PSXE2016
The debugger is probably telling fibs. It does that, more often than not.
More code is required to diagnose the crash - ideally something runnable. Obvious questions - is `i` in the range of 1:NUDCASIZE, has the CA component of element `i` been allocated (you say "the string..." in a few places, but there are actually NUDCASIZE deferred length strings), what's the interface of SAVUDCA, ...
(Why a sequence type?)
To expand on what IanH asked, let us suppose for a moment that NUDCASIZE = 5 and NUMUDCA = 4. You allocate UDCA as an array with 5 elements. Then, you allocate "the" string array component CA of UDCA(5) as an array of NSIZE elements, each of which is a character(len=CLEN) variable. That would leave UDCA(1)%CA, UDCA(2)%CA, UDCA(3)%CA and UDCA(4)%CA undefined.
Along the same lines, without seeing the declarations of the argument list of your subroutine, it is impossible to state why the call caused a crash.
As you can see, you need to provide more details and be more precise in your description.
The value of I in the main program in the code in #4 is undefined.
One of the dummy arguments in the subroutine is assumed shape. An explicit interface is required for an assumed shape array, there is no such interface.
s:\lang>ifort /warn:all /check:all uam.f alloc.f Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 220.127.116.11 Build 20161005 Copyright (C) 1985-2016 Intel Corporation. All rights reserved. alloc.f(15): warning #6717: This name has not been given an explicit type. CALL SAVUDCA(NREC,UDCA(I)%CA,UDCA(I)%NLEN,NFILE) -------------------------------^ alloc.f(15): error #7978: Required interface for passing assumed shape array is missing from original source. [CA] CALL SAVUDCA(NREC,UDCA(I)%CA,UDCA(I)%NLEN,NFILE) ----------------------------------^ compilation aborted for alloc.f (code 1)