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-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newscon02.news.prodigy.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!bigboote.WPI.EDU!news.tufts.edu!uunet!spool.news.uu.net!ash.uu.net!newsfd02.forthnet.gr!not-for-mail From: Ioannis Vranos Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) Date: Fri, 25 Mar 2005 03:34:24 +0200 Organization: FORTHnet S.A., Atthidon 4, GR-17671 Kalithea, Greece, Tel: +30 2109559000, Fax: +30 2109559333, url: http://www.forthnet.gr Message-ID: <1111714466.725311@athnrd02> References: <395uqaF5rhu2mU1@individual.net><1110329098.642196@athnrd02> <1110361741.551255@athnrd02> <422edaec$0$26554$9b4e6d93@newsread4.arcor-online.net> <1111464133.508323@athnrd02> <423fe9df$0$11476$9b4e6d93@newsread2.arcor-online.net> <1111521825.653841@athnrd02> <424094b0$0$11481$9b4e6d93@newsread2.arcor-online.net> <1111568404.687226@athnrd02> <1111572591.296439@athnrd02> <1111574207.72969@athnrd02> <42414f88$0$9217$9b4e6d93@newsread4.arcor-online.net> <1111576802.823362@athnrd02> <1111577078.934620@athnrd02> <1111586334.958702.249050@o13g2000cwo.googlegroups.com> <1111608867.922129@athnrd02> <1111676146.182139.284080@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: athnrd02.forthnet.gr Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: athprx02.forthnet.gr 1111714466 12768 193.92.150.73 (25 Mar 2005 01:34:26 GMT) X-Complaints-To: abuse@forthnet.gr NNTP-Posting-Date: Fri, 25 Mar 2005 01:34:26 +0000 (UTC) User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en In-Reply-To: <1111676146.182139.284080@z14g2000cwz.googlegroups.com> Cache-Post-Path: newsfd02!unknown@ppp16-adsl-51.ath.forthnet.gr Xref: g2news1.google.com comp.lang.ada:9946 comp.lang.c++:47148 comp.realtime:1698 comp.software-eng:5309 Date: 2005-03-25T03:34:24+02:00 List-Id: fabio de francesco wrote: > Sorry, maybe I was unable to explain the concept because of my poor > English. Try please to re-read the latest paragraph, because you're > missing the point. I know that standard guarantees minimum number of > bits per types. > > I was reasoning upon porting a C++ code from a machine providing C++ > "int"(s) with 32 bits capacity to another machine where "int"(s) are > only 16 bits. In that situation if you forget to substitute every "int" > with "long" you don't get any error from the compiler. True. I wish we got such errors/warnings. I still see no reason why compiler-writers do not implement such errors/warnings and it is not part of the standard requirement. > That ported > program can execute for years without any problem. When that variable > is assigned a value like 32768 you get -32768 and then negative numbers > increasing towards zero for each "++var;". Remember that this > assignment was considered allowable, since the programmer chose an > "int" type for that variable knowing that it is stored in 32 bits in > his development machine. Yes. Also I see no reason why explicit use of ranges and constraints can't be introduced in a future standard revision as additional keywords without breaking existing code. > Maybe that won't crash your program yet it is worse, because a bug has > been inserted and it may pass unnoticed for years. > > What I want to say is that in C++ (1) you must know how many bits are > reserved for every type you use and (2) you must carefully change types > when compiling to different targets. Yes C++ is more unsafe than Ada (but still more safe than C). > Instead in Ada a programmer can just write code that is portable across > different platforms without worrying of bits of storage for types. Just > ask the compiler "I need to store values between -80_000 and 80_000, so > please choose yourself how many bits I need", and you can be sure that > it won't raise any bug porting code from a machine with 32 bits "int" > to a 16 bits "int". OK, I already know that Ada is more safe than C++, when talking about "implicit" safety as opposed to "explicit" safety, and C++ *is* the second. Also I consider C++ being more "implicit" *paradigm-expressive* than Ada, as opposed to explicit-expressiveness (about the same that someone mentioned as expressiveness and expressibility in another message). In other words I expect an intermediate C++ programmer (like myself) to know how to write bullet-proof code. > The interesting thing in Ada is that either you can let your compiler > to choose how to internally reserve storage, or you can force a lot of > attributes for representation like the example that I provided: > > type Counter is new Integer; > for Counter'Size use 48; > for Counter'Alignment use 16; > > The above mentioned type declaration is something can't be done with > C++, as far as I know. In order to do same kind of things you must use > some no-standard compiler extension. Ada is simultaneously lower-level > and higher-level than C++. If you mean "more" I disagree. It simply provides more "implicit" safety than C++. In the low-level part I think they are about the same "implicit"-expressive, about the high level part (abstraction) I think C++ is better than Ada and with more complete paradigm-support ("implicit" expressiveness). -- Ioannis Vranos http://www23.brinkster.com/noicys