codee-com/open-catalog

[Fortran] Replace `if (integer)` with `if (logical)`

Open

#38 aberto em 24 de set. de 2024

Ver no GitHub
 (2 comments) (2 reactions) (0 assignees)Fortran (12 forks)auto 404
Fortrangood first issuenew check

Métricas do repositório

Stars
 (105 stars)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

In Fortran there is no equivalence between logical and integer variables, so 0 is not a replacement for .false., and 1 does not replace .true.. Yet, some compilers (ifort) will happily compile if (1).

Example:

if (0) write(*, *) 'Test is false'
if (1) write(*, *) 'Test is true'

A slightly more meaningful example

integer val
val = 1
if (val) write(*, *) 'Test is true'

This should be replaced by

integer val
val = 1
if (val > 0) write(*, *) 'Test is true'

Guia do colaborador