Code Comments
Programming Forum and web based access to our favorite programming groups.hi there, I have what is probably a very stupid question : why use DIMENSION statements to define arrays, when simply writing indices seems to be sufficient ? or is it ? thanks G.
Post Follow-up to this messagenews <tperzo@wanadoo.fr> wrote: >hi there, >I have what is probably a very stupid question : >why use DIMENSION statements to define arrays, when simply writing indices >seems to be sufficient ? >or is it ? I generally agree with you and rarely use DIMENSION statements. But they can be convenient if you have several arrays with the same shape: real, dimension(2,5) :: a,b,c,d is more concise and easier to modify than real :: a(2,5),b(2,5),c(2,5),d(2,5) One could use DIMENSION when there are several ALLOCATABLE arrays with the same number of dimensions, writing the slightly shorter real, allocatable, dimension(:,:,:) :: a,b,c instead of real, allocatable :: a(:,:,:),b(:,:,:),c(:,:,:) I think Walt Brainerd, one of the creators of the F (Fortran 95 subset) lang uage, which requires DIMENSION, has said that writing DIMENSION explicitly makes it easier to find array declarations in code. ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==-- -- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 News groups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption = ---
Post Follow-up to this message"beliavsky@aol.com" <beliavsky@127.0.0.1:7501> wrote in message news:41458ef2$1_1@127.0.0.1... > > news <tperzo@wanadoo.fr> wrote: indices > > I generally agree with you and rarely use DIMENSION statements. But they > can be convenient if you have several arrays with the same shape: > > real, dimension(2,5) :: a,b,c,d > etc. Correct, but that's not a DIMENSION statement, that's a DIMENSION attribute. I think OP may have meant DIMENSION a(2,5),b(2,5),c(2,5),d(2,5) which, as we all know, in the absence of an IMPLICIT NONE statement, can lead one to forget the type specification, with potentially disastrous consequences. Regards, Mike Metcalf
Post Follow-up to this messageOn Mon, 13 Sep 2004 13:47:28 +0100, "Michael Metcalf" <michael.metcalf@t-online.de> wrote: [snip] >DIMENSION a(2,5),b(2,5),c(2,5),d(2,5) > >which, as we all know, in the absence of an IMPLICIT NONE statement, can >lead one to forget the type specification, with potentially disastrous >consequences. But in the absence of IMPLICIT NONE, those are all real. No need to look back at the top of the program to see what they are. Ken Plotkin
Post Follow-up to this messageKen Plotkin <kplotkin@nospam-cox.net> wrote in message news:<31cck0t3d3aesbkg1tmcqeotto62p4 q7tk@4ax.com>... > On Mon, 13 Sep 2004 13:47:28 +0100, "Michael Metcalf" > <michael.metcalf@t-online.de> wrote: > > [snip] > > But in the absence of IMPLICIT NONE, those are all real. No need to > look back at the top of the program to see what they are. > > Ken Plotkin For the program integer a dimension a(2) end you DO need to look at the top of the program to know what kind of variable 'a' is. By writing integer a(2) end the information about 'a' is in one place. One wouldn't use 'a' as an integer variable in a real program, but I think it is better to localize information by using REAL, INTEGER, CHARACTER, or LOGICAL in array declarations.
Post Follow-up to this messagebeliavsky@aol.com wrote: (snip) > integer a(2) > the information about 'a' is in one place. One wouldn't use 'a' as an > integer variable in a real program, but I think it is better to > localize information by using REAL, INTEGER, CHARACTER, or LOGICAL in > array declarations. Well, a could be an INTEGER variable in a program that only used integer variables. I know a program that started out INTEGERA,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q ,R,S,T,U,V,W,X,Y,Z There is some advantage to using I though N to start variable names, even in languages without Fortran's type rules. -- glen
Post Follow-up to this messageIn article <31cck0t3d3aesbkg1tmcqeotto62p4q7tk@4ax.com>, Ken Plotkin <kplotkin@nospam-cox.net> writes >On Mon, 13 Sep 2004 13:47:28 +0100, "Michael Metcalf" ><michael.metcalf@t-online.de> wrote: > >[snip] > >But in the absence of IMPLICIT NONE, those are all real. No need to >look back at the top of the program to see what they are. > >Ken Plotkin > The compiler knows they are real. We have no way of telling, other than by trusting the programmer to have self-imposed coding standards for variable names, whether they should have been double precision, logical or even character. It's much easier to forget to put a declaration in than it is to type the wrong one, and without IMPLICIT NONE, almost impossible to detect. Catherine. -- Catherine Rees Lay To email me, use my first name in front of the "at".
Post Follow-up to this messageIn article <RW82d.97838$3l3.71366@attbi_s03>, glen herrmannsfeldt <gah@ugcs.caltech.edu> writes >beliavsky@aol.com wrote: > >(snip) > > > >Well, a could be an INTEGER variable in a program that only >used integer variables. I know a program that started out > > INTEGERA,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q ,R,S,T,U,V,W,X,Y,Z > >There is some advantage to using I though N to start >variable names, even in languages without Fortran's type rules. > >-- glen > I first learnt to program aged about 12, in BASIC on a ZX81. At the time I thought it strange that all the sample programs used FOR I = 1 TO N It took another 9 years before I found out where it came from! Catherine. -- Catherine Rees Lay To email me, use my first name in front of the "at".
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.