[Fortran-Experiments] Nested interface blocks with Bind(c)

Christopher D. Rickett crickett@lanl.gov
Sat Feb 24 21:10:00 GMT 2007


hi all,

> There is something I don't understand. I have in symbol.c's
> check_conflict:
>
> conflict:
>   if (name == NULL)
> {
>     printf("%s attribute conflicts with %s attribute\n",a1, a2);
>     gfc_error ("%s attribute conflicts with %s attribute at %L",
>                a1, a2, where);
> }
>
> The gfc_error message is never shown while the printf prints:
>    BIND(C) attribute conflicts with DUMMY attribute

this has happened to me a number of times in the past, but i think i've
since fixed the cases i know about.  the problem seems to be that once
gfc_error is called, either the caller or someone in the caller's call
stack, must call gfc_error_check ().  if it's not called, the buffered
error won't get printed.  that's what's useful about gfc_error_now; it
will print the message immediately and not buffer it.

>
> the next gfc_error which is actually printed is:
>   Error: Syntax error in BIND(C) statement at (1)
> which is in decl.c's gfc_match_subroutine. All my gfc_warning/gfc_errors
> I used in decl.c's gfc_match_bind_c are also ignored.
>
>
> The error message
>    BIND(C) attribute conflicts with DUMMY attribute
> makes kind of sense since "func" is a dummy argument. How about
> something like the following, is that patch correct?

i'm wondering if the rejection of the code is wrong?  shouldn't the
parameter be type(c_funptr) to be interoperable?  if the code really is
valid, then i think the patch you have below is fine.

>
> Index: symbol.c
> ===================================================================
> --- symbol.c    (revision 122287)
> +++ symbol.c    (working copy)
> @@ -402,7 +402,9 @@
>
>    conf (function, subroutine);
>
> -  conf (is_bind_c, dummy);
> +  if (!attr->subroutine && !attr->function)
> +    conf (is_bind_c, dummy);
> +
>    conf (is_bind_c, cray_pointer);
>    conf (is_bind_c, cray_pointee);
>    conf (is_bind_c, allocatable);
>
>> i copied this code and tried it on my local gfortran and it produces the
>> following output:
>>
>> tobias1.f03:5.30:
>>
>>   FUNCTION glutCreateMenu(func) BIND(C,NAME="glutCreateMenu")
>>                              1
>> Error: BIND(C) attribute conflicts with DUMMY attribute at (1)
>>
> I really wonder why I don't get this error message, but it shows the
> problem. (I attached a patch which shows the name of the variable to
> bring gfc_add_is_bind_c more into line with the other gfc_add_*
> functions.)

i think you didn't get it because i've updated my error handling to make
better sure that buffered errors are reported.  i'll submit my patch in a
matter of minutes.

>
>
> Now, one needs to find out why:
>    integer :: glutCreateMenu
> triggers no warning and why the warning
>   Variable 'func' at (1) is a parameter to the BIND(C) procedure
> 'glutcreatemenu' but may not be C interoperable
> is printed.

i'm not sure why the warning for glutCreateMenu isn't being printed; i
think it is because the parameters are verified for interoperability
before the return type is, and since the parameters fail, the return type
isn't checked.  the warning about func possibly not being interoperable is
a side effect of it being reported as an error for having the BIND(C)
attribute.

Chris



More information about the Fortran mailing list