------- Comment #4 from mikael at gcc dot gnu dot org  2009-01-06 21:16 -------
(In reply to comment #2)
> > The line:
> >   TYPE(C_PTR), INTENT(IN) :: CPTR ! The C address
> > should be:C_F_STRING(CPTR)
> >   TYPE(C_PTR), VALUE, TARGET:: CPTR ! the C address
> 
> You are right. The call to strlen is OK in either case, however, the call to
> C_F_POINTER() does not make sense for a pointer to a C string ("**char") only
> for the version with VALUE ("*char") as fptr should finally contain the 
> string.
> 

For TARGET, I agree because the standard says about c_f_pointer:
   The value of CPTR shall not be the C address of a Fortran variable that does
   not have the TARGET attribute.

However, for VALUE, I fail to understand what is wrong.
Without value, the code generated is:
c_f_string (struct array1_unknown & __result, integer(kind=4) .__result, void *
& cptr)
{
    (...)
    (*(integer(kind=4)[1] *) atmp.0.data)[0] = strlen (*cptr);
    (...)
    c_f_pointer_s0 (*cptr, (struct array1_unknown *) __result, &atmp.3, 1);
}

With value:
c_f_string (struct array1_unknown & __result, integer(kind=4) .__result, void *
cptr)
{
    (...)
    (*(integer(kind=4)[1] *) atmp.0.data)[0] = strlen (cptr);
    (...)
    c_f_pointer_s0 (cptr, (struct array1_unknown *) __result, &atmp.3, 1);
}

Both seem equally good, aren't they?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35612

Reply via email to