- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,I'm trying to pass some complex data from a C to a Fortran program without success for the moment.I managed to reproduce the problem in the small example belowC code:[cpp]#include void func(float _Complex x); int main(){ func((float _Complex)_Complex_I); return 1; } [/cpp] Fortran code:[fortran]subroutine func(x) bind(c) use iso_c_binding complex(c_float_complex), value :: x write(*,*)'x:',x return end subroutine func[/fortran] The value of x printed is(0.0000000E+00,1.5932920E-10). Am I doing anything wrong here?Note that the same code works fine with GNU and IBM compilers. Moreover, if "float" is replaced with "double" in both sources, then it works ok.Can anybody help please?thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would be interesting to see if the soon-to-be-released 64-bit version of the Intel compiler also has this problem.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
$ cc -m32 -g -c cplx.c
$ ifort -g -nofor-main cplx.o cfun.f90
$ ./a.out
x: (0.0000000E+00,1.000000)
$
If you are running on an Apple-Mac, have you checked regarding the X-Code bugs and work-arounds?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would be interesting to see if the soon-to-be-released 64-bit version of the Intel compiler also has this problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This issue sounds vaguely familiar and I'll look to see if we know about this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Although this statement is correct in this specific example, I would not count on the assumption in general:
"if the argument is passed by reference instead of by value then everything works"
because in C complex variables are structures, whereas in Fortran COMPLEX is an INTRINSIC type. Since structures are subject to padding/packing, mismatches can occur even if passing is done by reference.
Secondly, I think that the question
"In this case this means that C codes compiled with different compilers may not be compatible, right?"
puts the blame on the wrong entity. On Linux, for good or bad, GCC sets the standard and, as far as I know, did not deviate from the ABI defined by AMD. Discrepancies such as in this problem, therefore, are attributable to Fortran compilers rather than C compilers. In fact, your code runs fine with GFortran.
I am sure that Intel will do the right thing, once the issue is tagged as a bug.
By the way, the code runs correctly on IA64 (IFort 11.1.072, GCC) and Windows-XP64 (IFort 11.1.067-X64, Microsoft C). On the latter platform, however, Microsoft C uses an ABI that is almost completely different from the AMD/INTEL ABI, so GCC and its conventions do not enter the picture.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I reported this defect to Development (internal tracking id noted below) and will keep both posts updated with new status as I learn it.
Thank you again mecej4 for isolation details and convenient reproducer.
(Internal tracking id: DPD200198349)
(Resolution Update on 10/14/2012): This defect is fixed in the Intel® Fortran Compiler XE Update 6 (12.1.0.233 - Linux)- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page