I've tried the following program with two compilers. I think they both
get the "wrong" answers for P1 and P2. Neither one reports an error at
compile- or run-time. I've reported to the vendors.
Maybe it's my mistake.
I think P1 should be
11 12 13 14 21 22 23 24 31 32 33 34 41 42 43 44
and P2 should be
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
1. What do you think the "right" answers are for P1 and P2?
2. Do you have a compiler that does what you (or I) expect?
Best regards,
Van Snyder
==========================================================================
module RESHAPERS
interface RES
module procedure RES1, RES2
end interface
contains
function RES1 ( R1 )
integer, pointer :: RES1(:)
integer, target :: R1(:)
res1 => r1
end function RES1
function RES2 ( R2 )
integer, pointer :: RES2(:,:)
integer, target :: R2(:,:)
res2 => r2
end function RES2
end module RESHAPERS
program TEST
use RESHAPERS
integer, pointer :: P1(:)
integer, pointer :: P2(:,:)
integer, target :: T1(16) = (/ (i,i=1,16) /)
integer, target :: T2(4,4) = reshape( (/ ((10*i+j,i=1,4),j=1,4) /), (/4,4/) )
p1 => res(reshape(t2,(/16/)))
p2 => res(reshape(t1,(/4,4/)))
print *, 'T1 ='
print '(16i3)', t1
print *, 'T2 ='
print '(4i3)', (t2(i,:),i=1,4)
print *, 'P1 => res(reshape(t2,(/16/))) ='
print '(16i3)', p1
print *, 'P2 => res(reshape(t1,(/4,4/))) ='
print '(4i3)', (p2(i,:),i=1,4)
print *, 'SHAPE(P1) =', shape(p1)
print *, 'SHAPE(P2) =', shape(p2)
end program TEST
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|