D
dandelion
Chris Torek said:You haven't. You may think so, you may even have paid no attention
to them, but they are there. Without [invariants], programming is
impossible, after all.
I think you really need to take a leaf from Knuth here:
"Beware of bugs in the above code; I have only proved it
correct, not tried it."
Yes. I know that one (Thanks to /usr/bin/games/fortune).
As I believe David Parnas has noted as well, program proofs usually
embed deliberate simplifications, lest the proof be as complex as
(or more complex than) the program itself.
I surmise it's usually the latter. However, I wasn't talking of proving
correctness
That depends -- on what is on line 14, among other things. Even
if line 14 is something like:
p = &zog;
Ok. But then again, that is not what I meant. Sorry for my sloppy wording,
sometimes.
That should (of course) have read "at the end of the loop. That is, prior to
the execution of the code on line 14.
the value that one "sees" in i might change.
if &i == p. Correct. But outside the scope of the example.
In a debugger, for
instance, I might well find that i suddenly becomes 0xa0c9e7d4,
because it shares a register with variable "p" in the underlying
(optimized) machine code.
Also correct. But with the remark that using an debugger on optimized code
isn't the way to see what's happening to individual variables. For the
reason you specify.
On the other hand, if line 14 is:
printf("i is now %d\n", i);
I *would* expect to see "i is now 10" in the output, and if I did
not, I could use whatever additional information I had about the
system to try to find out why not.
That would be either a compiler bug and/or a hardware bug. I cannot really
imagine a well functioning system (hw&os&compiler) screwing up so basic a
loop. Unless (of course) it's a multithreaded program and 'i' is global, or
an IRQ screwed up, or (i've allredy read all your post) Alpha
particles/cosmic radiation or an insect crawling around in your system
(Eniac).
These *are* good things -- but remember:
Sometimes designs fail.
:-( said:As Bradley Sherman asked:
Can you prove that electromigration will not cause a fault in
the processor or gamma radiation will not alter a bit [...]?
You can't. After all physics is physics is nasty...
(We used to have memory chips with alpha-particle problems. Bits
stored in memory would change. Tim May is fond of telling the
story of how he figured this out. "Hot electron migration" remains
a problem in semiconductor design, too. I have stories about timing
problems in various CPUs, such as the carry-chain propagation bug
in the VAX, or the bug in the Ultrasparc CPU where the forwarding
logic would sometimes write an ALU computation into the wrong
register.)
Right you are. Thanks for the interesting story. I though my
"ghost-characters" coming in over an RS485 line were wild... It turned out
there ws this *huge* fridge right next to it.
However, the response was to someone who claimed to have written software
*without* invariants and my response was intended merely to show this is not
possible.