- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everybody!
Again I have some problems when I try to mixing codes written in fortran and C/C++.
I call a Fortran subroutine from a main program in C.
The passed arguments are structure type.
When I pass each argument separately, it works.
When I pass the structure, it doesn't work.
Should I do any change or declarationin my codes (Fortan and / or C/C++)?
Thanks in advance
MSantos
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
m.santos:Should I do any change or declarationin my codes (Fortan and / or C/C++)?
Most probably yes . But we cannot say anything useful unless you show us some code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The codes:
in C
extern __stdcall INFERE_C(struct GnStruct *,struct CvStruct *
,struct MvStruct *,struct DvStruct *
,struct AvStruct *,struct CviStructure *
,struct MviStructure *,struct AviStructure *);
INFERE_C(&ctrlPj[0].Gn,ctrlPj[0].Cv,ctrlPj[0].Mv,ctrlPj[0].Dv,ctrlPj[0].Av,Cvi,Mvi,Avi);
in Fortran
!DEC$ ATTRIBUTES EXPORT, STDCALL :: INFERE_C
!DEC$ ATTRIBUTES ALIAS:'_INFERE_C@32':: INFERE_C
Subroutine infere_c(Gn,Cv,Mv,Dv,Av,Cvi,Mvi,Avi)
I hope it is enough
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By the way, spelling out the entire ALIAS is often a bad idea; it tends to hide the problem rather than solve it. Instead, use:
!DEC$ ATTRIBUTES DECORATE, ALIAS: 'INFERE_C':: INFERE_C
In the debugger, you can always check the values of &ctrlPj[0].Gn on C side and LOC(Gn) on Fortran side upon entry -- if they don't match, you have a value/reference mismatch somewhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Unhappily I can rebuild my solution with this declaration.
In fact, my problem is related to an argument passed as value.
The arguments passed as reference have the same values in Fortran and C side.
Does anybody know why I have this problem?
Thanks
- 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
These codes are written and work in Visual Fortran 5.0 and C++ 6.0.
I am justtrying to convert them to Microsoft Visual Studio 2005 and Intel Fortran.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Intel compiler does not pass derived types by value the same way CVF did. It is an issue we are looking into. I recommend avoiding doing this if you can - pass them by reference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have done it.
Really is the best way.
Thanks for all.
MSantos
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page