https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71412
--- Comment #3 from kargl at gcc dot gnu.org --- (In reply to relliott from comment #2) > > I believe gfortran's behavior conforms to the standard. F2003 states > > > > When the execution of a procedure is terminated by execution > > of a RETURN or END statement, an allocatable variable that is > > a named local variable of the procedure retains its allocation > > and definition status if it has the SAVE attribute or is a > > function result variable or a subobject thereof; otherwise, it > > is deallocated. > > > > val is a local variable. val does not have the SAVE attribute. > > If that is the case, how should the desired result be achieved in a standard > conformant way? Ahem, give val the SAVE attribute. integer(c_int), pointer, save :: val