From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: <4A8049D6.3000207@tecmav.com> Date: Mon, 10 Aug 2009 10:19:07 -0700 Message-ID: Subject: Re: [9fans] Unexpected 8c warning message From: Russ Cox To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Topicbox-Message-UUID: 40d04f80-ead5-11e9-9d60-3106f5b1d025 This problem is uncomputable, so trying to handle every case that comes up is problematic. There has to be a line somewhere. Saying that the compiler could figure out does not imply that it must. I think it's perfectly reasonable that a compiler, when presented with a program like int x; for(___; ___; ___) { x = ___; ___; } if(!x) ___; should complain about a possible used-but-not-set of x. As a person reading that code, I can't look at the overall structure of the code and see that x is obviously initialized at the if statement, unless I analyze the various abstracted-away ___ pieces. And if one of those changes, then there is now a real error. SET is hard to use correctly and not portable. You are better off with a simple assignment, simpler than the one you used in your example: just zero the variable before the loop. int x; x = 0; for(___; ___; ___) { x = ___; ___; } if(!x) ___; Now at least the people reading the code can see that x is initialized, for sure. It's very hard for me to see how "x = 0" is a medicine worse than the disease. I do agree that the "SD = SDList[0];" you had is not a good solution, because it makes it look like that value is important, but "SD = nil;" avoids that issue. Alternately, since the if(!x) is really the continuation of the last iteration of the loop, you could move it inside the loop: int x; for(___; ___; ___) { x = ___; ___; if(last iteration && !x) ___; } which makes it clear to both people and compilers that x is set before it is used. It is not the compiler's job to enable you to be as clever as possible. If this really matters to you and you don't want the compiler warnings, you can always turn them off. Russ