Re: MR&C 7.9




"Richard Maine" <nospam@xxxxxxxxxxxxx> wrote in message
news:1hv0q9i.1bc34nmfmigxdN%nospam@xxxxxxxxxxxxxxxx
Lane Straatman <invalid@xxxxxxxxxxx> wrote:

Right
at the beginning of execution, a has been set to 0.0 . You can actually
comment out:
a=0.0
and get the same output .

No! No! No!
I didn't say this was a good idea. The sentence is quite true though, that
using illegal code, I got the same output. That this is illegal makes me
wonder about that run-time I had up-thread. When I toggled between
real, save :: a
!real :: a
I would get a run-time error when I hit
a = a + x
if a had not been saved, and ,consequently, on my machine, initialized to
zero. If this initilization is not something you can count on, then isn't
real, save :: a
a = a + 1.0
also illegal?


That is *NOT* guaranteed. If you comment out the a=0.0, then what you
have is illegal code. It will do different things on different
compilers, or perhaps even on the same compiler with different options.
In some cases it will be set to zero as you observed. In other cases, it
will be set to random garbage. In yet other cases, the compiler will
catch the error and abort the program.

The standard says that the initial value of "a" is undefined. That is
standard-speak for "anything can happen; don't count on it; adn just
because you observe some behavior in one case, still don't count on it".

This newsgroup quite regularly ends up helping people whose programs no
longer work because they depended on that behavior. I recommend against
joining the ranks of people who will need such help in the future.
I tried to find relevant material in the standard (04-007 pg 87, 91), but
found nothing.
--
LS


.



Relevant Pages

  • Re: MR&C 7.9
    ... compilers, or perhaps even on the same compiler with different options. ... because you observe some behavior in one case, ... he uses a test on COUNTER to decide to initialize ... In which case a does start out zero, and keeps it value between calls. ...
    (comp.lang.fortran)
  • Template Problem
    ... Is this illegal code ... or a compiler bug? ... emplate argument list ...
    (microsoft.public.dotnet.languages.vc)
  • Template problem
    ... Is this illegal code ... or a compiler bug? ... emplate argument list ...
    (microsoft.public.vc.language)
  • Re: Do loops until HUGE?
    ... But the compiler is also free to do a lot of other things, ... some of which involve exceeding limits and thus making the program ... And regardless of how the trip count is computed, ... things a compiler may do with such illegal code, ...
    (comp.lang.fortran)
  • Re: Specialisation of a template that results to another template
    ... > Is it illegal code or is it a limitation of the MS compiler? ... VC7.0 does not support partial specialisations. ...
    (comp.lang.cpp)