Re: C local auto-initialized?
Re: C local auto-initialized?
- Subject: Re: C local auto-initialized?
- From: Greg Guerin <email@hidden>
- Date: Thu, 20 Sep 2007 19:15:31 -0700
Fritz Anderson wrote:
>Debug configuration:
>sumY2 = 0
>sumY2 = 16.000000
>
>Release configuration:
>sumY2 = 8.69289e-311
>sumY2 = 16.000000
>
>Which means I can't say either way whether it exhibits the problem (in
>Release, the addend << the sum, for those playing along at home).
>
>This quasi-bug is mocking me. I'll try to find a way to reproduce it.
>
>I admit that it's perverse that I _want_ sumY2 to be non-zero.
It's not mocking you. It's doing exactly what I'd expect it to do:
Act in an indeterminate manner.
Maybe I'm being perverse, but it seems to me that it's doing all that could
be expected of it. Garbage values are essentially random. That means you
can't predict them. Yet by insisting on a non-zero value, you are
requiring a predictable (i.e. non-zero) value. Undefined behavior is
undefined.
Yes, it's annoyingly unillustrative that sumY2 is 0 in the Debug
configuration, but you're getting a different value in the Release
configuration, so what more can you really expect? The initial values are
undefined, which means exactly that: undefined.
If you REALLY want to figure this out for the Debug case, I think you'll
have to look a lot more closely at the assembly-level code and the full
code-path of the Debug execution environment, to figure out exactly where a
given garbage value truly comes from. I really don't see how you could do
it at just the C level. Oh sure, you could probably write some C code that
throws a bunch of semi-random data on the stack or into registers, and then
call your sample function, but that's going to be pretty close to an
empirical exercise in "fuzzing". I'm not suggesting that won't work, just
that you can't easily predict what it will lead to.
What you're trying to do is get defined behavior from something whose
behavior is undefined. I'm not surprised you can't pin it down, only that
you keep insisting the undefined behavior be defined.
From the results provided, it should also be clear that in the Release
configuration, the reason the garbage initial value was "disappearing" is
due entirely to the magnitude of that initial value. Adding such a tiny
value to most of the possible double number space would have made the
initial value seem to "disappear". Maybe you should do something other
than addition, or do something before the addition, like comparison or
inversion. True, none of those will make a zero into the non-zero you
seek, but the only way I can see to change that is to track down the true
origin of the recalcitrant 0.0 and "indeterminate" it into some other value.
OBTW, Murphy's lawyers called and said this code fragment may or may not be
infringing on their client's eponymous law. They were adamant, but quite
indeterminate. The Red Queen says "Hi", too.
-- GG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden