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: bobduff@world.std.com (Robert A Duff) Subject: Re: Uninitialized variables, Java example Date: 1996/07/25 Message-ID: #1/1 X-Deja-AN: 170833382 references: <31EEACDA.64880EEB@sage.inel.gov> <4t7g2q$ee0@goanna.cs.rmit.edu.au> organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-07-25T00:00:00+00:00 List-Id: In article <4t7g2q$ee0@goanna.cs.rmit.edu.au>, Richard A. O'Keefe wrote: >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. No, it doesn't. It's quite possible to write the above, and have it blow up at compile time. >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. Agreed. I would say, "Now the compiler knows that THE PROGRAMMER THINKS that path can't be traversed too." And another programmer knows that the first programmer thinks... - Bob