This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: DIMENSION statement
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: RadSurfer <RadSurfer at yahoo dot com>
- Cc: fortran at gcc dot gnu dot org
- Date: Thu, 2 Aug 2007 19:17:54 -0700
- Subject: Re: DIMENSION statement
- References: <loom.20070803T032222-430@post.gmane.org>
On Fri, Aug 03, 2007 at 01:40:28AM +0000, RadSurfer wrote:
> I am wondering what the purpose of the DIMENSION statement actually has...
>
> DIMENTION A(50),B(10)
>
> when used all by itself like that?
> How can that possibly be used by the compiler?
It's telling the compiler that A is a REAL array with 50 elements
and B is a REAL array with 10 elements.
> You then have to follow it with something like
> REAL A(50)
> INTEGER B(10)
No, you don't. Well, if you want B to be an INTEGER and you're
using either implicit typing of IMPLICIT NONE, thenn you need to
declare B. Consider
program x
real a
integer b
dimension a(2), b(3)
a(1) = 1.
a(2) = 2.
b(1) = 1
b(2) = 2
b(3) = 3
write(*,'(2F5.1,3I3)') a, b
end
and
program x
real, dimension(2) :: a
integer, dimension(3) :: b
a = (/ 1., 2./)
b = (/1, 2, 3/)
write(*,'(2F5.1,3I3)') a, b
end
and
program x
real :: a(2) = (/ 1., 2./)
integer :: b(3) =(/1, 2, 3/)
write(*,'(2F5.1,3I3)') a, b
end
> A single lone DIMENSION can't possibly generate any actual code or
> pre-processor code can it ?
Try the -fdump-tree-original option.
subroutine x
real a
dimension a(2)
a = (/1., 2./)
end
becomes
x ()
{
real4 a[2];
with a bunch of other code removed.
}
> If there's a better forum to discuss such "trivial" fortran matters, please
> let me know about them.
comp.lang.fortran (although some there do not tolerant tyro questions).
Although it's Fortran 77 based, I'd suggest reading Clive Page's
book. It short and can be read in a few hours.
http://www.star.le.ac.uk/%7Ecgp/fortran.html
--
Steve