This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: named warnings & individual warning control
>>>>> "Zack" == Zack Weinberg <zack@codesourcery.com> writes:
Zack> It occurs to me that the Java spec has definite rules for what
Zack> constructs are and are not to receive uninitialized-variable
Zack> diagnostics. Maybe it makes sense to adopt those for cross-language
Zack> use?
While personally I think the Java rules are nice-to-have in that they
eliminate the possibility of uninitialized local variables, they are
fairly static and probably won't conform to what most C users expect.
E.g., in Java this code is invalid:
boolean predicate = ...;
int x;
if (predicate)
x = 7;
... no uses of x
if (predicate)
do_something (x);
... since the Java rules don't notice that x is defined and used under
the same condition.
Still, one advantage of this approach is that the rules, while perhaps
limiting, are also well-defined and can be explained to users. Rules
that rely on the capabilities of the optimizer would seem to be
subject to random (hard to explain) changes.
If you want to read more about this, though, here is the
specification:
http://java.sun.com/docs/books/jls/second_edition/html/defAssign.doc.html#25980
This chapter is written in a fairly difficult-to-read style. But the
gist can be had by reading the intro material and skipping the
pedantically described rules at the end. You can ignore all the
definite unassignment stuff, that is only for initialization of final
variables, which doesn't have an analog in C.
Tom