[Patch, Fortran] Add -Wc-binding-type warning

Tobias Burnus burnus@net-b.de
Sat Mar 3 14:23:00 GMT 2012


GNU Fortran warns by default for code like the following:

interface
   subroutine sub (n)  bind (C)
     integer :: n
   end subroutine sub
end interface

Namely, it prints:

Warning: Variable 'n' at (1) is a parameter to the BIND(C) procedure 
'sub' but may not be C interoperable


That's on one hand correct: There is no defined relation between Fortran 
default kinds (or any kind number) and the C types. Thus, the proper way 
is to use the parameters defined in ISO_C_BINDING, such as "c_int".

On the other hand, "integer" and "int" is the same on many (but not on 
all systems) and, thus, many users simply use the default type.

Compiling interfaces with hundreds of such definitions clutters the 
screen with those warnings and makes it difficult to spot other warnings.

Thus, this patch adds a warning flag for this purpose - and it also 
excludes those warnings from the default setting. That's a bit in line 
with Fortran 2008 and TS 29113, which remove more and more constraints 
and force the users to ensure themselves that the variables are 
interoperable. However, keeping it as default warning is also fine with me.

Build and regtested on x86-64-linux.
OK?

Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Wc-binding-type.diff
Type: text/x-patch
Size: 11814 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20120303/6a19ef81/attachment.bin>


More information about the Fortran mailing list