This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Uninitialized use warning message
- From: Kean Johnston <jkj at sco dot com>
- To: Eyal Lebedinsky <eyal at eyal dot emu dot id dot au>
- Cc: gcc at gcc dot gnu dot org
- Date: Fri, 26 Aug 2005 18:10:49 -0700
- Subject: Re: Uninitialized use warning message
- References: <430F923C.4080803@sco.com> <430FAEE3.8080204@eyal.emu.id.au>
- Reply-to: jkj at sco dot com
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