- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Hopefully this should be easy...
I'm using fortran to call a c++ function.
This function returns the value 2 as a long - debugging shows this being set
But when it comes back into my integer4 fortran variable I see the return value as -2147483648
Any thoughts about what might be going wrong?
Very grateful for any assistance.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
But does the Fortran compiler "know" that SIDGETLANECT is an integer function?
If you do not declare it as such, via an interface block for instance, the default typing rules kick in an the function will be considered to return a floating-point number.
Try:
interface
integer function SIDGETLANECT(origin)
integer, value :: origin
end function
end interface
or the like
링크가 복사됨
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Can you show the code? It is very likely a mismatch in the interface as seen from both sides.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
fortran looks like:
INTEGER*4 LNS
LNS = SIDGETLANECT(%val(J2))
c++
long __stdcall SIDGETLANECT(long origin)
{
CComPtr<ISIAPILegs> legs = NULL;
CComPtr<ISIAPILeg> leg = NULL;
CComPtr<ISIAPILaneApproachs> laneApprs = NULL;
CComPtr<ISIAPILaneApproach> laneAppr = NULL;
long b;
site->get_Legs(&legs);
legs->get_Count(&b);
leg = NULL;
legs->get_Item(long (origin - 1) , &leg);
if (leg == NULL) return 0;
else
{
long laneApprCount, laneno;
VARIANT_BOOL laneDisciplineExisting = false;
leg->get_LaneApproachs(&laneApprs);
laneApprs->get_Count(&laneApprCount);
return laneApprCount ;
}
}
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
But does the Fortran compiler "know" that SIDGETLANECT is an integer function?
If you do not declare it as such, via an interface block for instance, the default typing rules kick in an the function will be considered to return a floating-point number.
Try:
interface
integer function SIDGETLANECT(origin)
integer, value :: origin
end function
end interface
or the like
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
You should also declare the C++ function as
extern "C" { long SIDGETLANECT(long origin); } // function prototype
See the IVF documentation: C/C++ Naming Conventions.
See also section under BIND
Jim Dempsey
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Sorry, its after midnight here and I probably should have also mentioned that
the c++ function is in a separate library
and
that it has a .h function declaration
extern "C" long __stdcall SIDGETLANECT(long origin);
I will take a look at the interface definition in the morning
Thanks for your input
Jim
