Code Comments
Programming Forum and web based access to our favorite programming groups.Hi Experts, I have seen many tutorial declared array in this form INTEGER, DIMENSION(6) :: myArray I an using a simpler form like this INTEGER :: myArray(6) Do you know any difference between those two forms?
Post Follow-up to this messageOn 15 Nov 2004 03:45:57 -0800 victor@in-box.net (victor) wrote: > Hi Experts, > > I have seen many tutorial declared array in this form > INTEGER, DIMENSION(6) :: myArray > I an using a simpler form like this > INTEGER :: myArray(6) > > Do you know any difference between those two forms? Only programming style. I prefer the former but an a lot of people prefer the latter. Use whatever makes sense to you. David
Post Follow-up to this messagevictor@in-box.net (victor) wrote: >Hi Experts, > >I have seen many tutorial declared array in this form >INTEGER, DIMENSION(6) :: myArray >I an using a simpler form like this >INTEGER :: myArray(6) > >Do you know any difference between those two forms? There is no difference. The F subset of Fortran 95 tries to ensure that ther e is only one way to express something, and its authors chose the form with DIMENSION. Both are ok in Fortran 95. When you have several arrays of the same shape, it is convenient to write real, DIMENSION(m,n) :: x,y,z but when the arrays have different shapes I prefer real :: x(m,n),y(m),z(n) to writing real, DIMENSION(m,n) :: x real, DIMENSION(m) :: y real, DIMENSION(n) :: z ----== 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 messagevictor@in-box.net (victor) wrote in message news:<aec1ceb.0411150345.c75330@posting.google. com>... > Hi Experts, > > I have seen many tutorial declared array in this form > INTEGER, DIMENSION(6) :: myArray > I an using a simpler form like this > INTEGER :: myArray(6) > > Do you know any difference between those two forms? Semantically there is no difference. It's purely a matter of coding style. When the F90 committee decided to make all attributes of declared names declarable in either separate attribute declaration statements or as part of the type declaration statement, they added the DIMENSION syntax you show above. At the time, the DIMENSION statement itself was quite unpopular and was really a likely candidate to be removed. But, it was an attribute specification statement, so consistency required it to be added to the type declaration syntax. I personally would prefer that *all* uses of the DIMENSION keyword be considered obsolescent and that the keyword should be removed from the standard entirely. On the other hand, there are those that claim to find the above use of DIMENSION more legible. -- J. Giles "I conclude that there are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies." -- C. A. R. Hoare
Post Follow-up to this messageJim Giles wrote: (regarding the difference between) and > Semantically there is no difference. It's purely a > matter of coding style. Well, I would say as far as style, with more arrays the former would be preferred, INTEGER, DIMENSION(6) :: myArray1, myArray2, myArray3, myArray4 If you change the dimension you only need to change it in one place, and it is easy to see that it applies to all. (snip) > I personally would prefer that *all* uses of the DIMENSION > keyword be considered obsolescent and that the keyword > should be removed from the standard entirely. On the > other hand, there are those that claim to find the above > use of DIMENSION more legible. -- glen
Post Follow-up to this messageDavid Ham <d.a.ham@citg.tudelft.nl> writes: > On 15 Nov 2004 03:45:57 -0800 > victor@in-box.net (victor) wrote: > ... > > Only programming style. I prefer the former but an a lot of people > prefer the latter. Use whatever makes sense to you. Swap the words "former" and "latter" in David's reply and you'll get mine... complete with David's last sentence. -- Richard Maine | Good judgment comes from experience; email: my first.last at org.domain | experience comes from bad judgment. org: nasa, domain: gov | -- Mark Twain
Post Follow-up to this messageThanks David! David Ham <d.a.ham@citg.tudelft.nl> wrote in message news:<20041115130122.792dd72f.d.a.ham@ citg.tudelft.nl>... > On 15 Nov 2004 03:45:57 -0800 > victor@in-box.net (victor) wrote: > > > Only programming style. I prefer the former but an a lot of people > prefer the latter. Use whatever makes sense to you. > > David
Post Follow-up to this messageThanks a lot for your help. "beliavsky@aol.com" <beliavsky@127.0.0.1:7501> wrote in message news:<41989bf5_1@127.0.0.1> .. > victor@in-box.net (victor) wrote: > > There is no difference. The F subset of Fortran 95 tries to ensure that th ere > is only one way to express something, and its authors chose the > form with DIMENSION. Both are ok in Fortran 95. When you have several arra ys > of the same shape, it is convenient to write > > real, DIMENSION(m,n) :: x,y,z > > but when the arrays have different shapes I prefer > > real :: x(m,n),y(m),z(n) > > to writing > > real, DIMENSION(m,n) :: x > real, DIMENSION(m) :: y > real, DIMENSION(n) :: z > > > > ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News== ---- > http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Ne wsgroups > ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---[/c olor]
Post Follow-up to this messageglen herrmannsfeldt <gah@ugcs.caltech.edu> wrote in message news:<cnaovl$hsl$1@gnus01.u.was hington.edu>... > Jim Giles wrote: > > (regarding the difference between) > > and > > > Well, I would say as far as style, with more arrays the former > would be preferred, > > INTEGER, DIMENSION(6) :: myArray1, myArray2, myArray3, myArray4 > > If you change the dimension you only need to change it > in one place, and it is easy to see that it applies to all. A more common case, at least in my code, is a lot of arrays with *related* but not *identical* bounds: Integer :: a(5), b(-2:2) ! same size, different bounds Real :: R(J,K), S(K,L), T(J,L) ! conformable for matrix mult. etc. And, if you really want to change the dimensions in one place, use named constants as the bounds. -- J. Giles "I conclude that there are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies." -- C. A. R. Hoare
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.