Skip to content

Commit b577aa8

Browse files
committed
Fortran does not guarantee logical AND short circuit
1 parent 2f89002 commit b577aa8

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

DEVELOPER_NOTES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,4 +929,11 @@ The problem is reported in https://llvm.org/bugs/show_bug.cgi?id=14713
929929
through the ncmpio driver directly.
930930
931931
---
932+
### Note on Fortran programming
933+
* Unlike C, the Fortran standard does not mandate or prohibit short-circuit
934+
evaluation for logical expressions. Thus, Fortran does not guarantee that
935+
the .AND. operator will skip evaluating the second logical expression if
936+
the first one is false. See PR #189.
937+
938+
---
932939

test/nf_test/test_write.F

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,20 @@ subroutine test_nfmpi_abort()
539539
err = nfmpi_inq_file_info(ncid, infoused)
540540
if (err .eq. NF_NOERR) then
541541
call MPI_Info_get(infoused, "nc_burst_buf",
542-
+ MPI_MAX_INFO_VAL, hint, flag, err)
543-
if (flag .AND. hint .EQ. 'enable') then
544-
err = nfmpi_flush(ncid)
545-
if (err .ne. NF_NOERR)
546-
+ call errore('nfmpi_flush: ', err)
542+
+ MPI_MAX_INFO_VAL-1, hint, flag, err)
543+
! The Fortran standard does not mandate or prohibit
544+
! short-circuit evaluation for logical expressions.
545+
! Fortran does not guarantee that the .and. operator will
546+
! skip evaluating the second logical expression if the
547+
! first one is false.
548+
!
549+
! if (flag .AND. hint .EQ. 'enable') then
550+
if (flag) then
551+
if (hint .EQ. 'enable') then
552+
err = nfmpi_flush(ncid)
553+
if (err .ne. NF_NOERR)
554+
+ call errore('nfmpi_flush: ', err)
555+
endif
547556
endif
548557
call MPI_Info_free(infoused, err);
549558
endif

0 commit comments

Comments
 (0)