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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,971aa11c293c3db1 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-07-23 04:51:54 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!ailinel.cbb-automation.DE!not-for-mail From: dmitry@elros.cbb-automation.de (Dmitry Kazakov) Newsgroups: comp.lang.ada Subject: Re: Ada The Best Language? Date: Mon, 23 Jul 2001 11:51:53 GMT Message-ID: <3b5c0a6b.1467500@news.cis.dfn.de> References: <5be89e2f.0107170838.c71ad61@posting.google.com> <5be89e2f.0107180235.726d46a8@posting.google.com> <9j3rrd$g71$1@s1.read.news.oleane.net> <5be89e2f.0107181300.4b4e93d7@posting.google.com> <3B57195E.A3A3FED@home.com> <9j93u6$1ua8$1@norfair.nerim.net> <3B586A17.862BA84D@home.com> <9j9s3t$kn8$1@wanadoo.fr> <9jej7c$7q1$1@wanadoo.fr> <9jff9l$sqp$1@wanadoo.fr> <3b5bd4b2.1217171@news.cis.dfn.de> <9jgmtp$3a1$1@norfair.nerim.net> NNTP-Posting-Host: ailinel.cbb-automation.de (212.79.194.99) X-Trace: fu-berlin.de 995889113 25125261 212.79.194.99 (16 [77047]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:10466 Date: 2001-07-23T11:51:53+00:00 List-Id: On Mon, 23 Jul 2001 10:27:27 +0200, "Bertrand Augereau" wrote: >> enum COLOR { BLUE, RED, GREEN }; >> >> int main (void) >> { >> COLOR X = BLUE; >> >> switch (X) >> { >> case 0 : break; >> } >> return 0; >> } > >I don't see this type of code as a coding mistake, it is just a nonsense way >of doing it. This can only be an intentional mistake and type safety is >there mainly for protecting you against non-intentional mistakes. What is the difference between "intentional" and "non-intentional" mistakes? Both result in blue-screen. It is nice to have Windows. We can always say, that it is Microsoft's fault when our programs crash (:-)). But what would be a blue-screen for a flight control system? >That's what forbidding implicit int->enum is for. Does the code above not contain an implicit int->enum conversion? >I'm not sure a compiler has to take care of this error, though Ada >programmers might think otherwise. No doubts. BTW in Ada the counterpart of C++ switch statement shall cover all alternatives, so being translated into Ada switch (X) { case BLUE : break; } would be also illegal, because it is not clear what to do with RED and GREEN. >It is often nice to have a enum->int conversion, especially when you can map >your enum to some int you need. > >enum BOOL { > FALSE = 0, > TRUE = !0; >}; > >Then if you need a enum->int mapping, you just have it for free by the fact >enum are reprensented by int in the machine (as with Ada, I suppose). I >think you can do that in Ada if you need it with using clause. enum <-> int mapping is an implementation detail. There is no need to expose it. A program that relies on the fact that on some particular machine, occasionaly the representation of COLOR::BLUE and int::0 are same, is poorly designed. That C++ allows such things be implicit [in Ada you may achieve the same effect only by an explicit way], is a clear language design fault. Regards, Dmitry Kazakov