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: mfeldman@seas.gwu.edu (Michael Feldman) Subject: Re: Uninitialized "out" parameters Date: 1996/07/21 Message-ID: <4ste71$hg8@felix.seas.gwu.edu>#1/1 X-Deja-AN: 169232367 references: <4smh9i$gp5@krusty.irvine.com> <31EF9DFC.6FB4@csehp3.mdc.com> <4ss763$2aq@felix.seas.gwu.edu> <4ssn9r$p6e@mulga.cs.mu.OZ.AU> organization: George Washington University newsgroups: comp.lang.ada Date: 1996-07-21T00:00:00+00:00 List-Id: In article <4ssn9r$p6e@mulga.cs.mu.OZ.AU>, 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. I know of at least one language >for which that is the case, and there are probably others. >(I'm not sure, but Java may be one of them?) I'm not sure about Java either, but 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. If the language rules required that each variable must be initialized at elaboration (say, either by an initialization expression or by default using some value within the type of that variable), then there would be no uninitialized-variable problem because all variables were guaranteed to be initialized. > >Note that type correctness (defined in the dynamic sense) is also >undecidable -- yet there are certainly *lots* of languages for which >the compiler enforces type safety at compile time. That is a different issue. If Ada _compelled_ initialization, it would be trivial to determine whether all variables were initialized. Certainly the compiler could "enforce" initialization; if you failed to supply an initializer, the compiler would supply a default. There have been earlier threads on why Ada does not compel initialization. This is NOT what we were talking about. The thread was about Ada as it is, not as we might like it to be. Given that Ada does _not_ compel initialization, it is undeciable for a compiler to catch all cases of use-before-initialize. Some trivial cases can be caught; others can be warned as "_might_ be used before initialization". 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. Does Java _compel_ initialization? Which languages do, in your experience? Mike Feldman