Re: Warning: The structure contains misaligned fields



On 4月28日, 下午9时08分, Gordon Sande <g.sa...@xxxxxxxxxxxxxxxx> wrote:
On 2008-04-28 09:28:50 -0300, blitheli <blith...@xxxxxxxxx> said:



Is anybody can tell me what is wrong with this? Is this a fatal error
in fortran?
Thanks!
-------------------------------
module test
implicit none

type :: ccc
sequence
private
logical :: is_null=.true.
real(8):: A0=0d0,B0=0d0, Lambda0=0d0, H0=0d0
end type ccc
end module test
-------------------------------
The compile says:

Warning: The structure contains one or more misaligned fields.
[CCC]

If you read he words it says WARNing. It does not say FATAL.
Usually the manual will list the types of errors and comment
on the distinction. Since only you know what system/compiler
you are using noone else can be of much help. Please RTFM!

REAL(8) is a trouble point in the long run when you get around to
changing compilers. But today the LOGICAL is 4 bytes and REAL(8)
will be 8 bytes. The module starts out on an even memory boundary
and assigns the 4 bytes for the logical. You have specified SEQUENCE
so the compiler has no choice in its assignement. Next you will find
an 8 byte double precision that will not be on an 8 byte boundary.
That could mean 1. poor esthetics 2. poor performance 3. run time
terminating exception depending on what processor you are using.
Hence a warning. If you current processor had option 3 it would
most likely have been a fatal error. So either it will run slowly
(which you might not notice) or it won't but may casuse trouble
when you change processor. Hence just a warning.

The fixs are to change the order of the variables, take off the
sequence or just live with it. Depends on why you have the module
structure presented. Some compilers have options to hide the warning
messaage so you can live with it and hide that fact from your boss
and/or colleagues

Telling folks what system/compiler comlete with versions is helpful.
It marks you as someone who may not have very much experience so
you will get more further questions than answers. Any answers will
be vague like the above. A few will be definitive because they will
have guessed important facts that may have been guessed incorrectly.
You have been warned but, hey, this is the internet.

Thank you very much. I understand it now.
By the way, what is the most important role of "sequence" in
fortran?
.



Relevant Pages

  • Re: Warning: The structure contains misaligned fields
    ... end module test ... Warning: The structure contains one or more misaligned fields. ... You have specified SEQUENCE ... Some compilers have options to hide the warning ...
    (comp.lang.fortran)
  • Re: No warning
    ... > I believe the following program is not standard conforming. ... > SEQUENCE ... > compilers, and I have yet to find one that gives an error ... > or warning for this program. ...
    (comp.lang.fortran)
  • Re: PROBLEM
    ... tmp.c:1: warning: initialization discards qualifiers from pointer ... The problem with C compilers is that these options are not enabled ... Compiling new C code in a mode that flags possible writes to string ... become illegal if the language were modified to make string literals ...
    (comp.std.c)
  • Re: something to do with void *
    ... Either a warning ... it's allowed to produce any additional diagnostics it likes. ... The assertion made by Emmanuel was that all compilers that he was aware ... dereferencing an uninitialized void pointer or a void pointer ...
    (comp.lang.c)
  • Re: Same code and different result, Why?
    ... No, it is undefined for all other compilers, as well. ... of sequence point is common for all C/C++ compilers. ... for the course for the technology you are using right now, ... sometimes decided by the underlying hardware, ...
    (microsoft.public.vc.language)