HELP Fortran treats my passed variables as a value

HELP Fortran treats my passed variables as a value

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

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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?

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

Jugoslav
www.xeffort.com

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

Retired 12/31/2016

"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

Retired 12/31/2016

!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

Jugoslav
www.xeffort.com

Leave a Comment

Please sign in to add a comment. Not a member? Join today