codee-com/open-catalog

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

Open

#38 建立於 2024年9月24日

在 GitHub 查看
 (2 留言) (2 反應) (0 負責人)Fortran (12 fork)auto 404
Fortrangood first issuenew check

倉庫指標

Star
 (105 star)
PR 合併指標
 (PR 指標待抓取)

描述

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'

貢獻者指南