https://gcc.gnu.org/bugzilla/show_bug.cgi?id=41227

--- Comment #22 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to rguent...@suse.de from comment #19)
> > Well, Bill Long of Cray seems to agree with my interpretation, cf.
> > http://mailman.j3-fortran.org/pipermail/j3/2010-February/003358.html
> 
> But that answer suggests we get it wrong (currenty interoperating
> with the C struct { int i; } works and with the plain decl it
> doesn't).  The answer specifically doesn't say that only (1)
> is valid.

As I stumbled over it again (and missed what I wrote 5 years ago in comment 0):
One also needs to distinguish between common blocks with and without BIND(C). 


The Fortran standard only defines interoperability with C with Fortran 2003's C
binding ("BIND(C)"). Thus, "external int i" interoperates with
  use iso_fortran_env, only: c_int
  integer(c_int) :: j
  common /i/ j
  bind(C) :: /i/
and for this construct, "struct {int i}" does not have to interoperate with it
according to the standard. If the front-end produces the wrong code in this
case, one can simply fix it. Seems as if we have to do this, including the
output DWARF.

[By the way, I assume that there is essentially no code out there, which uses
BIND(C) with COMMON: Either it is pre-Fortran-2003 code - or it uses modules
where one avoids all those issues with COMMON and either has "integer, bind(C)
:: i" or "type(t), bind(C) :: i" and no ambiguity.]


The other case is legacy code: There, programs can make the wildest assumptions
what C code should interoperable with Fortran. See also T.S.'s comment 20.
Seems as if a simple "struct" was the most common assumption - with a nonstruct
being effectively interoperable with a one-variable struct; hence, also the
latter seems to be used.

Reply via email to