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: arra@inmet.com (Arra Avakian) Subject: Re: Uninitialized variables, Java example Date: 1996/07/24 Message-ID: #1/1 X-Deja-AN: 170393844 sender: news@inmet.camb.inmet.com (USENET news) x-nntp-posting-host: professor.camb.inmet.com references: <31EEACDA.64880EEB@sage.inel.gov> <4t3f1u$t0u@newsbf02.news.aol.com> organization: Intermetrics, Inc. newsgroups: comp.lang.ada Date: 1996-07-24T00:00:00+00:00 List-Id: I find it interesting that the Sun Java compiler warns about POSSIBLE use of uninitialized variables with a message like Variable foo may not have been initialized This message appears even though all dynamic paths to the use of foo do in fact initialize the variable. For example, a switch statement without a default initializes the variable in all branches, but the compiler knows that if the default case occurs, the variable is not initialized. The programmer "knows" that the default case can not occur, but the compiler forces the programmer to initialize foo to get a successful compile, i.e. it will not produce the class file without the "unnecessary" initialization. Some may view this as extreme, since the compiler can not know statically the "truth", and forces a statically knowable work-around on the programmer. Is this what some people want for Ada 0x? It seems to me to be a tradeoff between efficiency (an unnecessary initialization to satisfy the compiler) and safety (the compiler is then allowed to detect statically known cases of uninitialized variables, i.e. true programming errors.) The programmer must analyze the error message and determine whether it is a programming error to be fixed, or a case where an "unnecessary" initialization is needed to quiet the compiler. The language spec says the following about this subject: 4.2.3 Setting Local Variables Methods are rigorously checked to be sure that all local variables (variables declared inside a method) are set before they are referenced. Using a local variable before it is initialized is a compile-time error. Arra Avakian Intermetrics, Inc. 733 Concord Avenue Cambridge, Massachusetts 02138 USA (617) 661-1840 arra@inmet.com