Uninitialized use warning message

Kean Johnston jkj@sco.com
Sat Aug 27 07:48:00 GMT 2005


> A common situation would be:
> 
> 	if (condition) {
> 		flag = 1
> 		msg = "Hello World";
> 	} else
> 		flag = 0;			[1]
> 	...
> 	if (flag)
> 		printf ("I say, %s\n", msg);	[2]
> 
> Point [1] is where I "fail" to init 'msg', point [2] is where I
> use it. I know that the program is safe, and if the flow analysis
> can relate 'flag' and 'msg' then the warning would go away.
> 
> Which one would we want listed in the proposed new warning, 1 or 2?
Definately 2. I wont say it is *impossible*, but I think
it is asking way too much of the compiler to warn about 1.
It implies a level of understanding of the flow of the
program that is completely unrealistic. However, warning at
2 should be trivial. Where this level of detail in the
warning is useful is if you have a particularly large function,
with the variables declared at the top (not at the top of, say,
and enclosing if() block). Its even worse when the code is
full of pre-processor conditionals. By telling me that 2
(or all instances of type 2), it saves me looking at *every*
usage of msg. It's just plain more useful, IMHO :)

Kean



More information about the Gcc mailing list