Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fortran] Replace if (integer) with if (logical) #38

Open
RRiva opened this issue Sep 24, 2024 · 2 comments
Open

[Fortran] Replace if (integer) with if (logical) #38

RRiva opened this issue Sep 24, 2024 · 2 comments

Comments

@RRiva
Copy link

RRiva commented Sep 24, 2024

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'
@inaki-amatria
Copy link
Contributor

Thank you so much for your valuable contribution!

Your example perfectly aligns with the broader efforts to modernize Fortran. And indeed, as you've pointed out, although these conditional expressions may not break compilation, they certainly lead to confusion and maintenance challenges.

We'd love for you to open a PR proposing a check for this in the Open Catalog. You can follow the guidance in #36 for adding new entries. Of course, if you'd prefer, just let us know, and we'll be happy to handle it!

@RRiva
Copy link
Author

RRiva commented Sep 25, 2024

Thanks @inaki-amatria 🙂 I don't think that I've more time to work on this, so I'll be happy if you can take over. The same goes for the other issues that I've opened 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants