On Tuesday 06 June 2006 5:06 pm, Maura Edeweiss Monville wrote:
Thak you. Worked examples are always welcome to understand the rules. It's not clear if the C external struct must be embedded in that "pack" declaration. In some other similar websites it is stated that a particular include file must be included in the C module ... This is confusing ... A C struct can cause many problems: Unpacked in a 64-bit Linux/Unix system: struct { char a; /* starts on a 64-bit boundary */ long b; /* Also starts on a 64-bit boundary */ } s; The size of s is 16 bytes with a 7 byte filler between a and b. On a 32-bit system, a will start on a 32-bit boundary, and b will start on a 32-bit boundary with a 3 byte filler leaving the size of s as 8 bytes. In a packed struct, a will start on a 64-byte boundary assuming it is not included inside a packed structure. But, b will start immediately after a with no filler so the 64-bit version of s is 9 bytes.
Remember that floats (32-bits) and doubles(64-bits) are defined by the IEEE
754 standard (on a Linux and Unix platform). Integers in FORTRAN and C will
be the same on the same platform as long as you understand the difference
in sizes in C and FORTRAN. Structures are another matter as they are
defined by the C standards and the alignments are "implementation defined".
I don't recall if the C standards require variables to be naturally aligned
or not. It does require that a structure start on a natural boundary. And,
as I mentioned, C arrays are row-major and FORTRAN arrays are column major.
Strings in FORTRAN as I remember have a leading length attribute and no
trailing nul.
(I'm going home :-).
--
Jerry Feldman