Passing c arrays into fortran as a variable sized matrix

前端 未结 2 901
旧巷少年郎
旧巷少年郎 2021-01-19 15:19

So, i\'ve been commissioned to translate some fortran subroutines into C. These subroutines are being called as part of the control flow of a large porgram based primarily

相关标签:
2条回答
  • 2021-01-19 15:50

    What it shouldn't be that others suggested: 1. Size of int vs. size of Integer. Since the first column has the right values. 2. Row vs. column ordering. Would just get values in wrong order not segmentation faulted. 3. Reference vs value passing. Since the first column has the right values. Unless the compiler is doing something evil behind your back.

    Are you sure you don't do this in some secret way?:

       someCArray++
    

    print out the value of the someCArray pointer right after you make it and right before you pass it. You also should print it out using the debugger in the fortran code just to verify that the compiler is not generating some temporary copies to help you.

    0 讨论(0)
  • 2021-01-19 15:58

    Have you considered the Fortran ISO C Binding? I've had very good results with it to interface Fortran and C in both directions. My preference is to avoid rewriting existing, tested code. There are a few types that can't be transferred with the current version of the ISO C Binding, so a translation might be necessary.

    0 讨论(0)
提交回复
热议问题