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,34a625e98d6a8792 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!t-online.de!news-lei1.dfn.de!news-ham1.dfn.de!news.uni-hamburg.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: The right way to handle this difference in Ada Date: Thu, 22 Jul 2004 17:52:33 +0000 (UTC) Organization: GMUGHDU Message-ID: References: NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1090518753 22167 134.91.1.34 (22 Jul 2004 17:52:33 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Thu, 22 Jul 2004 17:52:33 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: g2news1.google.com comp.lang.ada:2349 Date: 2004-07-22T17:52:33+00:00 List-Id: vic wrote: : : : Please consider this type: : : type unsigned_int_12_type is range 0..(2*12)-1; A step forward towards an Ada solution is stating what you need this type for. So for what are objects of this type used? It is likely easier then for people to hint at a language representation that suits your needs. If you just "port" the C++ solution to what you think is the "same" Ada solution, you might miss valuable facilities of Ada. Coding might also become much more difficult than it needs to be. : c := a-b : : 1) which should be the type of c? I think it should be something like: What it should be depends what c is supposed to be. For example, if you calculate in units of apples, then "a apples - b apples" cannot easily be a sensible expression if a > b, numerically. So what is c supposed to be? If you include debt (in apples) then c might be the number of apples that someone owes someone else. So there exists a common "counting type" for the number a, b, and c. In this case I'd choose a reasonable range for possible numbers of apples, say type Apple_Count is range -10_000 .. 20_000; and then, for measuring existing apples, subtype Existing_Apples is Apple_Count range 0 .. Apple_Count'last; (There are no negative number included since obviously there are no apples that don't exist.) Then, c: Apple_Count; a, b: Existing_Apples; ... c := a - b; Or do you need 12 bits for some hardware representation? In this case you can use a modular type as has been demonstrated in another response, a packed array of Boolean values, or a record with a representation clause (similar to a bitfield in C.) : 2) And I should rename a "-" operation which gets two signed_int_12_type as : operands and returns signed_int_12_type as result? If you want "-" to convert to the type of c, I think it might help the reader of the source code if instead you convert the operands so that "-" becomes a computation in the type of c. -- Georg