Re: Warning: The structure contains misaligned fields



On Mon, 28 Apr 2008 11:06:45 -0800, glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
wrote:

I thought that padding was allowed, though. COMMON in Fortran 66
was usually believed not to allow padding, creating alignment
problems fairly often. C struct definitely allows padding, which
is good because many current processors don't allow misaligned
access. (IA32 does, but it is often much slower.)
Doesn't COMMON now allow for padding?

Only to the length of a "storage unit" if you still want to meet the letter of
the standard.

If SEQUENCE types work with C interoperability they better
use the same padding that is used by the appropriate C compiler.

A type can be either SEQUENCE or BIND(C) - it can't be both. A type with
BIND(C) is supposed to have exactly the same memory layout that the
corresponding C compiler would use.

SEQUENCE types may or may not be padded, depending on the implementation and
options. The Intel compiler does not pad SEQUENCE types by default, but
padding is available through a switch.

Before BIND(C), SEQUENCE would be recommended for sharing structures with C.
Now one would prefer BIND(C).

--
Steve Lionel
Developer Products Division
Intel Corporation
Nashua, NH

For email address, replace "invalid" with "com"

User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://support.intel.com/support/performancetools/fortran
My Fortran blog
http://www.intel.com/software/drfortran
.



Relevant Pages

  • Re: sizeof(type) > than it should be ... help!
    ... sort of padding they want in derived types, ... Numeric sequence type and character sequence types are ...
    (comp.lang.fortran)
  • Re: sizeof(type) > than it should be ... help!
    ... sort of padding they want in derived types, ... Numeric sequence type and character sequence types are ...
    (comp.lang.fortran)
  • Re: SEQUENCE
    ... efficient order, these must interoperate with the Windows API, so they ... trying to make the compiler generate compatible padding. ... you are using Intel Fortran The Intel Fortran ... You can ask for SEQUENCE types to participate in alignment ...
    (comp.lang.fortran)
  • Re: traumatized by pointer casting
    ... the compiler will probably allocate it like ... >> The padding byte is required because d must start at an even address. ... >> category that the C standard calls undefined behavior. ... > architecture) will have to determine how to handle the undefined behavior? ...
    (comp.lang.c)
  • Re: Array assignment via struct
    ... >> the DS9000 is the only implementation to include padding. ... it would make sense on many platforms to pad struct foo to 4 bytes and ... but you never know what code an optimising compiler is ...
    (comp.lang.c)