COMMON requires 4 bytes of padding at start

Steve Kargl sgk@troutmask.apl.washington.edu
Fri Sep 12 14:04:00 GMT 2008


On Fri, Sep 12, 2008 at 12:25:26PM +0200, Tobias Burnus wrote:
> 
> Mentioning the align-commons option allows the user to find an
> explanation in the manual. One could even include an example like:
> 
> "Example: In the following program, the variable "r" is not aligned,
> which slows down the memory access.
>   integer(4) :: i
>   real(8) :: r
>   common /com/ i, r
> This can be solved by swapping "i" and "r" (which has to be done in all
> scopes of "com") or by using -falign-commons. However, then the
> definition of all commons with the same name needs to be identical;
> otherwise this leads to wrong code; for "com" an example would be to use
> in another scope
>   integer(4) :: i
>   common /com/ i"

As pointed out be Tobi (not Tobias), the above is true on only some
architectures.  You need to wrap it in a caveat: "On some architectures,
notable IA32, double precision should be aligned to 8-byte boundaries
... "

One may also want to add "To avoid potential alignment issues in 
COMMON blocks, it is recommended to order objects from largests
to smallest."

> > With this patch one gets the expected output "2 3" for Tobias' test
> > case when omitting -falign-commons. Including the flag gives the old
> > output "0 2".
> >   
> For completeness: I think my test was invalid ISO Fortran

Odd.  I concluded that the program was legal.  Why do you think
it is invalid?

-- 
Steve



More information about the Fortran mailing list