From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,803df5f3f60558d5 X-Google-Attributes: gid103376,public From: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) Subject: Re: Uninitialized "out" parameters Date: 1996/07/22 Message-ID: <4svba5$j2i@mulga.cs.mu.OZ.AU>#1/1 X-Deja-AN: 169421690 references: <4smh9i$gp5@krusty.irvine.com> <31EF9DFC.6FB4@csehp3.mdc.com> <4ss763$2aq@felix.seas.gwu.edu> <4ssn9r$p6e@mulga.cs.mu.OZ.AU> <4ste71$hg8@felix.seas.gwu.edu> organization: Comp Sci, University of Melbourne newsgroups: comp.lang.ada Date: 1996-07-22T00:00:00+00:00 List-Id: mfeldman@seas.gwu.edu (Michael Feldman) writes: >Fergus Henderson wrote: >>mfeldman@seas.gwu.edu (Michael Feldman) writes: >> >>>It _cannot_ be a compiler error, because in general it is undecidable >>>whether a variable is used before it is initialized. >> >>Sure it could be a compiler error. > >[...] you quoted me out of context; we >were talking about Ada, in which there is no _required_ initialization >of variables. In that context, my statement is correct. [...] >The thread was about Ada as it is, not as we might like it to be. Threads do have a habit of shifting topics. When you started talking about what "cannot be", and referred to undecidability to justify your point, rather than referring to the RM, it seemed to me that you were talking about what is or is not logically possible, rather than what happens to be the case. I seem to have misinterpreted you, so my apologies. >Consider a trivial case: > > X: Integer; > Y: Character; > >begin > > get(Y); > if Y = 'a' then > X := -3274; > else > code not involving X > end if; > put(X); > >What should the compiler do here? _Maybe_ X will be used before >initialization. We cannot know with confidence whether it _will_ be. If you're talking about Ada-as-it-is, then the compiler should issue a warning, but accept the code. It should do the same thing even for a code fragment such as X: Integer; begin put(X); unless it can prove that this code fragment will be executed. If you're talking about Ada-as-it-should-be, then the question is more debatable. I think it is a good idea for compilers to warn about such constructs, and a good idea for programmers to always restructure their code to avoid such warnings. If you accept that, it's only a short step from there to agreeing that these messages should be errors rather than warnings. If you transliterate that example from Ada to Mercury, and try compiling the resuling code, the Mercury compiler will report an error "mode mismatch in if-then-else", and will tell you that `X' is bound in one branch of the if-then-else, but not in the other. >Does Java _compel_ initialization? My copy of the Java language specification is elsewhere at the moment, and I don't have a Java compiler at hand to test, so there is a quite large chance that I may be wrong about this, but I _think_ that Java does not require initialization at the point of declaration, but instead requires that a variable be initialized along all the execution paths leading to a possible use of a that variable; that would mean that if a variable wasn't used, there would be no requirement to initialize it. -- Fergus Henderson | "I have always known that the pursuit WWW: | of excellence is a lethal habit" PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.