- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
From the documentation https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-0/global-data.html I can see how to make global variables defined in Fortran accessible from C.
Is this possible the other way around? I.e. accessing a global variable defined in C from Fortran?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you tcu for the link to the solution and Steve for a thorough explanation!
I was expecting the Fortran declaration to look different depending on whether accessing a variable defined elsewhere or defining a variable that can then be accessed elsewhere (c.f. extern in C). So exactly the same point as for the person who had posted the linked question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That post is correct - in Fortran you declare a module variable (must be at module level and not in a procedure), and give it the BIND(C) attribute, specifying the case-sensitive name if not in all lowercase.) The standard says:
A C variable whose name has external linkage may interoperate with a common block or with a variable declared in the scope of a module. The common block or variable shall be specified to have the BIND attribute.
At most one variable that is associated with a particular C variable whose name has external linkage is permitted to be declared within all the Fortran program units of a program. A variable shall not be initially defined by more than one processor.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page