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

Tobias Burnus burnus@net-b.de
Sat Feb 24 12:18:00 GMT 2007


Hi,

Christopher D. Rickett wrote:
>> INTERFACE
>>   FUNCTION glutCreateMenu(func) BIND(C,NAME="glutCreateMenu")
>>     use iso_c_binding
>>     INTEGER :: glutCreateMenu
>>     INTERFACE
>>       SUBROUTINE func() BIND(C)
>>       END SUBROUTINE func
>>     END INTERFACE
>>   END FUNCTION glutCreateMenu
>> END INTERFACE
>> END MODULE OpenGL_glut
>>
>> test3.f90:9.31:
>>       SUBROUTINE func() BIND(C)
>>                               1
>> Error: Syntax error in BIND(C) statement at (1)
>>     
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

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?

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.)


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.

Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fort-exp-add_bindc.diff
Type: text/x-patch
Size: 3361 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070224/b3cc45be/attachment.bin>


More information about the Fortran mailing list