Re: C local auto-initialized?
Re: C local auto-initialized?
- Subject: Re: C local auto-initialized?
- From: Laurence Harris <email@hidden>
- Date: Thu, 20 Sep 2007 22:04:00 -0400
On Sep 20, 2007, at 8:21 PM, Fritz Anderson wrote:
Note that if you compile with all warnings enabled (which I do as
a matter of course) and you have optimisations enabled, the
compiler will warn you that you're using an uninitialised variable.
Yes, that is good. However, people seem to forget what I'm doing:
I'm trying to teach how to debug something. I DON'T WANT TO AVOID
THE BUG. And, if I'm debugging, there's no optimization. Besides,
I'm writing for instructional purposes, teaching Xcode, and at the
very beginning, I can't detour people away from instructional tasks
to adjusting the development environment.
The nature of the code you posted is such that I don't see a bug. In
my mind a bug is something that can prevent code from consistently
producing the correct result or behavior, but this code is not trying
to do anything. That is, there is no "correct" result against which
you can compare actual results, so how can you say it isn't working
correctly and therefore has a bug? For example, what if it's supposed
to be generating a random number? In that case it's obviously not
going to be a good random number generator, but it isn't buggy in the
usual sense, just poorly designed because it relies on the value of
an uninitialized variable being random.
If your goal is to teach them how to use the debugger to trace
through code and observe values, you don't need a bug in the code to
do that. If your goal is to teach them how to use that skill to track
down a bug, give them some code with a known expected result that
isn't achieved so they can trace through the code and identify when
things go wrong. If you want to demonstrate the evils of
uninitialized variables in the process, give them a program that will
fail even if the uninitialized variable is 0. After all, if 0 isn't
the correct initial value, it's still a bug and they need to be able
to find that.
This quasi-bug is mocking me. I'll try to find a way to reproduce it.
What bug? Nothing is behaving in an unexpected manner as far as I can
tell.
I admit that it's perverse that I _want_ sumY2 to be non-zero.
It might also cause them to think that a random, nonzero value is the
only kind of uninitialized variable that can cause a problem. Then
when they go to debug something and see a variable is 0 it might not
trigger a flag when it should.
Larry
_______________________________________________
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