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,583275b6950bf4e6 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-05-20 09:10:46 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out.visi.com!petbe.visi.com!nntp5.savvis.net!uunet!ash.uu.net!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Quality systems (Was: Using Ada for device drivers? (Was: the Ada mandate, and why it collapsed and died)) Date: 20 May 2003 12:10:42 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <9fa75d42.0305141747.5680c577@posting.google.com> <3ec4b1c9$1@news.wineasy.se> <9fa75d42.0305161748.1735fc32@posting.google.com> <4W%xa.28765$cK5.11964@nwrdny02.gnilink.net> <1053353256.804734@master.nyc.kbcfp.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1053447042 12574 199.172.62.241 (20 May 2003 16:10:42 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 20 May 2003 16:10:42 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: archiver1.google.com comp.lang.ada:37563 Date: 2003-05-20T12:10:42-04:00 List-Id: Vinzent Hoefler writes: > Hyman Rosen wrote: > > >Vinzent Hoefler wrote: > > > (and that sometimes might be not that easy as it looks at the first glance). > > > >That's because the Ada folks got clever and decided that the > >modulus didn't need to be a poer of two. > > You don't seem to see the real problem. > > Try that with binary values on a machine with one's complement. Try > that on a machine that throws an overflow error if the sign changes... > > There is much more work involved to make it work correct than to > simply leave it implementation defined like in C. But it is not implementation defined in C. C requires unsigned arithmetic to wrap around. Ada requires modular arithmetic to wrap around (but allows an out for ones' complement machines). Signed arithmetic is unpredictable in C (in overflow cases). In Ada, you get an exception. > >Doesn't Dewar rant on this subject occasionally? Yes, he does. I agree with him -- non-binary modulii are an unnecessary frill, and should have been left out of Ada. Consider the weird semantics of "not" for non-binary modulii. > So what? You don't have to use it (BTW, SPARK explicitely forbids > that), but the problem would remain the same for some machines. > > >> I doubt that. C just got modular types because it was convinient and > >> natively supported by the machine. > > > >That doesn't mean that Ada didn't copy the notion from C. > > I still doubt that. And unless someone from the language designers can > definitely confirm that, I will keep doing so. OK, I was on Ada 9X design team. The fact that other languages support modular arithmetic was certainly one factor in the decision. C is the prime example, but there are others. And the fact that these types wrap around in Ada (rather than raising an exception on overflow) is partly because that's what other languages do, and partly because that's what much hardware does. > The use(fulness) of modular types is older than C. True. By the way, modular types is one of my least favorite features of Ada. It's an odd mixture of high level and low level. For high-level purposes, I'd rather have multi-word arithmetic, and do the "mod"s explicitly when desired, and I don't want bit-wise "and" and the like. For low-level purposes, I want bit-wise "and", but I don't want non-binary modulii. Note that even for binary modulii, Ada gives you more than C. C supports certain-sized unsigned types (short, long, etc) -- presumably the ones supported by the hardware. But in Ada, you can have a modulus of 2**13, for example. I believe most implementations do that with an "and" instruction on every arithmetic operation. Another way to do it would be "lazy" -- do the "and" only on output and conversion and the like. The design team actually went back and forth several times between two solutions: a kludgy "magic" package that supports unsigned types of certain sizes, pretty much like C, and a first-class type with syntax and relatively general semantics (including non-binary modulii). I think perhaps the magic package was the better solution. - Bob