- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - OpenVMS
- >
- Alignement of Structure in Fortran and C
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2010 01:24 AM
тАО03-31-2010 01:24 AM
Alignement of Structure in Fortran and C
1) Fortran Structure:
structure /Point/
union
map
REAL x,y,z
end map
map
REAL coor(3)
endmap
end union
end structure
2) Fortran Structure containing another Fortran Structure
struct COMP
{
Point pt;
INTEGER ext;
}
3)Fortran Structure
struct NESTED
{
COMP cp(10)
INTEGER tcp;
}
Can anybody help in writing properly aligned C Structure for the above fortran structures.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2010 03:28 AM
тАО03-31-2010 03:28 AM
Re: Alignement of Structure in Fortran and C
typedef union
{
float x,y,z;
float coor[3];
} Point;
typedef struct
{
Point pt;
int ext;
} COMP;
typedef struct
{
COMP cp[10];
int tcp;
} NESTED;
Purely Personal Opinion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2010 04:52 AM
тАО03-31-2010 04:52 AM
Re: Alignement of Structure in Fortran and C
First of all, i want to correct my question.
structure for COMP and nested are as follow:
struct COMP
{
record /Point/ pt;
INTEGER ext;
}
struct NESTED
{
record /COMP/ cp(10)
INTEGER tcp;
}
I tried with the same C Strucutres as you suggested. But it result in mis alignment hence incorrect data is shared across fortran and C.
I think its something to do with
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2010 05:10 AM
тАО03-31-2010 05:10 AM
Re: Alignement of Structure in Fortran and C
Have you tried to identify the difference, for example by printing out address (offsets) for component fields?
What compiler switches are used?
What platform? VAX floats or IEEE?
Check out the HELP text for HELP CC /FLOAT
Now compile with /LIST and /SHOW=MAP (C: /SHOW=SYMBOLS and looks for thing like the FLOAT option(s) used.
The Fortran compiler listign might show some things like:
/DOUBLE_SIZE=64
/FLOAT=G_FLOAT
/GRANULARITY=QUADWORD
/IEEE_MODE=FAST
/INTEGER_SIZE=32
/REAL_SIZE=32
Now let that sink in, compare to C, and what you see in the programs.
Use Debugger for final confirmation
In the debugger I like EVAL/ADD after SET MODE HEX for TEST programs. You see addresses like 10000 or 30000 as start of those test structure and offsets for the fields are very obvious
Cheers,
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2010 05:17 AM
тАО03-31-2010 05:17 AM
Re: Alignement of Structure in Fortran and C
#pragma member_alignment save
#pragma nomember_alignment
struct ...
}
#pragma member_alignment restore
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2010 05:26 AM
тАО03-31-2010 05:26 AM
Re: Alignement of Structure in Fortran and C
If using the F95 TYPE definition instead of the DEC Fortran STRUCTURE/RECORD extension, include the STORAGE attribute.
This way you are as insulated as possible from external factors such as the presence or omission of compiler switches that affed default Integer/Real sizes and alignment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2010 06:06 AM
тАО03-31-2010 06:06 AM
Re: Alignement of Structure in Fortran and C
Misalignment problem occurs only because i am using record /Point/ and
record /COMP/ cp(10)
However i have previously worked on simple structure containing INTEGER,REAL,LOGICAL.... and alignments work properly with my compiler settings.
But in this case structure (NESTED) contains Userdefined structure (Point and COMP)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2010 06:50 AM
тАО03-31-2010 06:50 AM
Re: Alignement of Structure in Fortran and C
It can be preferable to use SDL for these definitions and for related definitions, as that usage reduces the likelihood of errors, and as it eases maintenance, and as it allows the structures to be documented via SDML (if the DEC Document package is available), and as it forces some discipline around the structures.
This SDL usage does presuppose control over the Fortran and the C source code involved.
Regardless of whether you might choose to use SDL here, embedding and implementing and checking a version number within the structures can be an invaluable technique for avoiding skews; this if you're working with a common or other such technique, and don't rebuild all code referencing the shared data as a unit. This means you can detect and flag cases where the (shared) data structure has changed.
SDL-related discussions:
http://labs.hoffmanlabs.com/node/588
http://labs.hoffmanlabs.com/node/595
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-31-2010 12:40 PM
тАО03-31-2010 12:40 PM
Re: Alignement of Structure in Fortran and C
Rather than start with your existing Fortran structure and try to force another language to match it, look at the structure itself and put it in a form which naturally fits the data alignment models of all languages you want to define it in.
The first thing I'd suggest is to move your INTEGER fields to the BEGINNING of the nested structures and then pad to quadword align the embedded structure. I'd also pad out the "Point" structure to an even number of longwords. The simplest way to keep everything aligned is to make them all naturally aligned sizes.
Thus:
structure /Point/
union
map
INTEGER*4 padding(4) ! force size
end map
map
REAL x,y,z
end map
map
REAL coor(3)
endmap
end union
end structure
struct COMP
{
int ext;
int pad1;
Point pt;
}
struct NESTED
{
int tcp;
int pad2;
COMP cp(10)
}
You can do the same with appropriate alignment qualifiers, pragmas or compiler directives. Make sure you generate full compiler listings and check the offsets of all fields to ensure they line up.
Even better is to do what Hoff suggests and use a utility like SDL whos whole reason for existence is to solve the problem you're asking about.