Regarding the base addresses of zero-sized arrays, there are two guides available:
1) In TS 29113 (Further C interp - integrated into f2015) the discussion of the base address of an array descriptor allows for zero-sized objects and requires that the address in a value different from NULL. This allows a NULL pointer to distinguish an unallocated allocatable or disassociated pointer (represented by a NULL bas address) from an object that is allocated but just has zero size (or a pointer associated with a target of zero size).
2) The scheme in (1) is consistent with the expectations of normal zero-sized objects in Fortran. It they are part of a storage sequence, basically they have the address of the next thing in the sequence that is not zero-sized. Even outside a storage sequence, variables are stored somewhere in memory (stack, heap, …) and a reasonable implementation would be to follow similar rules. Try this program, for example:
program zero
use,intrinsic :: iso_c_binding, only: c_loc
real,dimension(1:0),target :: a,b
real,target :: c(10)
print *, "sizes of a, b, c: ",size(a), size(b), size(c)
print *, "loc of a, b, c : ",c_loc(a), c_loc(b), c_loc(c)
end program zero
> gfortran test.f90
> ./a.out
sizes of a, b, c: 0 0 10
loc of a, b, c : 140734155586880 140734155586880 140734155586832
Cheers,
Bill
On Oct 30, 2014, at 5:30 PM, Neil Carlson <[log in to unmask]> wrote:
> Hello all,
>
> I'm tracking down some mysterious platform-dependent problems and am wondering just how
> interoperable 0-sized arrays are with C. For example,
>
> void func (int *array, ...)
>
> interface
> subroutine func (array, ...) bind(c)
> integer(c_int) :: array(*)
> end subroutine
> end interface
>
> Will this work with 0-sized actual arguments? Of course I'm assuming
> that the C pointer will never be de-referenced in this case. Basically,
> I'm wondering if some sensibly-valued address gets passed.
>
> And more specifically, does C_LOC return some sensible dummy value for a 0-sized array argument, again with the caveat that you shouldn't attempt to use it for anything.
>
> Thanks,
> Neil
>
Bill Long [log in to unmask]
Fortran Technical Suport & voice: 651-605-9024
Bioinformatics Software Development fax: 651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101
|