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 05:02:51 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!fr.usenet-edu.net!usenet-edu.net!teaser.fr!nerim.net!norfair.nerim.net!not-for-mail From: "Bertrand Augereau" Newsgroups: comp.lang.ada Subject: Re: Ada The Best Language? Date: Mon, 23 Jul 2001 14:06:49 +0200 Organization: Nerim -- xDSL Internet Provider Message-ID: <9jh3p9$4cv$1@norfair.nerim.net> 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> <3b5c0a6b.1467500@news.cis.dfn.de> NNTP-Posting-Host: aboukir-101-2-1-inutero.adsl.nerim.net X-Trace: norfair.nerim.net 995889770 4511 62.4.19.69 (23 Jul 2001 12:02:50 GMT) X-Complaints-To: abuse@nerim.net NNTP-Posting-Date: Mon, 23 Jul 2001 12:02:50 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Xref: archiver1.google.com comp.lang.ada:10467 Date: 2001-07-23T14:06:49+02:00 List-Id: > > > >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? Oh, I never do that ;-) You are right for critical applications. But I write videogames for a living (PC & PS2) and you can't even rely on hardware and OS in this field, the specs vary every day and the deadlines are insane, so the quality of your code is not that important ;-) I just wanted to say that *nobody* would write such code as a mistake. It can only be intentional. And I don't see whant "non-intentional" mistake you can do with this enum->int conversion. > > >That's what forbidding implicit int->enum is for. > > Does the code above not contain an implicit int->enum conversion? Nope. The enum is converted to an int, and then you can test its value if you want. But I have to repeat it is totally illogical and nobody would write such a thing. > > >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. Most compilers issue a warning when you do not test every alternative of an enum. GCC does for instance. > > >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. Agreed. Too much implicit is dangerous. The major flaw of C++ is inheriting for C but I love the non-verbose syntax.