[Info-vax] Alpha Fortran data alignment
Richard B. Gilbert
rgilbert88 at comcast.net
Tue Aug 31 16:51:18 EDT 2010
glen herrmannsfeldt wrote:
> Richard B. Gilbert <rgilbert88 at comcast.net> wrote:
>> tadamsmar wrote:
>>> I was checking the locations of variables.
>
>>> If I run this:
>
>>> integer*2 prmidx
>>> real*4 vlu
>>> prmidx = 1
>>> vlu = 10000000
>>> call sub(prmidx,%loc(prmidx),%loc(vlu))
>>> end
>>> subroutine sub(prmidx,lp,lv)
>>> integer*4 prmidx,lv,lp
>>> type *,prmidx,lp,lv
>>> end
>
>>> 1 196608 196616
>
>>> But if I change prmidx to real*4 in main and real*8 in
>>> the sub, I get:
>
>>> 128.000036285423 196608 196612
>
>>> It appear that 8 bytes are allocated for an integer*2 and 4 bytes are
>>> allocated for a real*4
>
> There is no requirement that variables be allocated in memory
> in the order that they are declared. Sometimes the compiler even
> needs temporary variables that might also be allocated.
>
>>> Why is this?
>
>> Because you are breaking all the rules!!!!!!!
>
>> You have assigned different sizes (INTEGER*2 and INTEGER*4) for the same
>> variable in MAIN and SUB. The subroutine will see 16 bits of data and
>> 16 bits of garbage.
>
> That is true, but completely unrelated to the question being asked.
> The question only has to do with the addresses of the variables
> in the main program. %loc() finds the address and passes that
> as an integer. The OP only was asking about the sizes and
> positions in memory of the variables.
>
I suppose I could simply ignore the errors but code like that pushes
several of my buttons! I used to make my living helping the computer
illiterate write successful programs.
If someone posts Fortran code that is not logically and syntactically
correct and I see it, I'm likely to comment. If you are not the author
of the code in question, please feel free to ignore my comments.
More information about the Info-vax
mailing list