On Tuesday 06 June 2006 7:42 pm, Colin Carter wrote:
On Wednesday 07 June 2006 07:43, Jerry Feldman wrote:
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 :-).
The first BYTE of a FORTRAN character string is its DEFINED length (not the number of characters stored), and the old standard for calling routines was to pass the number of characters as an extra parameter in a CALL statement (i.e. the length was pushed onto the stack, but not seen in the source code) also, C and FORTRAN parameters were pushed onto the stack in opposite sequence, and clearing the stack can be the responsibility of the caller or of the routine. New FORTRAN compilers are now the same as C. FORTRAN always passes by address. Recent FORTRAN compilers have changed things. So you need to know your compilers :-)
Besides COMMON blocks are obsolete now. Use MODULE Thanks for posting this. I know that the code Maura is working with is older existing code. However I did forget to mention the calling sequences. Actually, parameter passing on some systems is defined by a "calling standard". Another thing I forgot to mention is that, as you mentioned, FORTRAN passes parameters by reference where C passes parameters by value. (Note that arrays in C are effectively passed by value). But, as you pointed out it is important to know the platform and compilers. On Linux, while you have GCC and GNU FORTRAN, there are other compilers available. -- Jerry Feldman
Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9