This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bizarre error with mixed C and Fortran


Bernd Lütkenhöner wrote:
Dear Janne,

Thank you so much for your help. It seems that you solved the problem.

double cx_(double *r)      /* called by FORTRAN routine f2 */
{
 r[0] = 1;
 r[1] = 2;
 r[2] = 3;
}

c***************************************/
c*  The FORTRAN module                 */
c***************************************/

c  calling C-routine cx causes a problem,
    call cx (r)

After replacing 'double cx_' by 'void cx_', at least my simple test suite works fine now.

Alternatively, you could try the -ff2c command line argument. This should give g77 compatible calling conventions in all corner cases.


I'm still surprised by this error. The only explanation I have is that doubles are returned by an additional hidden argument that is appended to the argument list in the -ff2c case and via the stack in the non-ff2c case. The latter could create troubles if the C code is not aware.

Cheers,
- Tobi

The original software consist of hundreds of Fortran and C routines, and it worked fine on different machines for more than 15 years. But GCC is evidently more meticulous than the compilers I used before. Of course, I always thought that the error would be in my code. But in the end, the test suite was apparently too simple to notice the problem. ;-)

Thanks again
   Bernd



--
Tobias Schlüter
Am Coulombwall 1, Zi. 326
85748 Garching b. München
Tel.: +49/89/289-14139


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]