User account creation filtered due to spam.

Bug 47605 - Document that C_Bool might be the wrong constant for C Booleans
Summary: Document that C_Bool might be the wrong constant for C Booleans
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: documentation
Depends on:
Blocks:
 
Reported: 2011-02-04 07:17 UTC by Tobias Burnus
Modified: 2015-08-31 05:31 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-03-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-02-04 07:17:13 UTC
James pointed out the following at
http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/3c2784c55d402ced

c_bool is typically one byte wide, and c_int 4. That means: Most C programs - except of those few which explicitly use _Bool, use a 4 byte and not a 1 byte Boolean variables.

I think one should put a warning into the manual - either in the C Binding part [1] or in the section about the ISO C Binding constants [2], or in both.

[1] http://gcc.gnu.org/onlinedocs/gfortran/Intrinsic-Types.html
[2]http://gcc.gnu.org/onlinedocs/gfortran/ISO_005fC_005fBINDING.html
Comment 1 Dominique d'Humieres 2014-03-22 19:34:16 UTC
In [1] I see

> For logical types, please note that the Fortran standard only guarantees
> interoperability between C99's _Bool and Fortran's C_Bool-kind logicals and C99
> defines that true has the value 1 and false the value 0. Using any other integer
> value with GNU Fortran's LOGICAL (with any kind parameter) gives an undefined
> result. (Passing other integer values than 0 and 1 to GCC's _Bool is also
> undefined, unless the integer is explicitly or implicitly casted to _Bool.)

What should be added to that?
Comment 2 Dominique d'Humieres 2015-08-31 05:31:12 UTC
> > For logical types, please note that the Fortran standard only guarantees
> > interoperability between C99's _Bool and Fortran's C_Bool-kind logicals and C99
> > defines that true has the value 1 and false the value 0. Using any other integer
> > value with GNU Fortran's LOGICAL (with any kind parameter) gives an undefined
> > result. (Passing other integer values than 0 and 1 to GCC's _Bool is also
> > undefined, unless the integer is explicitly or implicitly casted to _Bool.)
>
> What should be added to that?

No answer for over a year. Closing as FIXED.