[Info-vax] Alpha Fortran data alignment
Richard B. Gilbert
rgilbert88 at comcast.net
Tue Aug 31 15:36:22 EDT 2010
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
>
> Why is this?
>
> Thanks!
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.
You have made essentially the same error with REAL*4 and REAL*8.
If you write real programs this way, you will NEVER be certain what your
results mean!!! Or you may be certain and wrong!!!!!!
Main does not pass the value of prmidx, it passes the *address* of
prmidx. In Fortran, arguments are normally passed by reference (address
of the argument).
This piece of shit might actually run on some platforms but it's not
something I want to bet on.
Go thou and sin no more! If you don't straighten up, God will surely
punish you! And your fellow men will laugh you out of town first!
More information about the Info-vax
mailing list