- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm currently developing a static library in Fortran containing common blocks. These COMMONswill be accessed from C++ application, that links the fortran library. As the C++ app requirement is that the data from extern "C" is aligned by 1 byte, I was hoping to set this in VF11 compiler settings, however I have only found /allign: commons (4 bytes) and/allign: dcommons (8 bytes). Is there a different way of solving this problem (e.g. in-line allignment macro)? I would be most grateful for your help.
Regards,
Mario
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Generally speaking, it's unreliable to depend on schemes for including padding between variables in COMMON, particularly when interoperating between languages. Perhaps that is the point you are making.
The traditional recommendation to declare all data in a COMMON in decreasing order of size is still good, to avoid requirements for padding to produce correct alignments. This is satisfactory, in the absence of requirement for efficient vectorization.
In order to promote vectorization without inclusion of padding, we set arrays to specific sizes, such as multiples of 16. That may not be among your concerns.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Declare your COMMON with the BIND(C) attribute, like this:
BIND(C) :: /COMMON_NAME/
This will make Fortran lay out the variables exactly as C would in a struct. Fortran does not pad COMMONs by default, which is why you don't see an option for it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My C++ appneeds to support the dataalignment by 1 for legacy reasons (porting from Alpha)and a chain structureof the set of software modules that passes this data. The fortran code is mid-way in this chain, it gets HUGE amount of REAL*4, INTEGER*2 and LOGICAL*1 variables and arrays and collects it in COMMONs in various order (so no natural alignment possible). Next, the C++ gets itby extern "C", wraps it into structures and passes it further on. At each stage, the offsets between each vaiable must be kept constant. I'd like to avoid low-level data manipulation and COMMONs redefinition, as the whole chain would be affected.
Any way to 'hack' :) the IVF11 compiler?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As Steve pointed out, the iso_c_binding declaration guarantees consistency (almost certainly with no padding) between Fortran and extern "C"
The mis-alignment would have been problematical on Alpha, and the code was intentionally non-portable, but Steve's suggestion seems best.
- 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
Thanks guys!
Mario

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