Your function doesn't return an array of pointers, it returns an array of characters of length 16. You may be assigning the return value to a pointer or allocatable variable of a rank 1 array character(len=16), but that is a separate issue.
A function returning an array needs an explicit interface. It isn't clear from your question if this requirement has been met and this can be accomplished three ways:
- put the function in a module (easiest!)
- put the function in the main program after a
contains statement
- write an interface block for the function in the scoping unit is used in.
For example:
module A
contains
function f(n)
implicit none
integer :: n
character(len=16) :: f(n)
f(1:n) = 'DEFAULT'
end function f
end module A
program test
use A
implicit none
character(len=16), pointer :: array(:)
allocate(array(10))
array = f(10)
print *, array
end program test
This puts your function within module 'A' as is with slight the addition of implicit none statement, which you should be using. Unlike C, Fortran will let you use variables without declaring them and implicitly assign types to them, which rears its ugly head when a typo creates a new variable and a debugging nightmare. implicit none tells the compiler to only use variables you declare.
The main program in the example above stores the return value of function in a pointer to a character array. The return value is not simply N*16 bytes because, unlike C, Fortran strings contain some metadata, including the length (and are not null terminated). The array itself will have an array descriptor internally that stores information on the array bounds, dimensions and some other information, so the overall allocation will be for at least N*(16+character scalar overhead)+array descriptor length. A bit more is going on under the hood than in C.
A last point to note, the variable f of the same name of the funtion f is the type of the function and its return value. This will be in scope when the function returns and the memory will be copied into the allocated memory of array. A final potential issue you might run into as a C programmer is that Fortran passes arguments by reference. This isn't an issue here, but later on this might crop up if you assumed pass by value like C does.