Assume a C or C++ program wishes to send/receive logical(C_BOOL) from a fortran procedure. This is broken with NVHPC at least 24.3. The issue is when .not. doesn’t properly invert the value since NVHPC designates logical as odd and even per the reference manual instead of 1 and 0 like other compilers.
nvfortran reference guide:
The logical constants .TRUE. and .FALSE. are defined to be the four-byte values -1 and 0 respectively.
A logical expression is defined to be .TRUE. if its least significant bit is 1 and .FALSE. otherwise.
MWE
nvfortran -c c_bool.f90
nvc c_bool.o c_bool.c
./a.out.
# results in failure
c_bool.c:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
bool logical_not(bool);
int main(void) {
int c = 0;
bool b = true;
b = logical_not(b);
if(b){
fprintf(stderr, "not(true) != false\n");
c++;
}
b = logical_not(b);
if(!b){
fprintf(stderr, "not(false) != true\n");
c++;
}
if(c){
fprintf(stderr, "ERROR: C_BOOL\n");
return EXIT_FAILURE;
}
printf("OK: C_BOOL\n");
return EXIT_SUCCESS;
}
c_bool.f90
module dummy
use, intrinsic :: iso_c_binding, only: C_BOOL
implicit none
contains
logical(C_BOOL) function logical_not(L) bind(C)
logical(C_BOOL), intent(in), value :: L
logical_not = .not.L
end function logical_not
end module dummy