| Thread Tools | Search this thread |
|---|
riccardo42
| July 7, 2009 6:31 AM PDT Fortran 2003 C-interoperable code: possible wrong assembly generation by the compiler | ||||
Hi, I'm exploring the opportunities offered by the Fortran 2003 standard to create C-interoperable functions and subroutines and I stumbled in what seems like an error in the code generated by the compiler on a rather simple function. Here is the fortran module (lines marked as OPTIONAL can be commented without changing the behaviour of the code generated, I left them to give an idea of what my original test was): ----------- test_module.f90 --------------------------------------------------- And this is the C code used to call the fortran function: ------------- test.c ----------------- #include <stdlib.h> #include <stdio.h> #include "test_module.h" int main(int argc, char *argv[]) { double *testarray=NULL; int i; testarray=arrayfunc(10); for(i=0;i<10;i++) printf("Element %2d of the Fortran array: %g\n", i, testarray[i]); return 0; } --------------------------- The function arrayfunc (which should have allocated an array and passed it to the C function) is supposed to print it's "size" argument as the first action (10, which is to be received by value, as explicitly specified in the declaration), however both on ifort 10.1 (ia32) and ifort Version 11.1 (ia64) where I tested the code, the argument seems to be received incorrectly (in fact in the 64bit example, the variable seems to point to uninitialized memory...).
This is what happens with ifort 10.1 on my atom N270 (ia32): $ ./test and those are a couple of results on my Q9550 (ia64 with a 64bit ubuntu): $ ./test I have tested the same example with 2 other compilers on both computers and the result was, as expected, something like:
The size received is: 10 The code was interfaced with gcc-4.33 (although for what I know about assembly I'm rather positive it isn't relevant to the matter at hand) and the fortran code compiled in many different ways (as a shared library, as a simple object file, with/without debugging symbols, with/without optimization enabled and so forth...).
Now because I'm not coding in Fortran since a long while the fortran code might not be fit to my purpose, however I think there is still a glitch in the compiler that might be worth a bug report.
I read some documentation on this site and elsewhere about C-Fortran interfaces, but since I'm new to the task, any comment, suggestion or costructive critic will be highly appreciated.
Thank you for your time and patience, RiccardoPS: I apologize for the poor look of this post (I'm in the software network since half an hour and I'm not yet skilled with the composer :-) ) | |||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
| 8285 users have contributed to 31229 threads and 99106 posts to date. |
|---|
| In the past 24 hours, we have 16 new thread(s) 55 new posts(s), and 81 new user(s). In the past 3 days, the most popular thread for everyone has been comparison cilk++, openmp, pthreads first results The most posts were made to comparison cilk++, openmp, pthreads first results The post with the most views is Very amusing... Escalated as Please welcome our newest member tvinni |