Skip to content

Instantly share code, notes, and snippets.

@jeffhammond
Forked from certik/README.md
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffhammond/9746080 to your computer and use it in GitHub Desktop.
Save jeffhammond/9746080 to your computer and use it in GitHub Desktop.

Compile using either of:

./compile_gnu

and you should get the result:

           3 T F
true -> false
           3 F T
false -> true
Done.

Now compile using Intel:

./compile_intel

and you get the result:

           3 T F
true -> true
           3 F T
false -> true
Done.

Which is incorrect. Enable -fpscomp logical in compile_intel, recompile, then you get:

           3 T F
true -> false
           3 F T
false -> true
Done.
module a
use iso_c_binding, only: c_int, c_bool
implicit none
private
public foo
contains
subroutine foo(n, relat, relat_out) bind(c, name="foo")
integer(c_int), intent(in), value :: n
logical(c_bool), intent(in), value :: relat
logical(c_bool), intent(out) :: relat_out
relat_out = .not. relat
print *, n, relat, relat_out
end subroutine
end module
# you can only find Cray compilers on a Cray machine...
module load PrgEnv-cray
module swap PrgEnv-intel PrgEnv-cray
module swap PrgEnv-gnu PrgEnv-cray
module swap PrgEnv-pgi PrgEnv-cray
cc -V
cc -o m.o -c m.c
ftn -o a.o -c a.f90
cc m.o a.o -o cray
gcc -o m.o -c m.c
gfortran -o a.o -c a.f90
gcc m.o a.o -lgfortran -o gnu
xlc -o m.o -c m.c
xlf2003 -o a.o -c a.f90
xlc m.o a.o -lxlf -o ibm
icc -o m.o -c m.c
#ifort -fpscomp nologicals -o a.o -c a.f90
ifort -o a.o -c a.f90
icc m.o a.o -lifcore -o intel
pgcc -o m.o -c m.c
pgf90 -o a.o -c a.f90
pgcc m.o a.o -pgf90libs -o pgi
#include <stdio.h>
#include <stdbool.h>
void foo(int n, bool relat, bool *relat_out);
int main()
{
bool relat_out;
foo(3, true, &relat_out);
printf("true -> %s\n", relat_out ? "true" : "false");
foo(3, false, &relat_out);
printf("false -> %s\n", relat_out ? "true" : "false");
printf("Done.\n");
return 0;
}
@jeffhammond
Copy link
Author

As I noted through another channel, Bill is correct and my attempts to test Cray's behavior were at first flawed.

@certik
Copy link

certik commented Mar 25, 2014

Thanks everybody for testing this! Conclusion: gfortran, Cray, IBM work. Intel and PGI need an extra option to work.

I've documented this behavior here:

http://www.fortran90.org/src/gotchas.html#c-fortran-interoperability-of-logical

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