comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Another problem with stream reading.
Date: Thu, 28 Mar 2002 16:30:47 -0600
Date: 2002-03-28T16:30:47-06:00	[thread overview]
Message-ID: <ua76ac8dcaat70@corp.supernews.com> (raw)
In-Reply-To: ud6xpwnn7.fsf@ctwd0143.fitlinxx.com

David Bolen wrote in message ...
>"Randy Brukardt" <randy@rrsoftware.com> 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.







  reply	other threads:[~2002-03-28 22:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-25 18:53 Another problem with stream reading Erik Sigra
2002-03-25 19:01 ` Dan Andreatta
2002-03-25 19:14   ` Erik Sigra
2002-03-25 22:20     ` Jeffrey Carter
2002-03-25 22:28     ` Stephen Leake
2002-03-26 17:54 ` Warren W. Gay VE3WWG
2002-03-27 15:53   ` Erik Sigra
2002-03-27 21:22     ` Warren W. Gay VE3WWG
2002-03-27 22:50     ` Dan Andreatta
2002-03-27 23:55     ` Randy Brukardt
2002-03-28  0:18       ` David Bolen
2002-03-28 22:30         ` Randy Brukardt [this message]
2002-03-28  0:33       ` tmoran
2002-03-28 15:21       ` Marin David Condic
2002-03-29 11:30         ` Larry Kilgallen
2002-03-29 14:33           ` Marin David Condic
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox