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-27 15:54:16 PST Path: archiver1.google.com!news1.google.com!sn-xit-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: Wed, 27 Mar 2002 17:55:34 -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:21736 Date: 2002-03-27T17:55:34-06:00 List-Id: Erik Sigra wrote in message ... >If you look carefully at my code you can se that i did NOT write "Integer >range", just "range". And there is certainly no need for a sign bit for the >range 0 .. 255. If I lie to the compiler, it does certainly not disregard it. >It complais loudly. If I for example say "for Byte'Size use 7;", it replies >"size for "Byte" too small, minimum allowed is 8" That's the form of a declaration for a signed integer type. And negative values must be provided for the base type, read the RM! http://www.adaic.org/standards/95lrm/html/RM-3-5-4.html, paragraph 9. > I should not need a modulo type for unsigned numbers. You (usually) don't. But streams always read and write the base type, and that is always signed unless use use a modular type. And your original question was about the behavior of streams. It would be nice if Ada had real unsigned types with checking, etc., but I brought that up repeatedly during the design of Ada 95, and there was no support. And that has not changed, so don't expect it to change in Ada 0y. So we have only modular types if we really need unsigned behavior. 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. That's unfortunate, given that the code generator is able to generate the operations, but that is the price of having a good language standard. (We could have, and probably should have, implemented a pragma to let the compiler ignore the language rules here -- that is explicitly allowed by the standard - see "non-standard integer types" (paragraph 26 in the same RM section referenced above) -- but we never had a business reason for doing so. Besides, I hate pragmas. :-) Randy Brukardt.