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: ok@goanna.cs.rmit.edu.au (Richard A. O'Keefe) Subject: Re: Uninitialized variables, Java example Date: 1996/07/25 Message-ID: <4t7g2q$ee0@goanna.cs.rmit.edu.au>#1/1 X-Deja-AN: 170506203 references: <31EEACDA.64880EEB@sage.inel.gov> <4t3f1u$t0u@newsbf02.news.aol.com> organization: Comp Sci, RMIT, Melbourne, Australia nntp-posting-user: ok newsgroups: comp.lang.ada Date: 1996-07-25T00:00:00+00:00 List-Id: arra@inmet.com (Arra Avakian) writes: >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.) Wrong. If the problem is that the programmer knows that the default: case can never be executed and the compiler doesn't, then the programmer should TELL the compiler. For example, in the same situation in C, one does int x; switch (e) { case ..: ... x = ..; break; case ..: ... x = ..; break; default: abort(); } I actually use a "shouldnt" macro (name stolen with thanks from Interlisp) which is like assert(0) but cannot be suppressed by NDEBUG. Now the compiler knows that path can't be traversed too. Better still, a human reader knows that the original programmmer *thought* about the problem and didn't just accidentally leave out the default: And there is no unncessary initialisation anywhere. In short, this is a perfect example of where a warning about a possibly uninitialised variable is _really_ a warning about badly written code. -- Fifty years of programming language research, and we end up with C++ ??? Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.