Re: question about initializing variables to 0
- From: David Flower <DavJFlower@xxxxxxx>
- Date: 4 May 2007 01:21:42 -0700
On May 3, 8:29�pm, "jamesgi...@xxxxxxx" <jamesgi...@xxxxxxx> wrote:
On May 3, 1:11 pm, Randall Mackie <rlmackie...@xxxxxxxxx> wrote:
Maybe this is a question of style more than substance, but when initializing
variables to zero, does it matter if you use:
x = 0
or
x = 0.0 (for real)
or
x = 0.d0 (for double real)
or
x = cmplx(0.d0, 0.d0, kind=r8) (for example)
Does the first one (x = 0) always work regardless of how x is declared?
Yes. Some purists would insist that you use the correct
type of literal regardless. If the value were, say, one-tenth
it would make a difference which kind of literal you used.
By always using a matching kind (both type and KIND) of
literal, you have a habit which is perhaps safer. I have no
strong opinion either way in Fortran. I'd would prefer that
it not matter though. I think Fortran is misdesigned in that
respect.
I do have one change to your above though. When I have
any COMPLEX data at all, I always USE a module that defines
a generic operator for COMPLEX literals called .I. Using
that, the last assignment would read:
X = 0.d0 +.i. 0.d0
I don't use the CMPLX intrinsic at all anymore.
--
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- Hide quoted text -
- Show quoted text -
I respectfully disagree about your non use of the intrinsic CMPLX.
The problem is not how the code looks to you, but how it looks to a
future maintenance programmer.
When there is a choice between two ways of writing code, other things
being equal, the more standard one should be chosen.
David Flower
.
- Follow-Ups:
- Re: question about initializing variables to 0
- From: Brooks Moses
- Re: question about initializing variables to 0
- References:
- question about initializing variables to 0
- From: Randall Mackie
- Re: question about initializing variables to 0
- From: jamesgiles@xxxxxxx
- question about initializing variables to 0
- Prev by Date: Re: I/O in PURE and ELEMENTAL procedures in Fortran 2008
- Next by Date: Re: question about initializing variables to 0
- Previous by thread: Re: question about initializing variables to 0
- Next by thread: Re: question about initializing variables to 0
- Index(es):
Relevant Pages
|