[Patch, Fortran] PR55758 - Non-C_Bool handling with BIND(C)

Tobias Burnus burnus@net-b.de
Thu Dec 27 22:31:00 GMT 2012


Dear all,

See also the discussion in the thread starting at 
http://gcc.gnu.org/ml/fortran/2012-12/msg00135.html

a) The Fortran standard only defines LOGICAL(kind=C_Bool) as being 
interoperable with C - no other LOGICAL type. That matches GCC: With gcc 
(the C compiler) only _Bool is a BOOLEAN_TYPE with TYPE_PRECISION == 1. 
Hence, this patch rejects other logical kinds as dummy argument/result 
variable in BIND(C) procedures if -std=f2003/f2008/f2008ts is specified 
(using -pedantic, one gets a warning).

b) As GNU extension, other logical kinds are accepted in BIND(C) 
procedures; however, as the main use of "LOGICAL(kind=4)" (for BIND(C) 
procedures) is to handle logical expressions which use C's int, one has 
to deal with all integer values and not only 0 and 1. Hence, a normal 
integer type is used internally in that case. That has been done to 
avoid surprises of users and hard to trace bugs.

Note: logical(c_bool) and all logicals which are not dummy or result 
variables of a bind(C) procedure remain BOOLEAN_TYPEs  with 
TYPE_PRECISION == 1 bit. For those a .true. with internal value "-1" 
will lead the surprising result .not.(-1) => (-2) => .true., i.e. .true. 
== .not. .true. But that's simply an invaliduse of those logicals and 
not a bug in the compiler. (-> won't fix).


Build and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: c-bool.diff
Type: text/x-patch
Size: 6858 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20121227/598b2706/attachment.bin>


More information about the Gcc-patches mailing list