This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/36759] C_LOC and characters greater then one in length.
- From: "burnus at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Jul 2008 22:41:42 -0000
- Subject: [Bug fortran/36759] C_LOC and characters greater then one in length.
- References: <bug-36759-16432@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #1 from burnus at gcc dot gnu dot org 2008-07-07 22:41 -------
> A = c_loc(arg1)
> 1
> Error: CHARACTER argument 'arg1' to 'c_loc' at (1) must have a length of 1
>
> I'm not sure where this restriction comes from (it's not part of the standard).
One could argue that one should allow it as vendor extension, however, the
restriction is in the standard:
"Interoperability of intrinsic types"
"A Fortran intrinsic type with particular type parameter values is
interoperable with a C type if the type and kind type parameter value are
listed in the table on the same row as that C type; if the type is character,
interoperability also requires that the length type parameter be omitted or be
specified by an initialization expression whose value is one."
For interoperability one thus should use instead of
character(len=2) :: str
rather
character(len=1,kind=c_char) :: str(2)
(This is also the case for dummy arguments of BIND(C) procedures, though there
one can as pass "a string" as actual argument, cf. "storage sequence".)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36759