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,ba0587ecc5989bed X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-03-28 14:29:32 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Another problem with stream reading. Date: Thu, 28 Mar 2002 16:30:47 -0600 Organization: Posted via Supernews, http://www.supernews.com Message-ID: References: <3CA0B5C4.2060804@home.com> X-Newsreader: Microsoft Outlook Express 4.72.3612.1700 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3719.2500 X-Complaints-To: newsabuse@supernews.com Xref: archiver1.google.com comp.lang.ada:21795 Date: 2002-03-28T16:30:47-06:00 List-Id: David Bolen wrote in message ... >"Randy Brukardt" writes: > >> Janus/Ada, at least, will generate code for your type byte as if it is >> unsigned (that has necessary for Ada 83, which had no unsigned types at >> all), with all of the checking. But where the language requires the base >> type (such as in streams), we have to use signed 16-bits. >> >> The place this matters, of course, is for the largest unsigned type. If >> you declare >> type Unsigned is range 0 .. (2**32)-1; >> in Janus/Ada for Windows, you'll get an error, because there is no >> signed base type large enough to fit it. > >How would you typically work around this, if you really wanted to be >working with 32-bit unsigned quantities in your code? If there's no >signed base type large enough (sans 64-bit support presumably) would >you have to implement your own set of operations on, say, a data type >made out of two 16-bit values? Portably, I think you'd have to do something like that. Another option would be to use a 32-bit modular type, and do overflow checking explicitly. For instance, for "+", if the result is smaller than either of the operands, you've overflowed. Doing that for "*" is unpleasant (you pretty much have to emulate the multiply), but its easy for all of the other operations. It would be easy to define a package like that (that is essentially how the Janus/Ada compiler handles value for code generation purposes). A pragma or something to get to the code generator's DW type would probably be the best solution for Janus/Ada, since that would use the processor's carry flag to do the overflow check. But of course that wouldn't be portable. Randy.