Re: F2008 draft
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Mon, 17 Jul 2006 14:25:25 -0700
Richard Maine wrote:
(snip on BLOCKs and scoping)
Among the issues:
Lifetime of variables declared in a block. Do they "go away" when the block exits? Can they be SAVE'd? Can they have an intermediate form of SAVE that makes them last until the procedure exits?
All the complications of host association come into play. A "favorite" is implicit typing. If you can have explicit declarations in such a block, can you also have implicit ones? If not, you have a funny inconsistency. If so, you have the possibility of implicitly declared variables ending up in lower scopes than intended.
PL/I, which also has implicit declaration, has two grouping operations.
DO (with or without iteration) has no scoping effect, and BEGIN, which
does. It also has internal procedures, which have the same scoping
questions.
(snip)
For now, you can use: DO ... EXIT; END DO
I've seen this idea before and I personally strongly recommend against using that form for a "do once". I consider it to be a "hack", and it shares many of the problems of such things. It is confusing and extremely error prone.
In C there is:
do { } while(0), not quite as confusing. The do grouping implies that
the conditional test is at the end. It is mostly needed with #define
statements to add grouping without confusing some constructs.
Fundamentally, DO is a looping construct. In this particular case, you are even using an infinite loop form if it, counting on the exit to make it do what you really want. It is confusing because the reader sees the infinite loop and has to look inside to understand that it can never actually loop. It is error prone because accidentally omitting the exit (as could happen any number of ways) completely changes the nature of it; you then have that infinite loop.
In PL/I the non-looping DO was part of the language from the beginning,
and is much more common than looping DOs. It would be confusing
to try to add one now to Fortran, though.
-- glen
.
- References:
- F2008 draft
- From: Joe Krahn
- Re: F2008 draft
- From: Richard Maine
- F2008 draft
- Prev by Date: Re: double confusion
- Next by Date: Re: F2008 draft
- Previous by thread: Re: F2008 draft
- Next by thread: Re: F2008 draft
- Index(es):
Relevant Pages
|
|