Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29264 Discussions

HELP Fortran treats my passed variables as a value

scottgrossman
Beginner
860 Views
First of all thanks to everyone who helped me get this far. I finally got my test program to the point where it executes, but for some reason the address I'm passing from my C routine to the fortran subroutine is being treated as a value not an address.

Ive attached the 2 test files below
Any thoughts would be appreciated.


Thanks again
Scott

0 Kudos
5 Replies
isn-removed200637
860 Views
You forgot to add the INTERFACE block in the SUBROUTINE code.
An explicit interface is apparently a requirement for this to work. Try the following (after editing out the
blanks and the
s that the forum software is adding at random!!!! - PLEASE GET THIS FIXED!!!):

SUBROUTINE ENGAGEABILITY_INIT(int1)

interface 

subroutine FORTRANTEST(int1)

!DEC$ ATTRIBUTES C, ALIAS:'_ENGAGEABILITY_INIT@4' ::
ENGAGEABILITY_INIT

integer int1

end subroutine FORTRANTEST

end interface

! Expose subroutine Fortran to users of this DLL

!DEC$ ATTRIBUTES DLLEXPORT:: ENGAGEABILITY_INIT

integer int1

int1 = int1 + 10

return

END SUBROUTINE ENGAGEABILITY_INIT


The above works for me using the Compaq VF compiler.

P.S. to Steve Lionel, when I change the double-underline
'__stdcall' in the EXTERNAL 'C' statement in the C++ code
to a single underline, there is no apparent change in
behaviour and no compiler objections. SO, what is the
point of the double as opposed to single underline?
0 Kudos
Jugoslav_Dujic
Valued Contributor II
860 Views
!DEC$ATTRIBUTES C changes the default argument-passing mechanism to by-value. If you want it to be by reference, specify REFERENCE attribute as well.

See "ATTRIBUTES" entry in Programmer's guide for detailed explanation, especially C, STDCALL, VALUE and REFERENCE attributes. Interactions between these are a bit complicated (the latter two can be specified for routine and/or for its arguments, with slightly different semantics), so read it carefully.

Jugoslav
0 Kudos
Jugoslav_Dujic
Valued Contributor II
860 Views
Feel frustrated by the Forum Tony? I sympathize with you. FYI, your post ended up in the wrong thread; you probably wanted to respond to matthewkmk.

Jugoslav
0 Kudos
Steven_L_Intel1
Employee
860 Views
The forum vendor has been informed of the problems here - I have no idea what triggered them, some change that was evidently made late last week... Sorry for the inconvenience, it annoys me as much as it does you.

Steve
0 Kudos
Steven_L_Intel1
Employee
860 Views
"P.S. to Steve Lionel, when I change the double-underline
'__stdcall' in the EXTERNAL 'C' statement in the C++ code
to a single underline, there is no apparent change in
behaviour and no compiler objections. SO, what is the
point of the double as opposed to single underline?"

You're asking me a C++ question? :-)

As far as I understand, __stdcall, with two underscores, is the way you spell this in Visual C++. I think the two-underscores is a convention to avoid conflicts with user macros, but maybe a single underscore macro is also defined. Dunno.

Steve
0 Kudos
Reply