- #1
- 3,971
- 328
Hi, I just realized that I have been making bad array assignments in my code. Specifically, I think I have been assigning to slots that the array does not have. For example, I might declare an array:
And then assign values of y from values of x in such a fashion:
So for the second do-loop, I should be going over values of i for slots that x doesn't have, right?
I realized that what I should have written was something like:
Now that I think about it, I would have guessed I should have incurred a bunch of compile-time or at least run-time errors. However, with these errors, the code actually still ran. I did not get compile or run-time errors using these faulty array assignments. Can anyone guess what Fortran has been doing?
Code:
int,parameter :: nflavor=3
int,parameter :: nflavor2=nflavor*2
real,dimension(nflavor)::x
real,dimension(nflavor2)::y
And then assign values of y from values of x in such a fashion:
Code:
do i=1,nflavor
y(i)=x(i)
end do
do i=nflavor+1,nflavor2
y(i)=x(i)
end do
So for the second do-loop, I should be going over values of i for slots that x doesn't have, right?
I realized that what I should have written was something like:
Code:
do i=nflavor+1,nflavor2
y(i)=x(i-nflavor)
end do
Now that I think about it, I would have guessed I should have incurred a bunch of compile-time or at least run-time errors. However, with these errors, the code actually still ran. I did not get compile or run-time errors using these faulty array assignments. Can anyone guess what Fortran has been doing?