This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: named warnings & individual warning control

>>>>> "Zack" == Zack Weinberg <> 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

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]