Next: , Previous: KIND Type Parameters, Up: Compiler Characteristics


5.2 Internal representation of LOGICAL variables

The Fortran standard does not specify how variables of LOGICAL type are represented, beyond requiring that LOGICAL variables of default kind have the same storage size as default INTEGER and REAL variables. The GNU Fortran internal representation is as follows.

A LOGICAL(KIND=N) variable is represented as an INTEGER(KIND=N) variable, however, with only two permissible values: 1 for .TRUE. and 0 for .FALSE.. Any other integer value results in undefined behavior.

Note that for mixed-language programming using the ISO_C_BINDING feature, there is a C_BOOL kind that can be used to create LOGICAL(KIND=C_BOOL) variables which are interoperable with the C99 _Bool type. The C99 _Bool type has an internal representation described in the C99 standard, which is identical to the above description, i.e. with 1 for true and 0 for false being the only permissible values. Thus the internal representation of LOGICAL variables in GNU Fortran is identical to C99 _Bool, except for a possible difference in storage size depending on the kind.