- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.)
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.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
I was confused by the various 'references' to the word REFERENCE and VALUE in the help and the use in the DEC$ statement.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page