Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Use of REFERENCE in an INTERFACE block

AndrewC
New Contributor III
496 Views
I feel completely clueless here but I keep getting a syntax error when trying to define access to a C function that takes a variable by reference. What am I missing?
Not an attribute-spec keyword [REFERENCE]


INTEGER*4 FUNCTION TEST
INTERFACE
INTEGER*4 FUNCTION C_TEST(a,b) BIND(C, NAME="_ctest")
INTEGER*4 , REFERENCE :: a
INTEGER*4 , REFERENCE :: b
END FUNCTION C_TEST
END INTERFACE
INTEGER*4 I,J
I=1
J=2
TEST = C_TEST(I,J)
RETURN
END

INTEGER*4 FUNCTION TEST2
INTERFACE
INTEGER*4 FUNCTION C_TEST2(a,b) BIND(C, NAME="_ctest2")
INTEGER*4 , VALUE :: a
INTEGER*4 , VALUE :: b
END FUNCTION C_TEST2
END INTERFACE
INTEGER*4 I,J
I=1
J=2
TEST2 = C_TEST2(I,J)
RETURN
END


0 Kudos
2 Replies
Steven_L_Intel1
Employee
496 Views
REFERENCE is not a Fortran language attribute. VALUE is. You do not need a REFERENCE attribute - arguments are passed by reference unless you say VALUE.

Note that this is different behavior from using the !DEC$ ATTRIBIUTES directive to specify the C calling mechanism, where the default mechanism (in most but not all cases) changes to "value" and a REFERENCE keyword is supported.

You should remove the REFERENCE keyword and also the leading underscore in the NAME= specifier, as the compiler will apply the same default decoration as the C compiler would. (Certain 10.1 compilers got this wrong, but it's been fixed for several months now.)
0 Kudos
AndrewC
New Contributor III
496 Views
Thanks! I knew it had to be something obvious.
I was confused by the various 'references' to the word REFERENCE and VALUE in the help and the use in the DEC$ statement.
0 Kudos
Reply