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,4f1dddd3318e056d X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-06-11 00:18:10 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!newsswitch.lcs.mit.edu!newsfeed.mathworks.com!wn3feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!not-for-mail From: "David Thompson" Newsgroups: comp.lang.ada References: Subject: Re: type declaration and storage requirements X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Message-ID: Date: Tue, 11 Jun 2002 07:18:10 GMT NNTP-Posting-Host: 12.89.134.205 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1023779890 12.89.134.205 (Tue, 11 Jun 2002 07:18:10 GMT) NNTP-Posting-Date: Tue, 11 Jun 2002 07:18:10 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:25729 Date: 2002-06-11T07:18:10+00:00 List-Id: Russ <18k11tm001@sneakemail.com> wrote : > Ada allows me to specify the number of digits and the range of a > floating-point type, or the delta and range of a fixed-point type. > This gives more control than, say, C/C++, which only allows me to > specify single or double precision. ... C and C++ don't have fixed-point at all, although in C++ you could cobble up a perhaps-templated class (= ADT) that does a tolerable approximation except for literals. For floating-point, there's a more-or-less workaround: #include ... #if FLT_DIG >= 11 /* single is good enough */ typedef float mytype; #elif DBL_DIG >= 11 /* single isn't but double is */ typedef double mytype; #elif LDBL_DIG >= 11 /* not double but 'extended' */ typedef long double mytype; #else #error We lose, no suitable floating type #endif In C++, you can also use std::numeric_traits<>, but only at 'compile time' not in the preprocessor. Which Ada-trained folks may prefer anyway except that it can't alter a function 'signature' i.e. the choice of dummy/formal/parameter types. And of course neither C nor C++ has user-set ranges (or subtypes) distinct from the underlying/base type's range, though again in C++ you could write a class to do it, but only at runtime cost, since the uneuphoniously-named 'non-type template parameters' can't be floating-point. Well, unless you (can) inline everything and the compiler can determine/prove no aliasing, I think that works but I'd have to try it out to be certain. (Aside: 'C/C++' is even more flamebaitful in comp.lang.c then 'ADA' is here. C is _not_ strictly a subset of C++, though it is _close_ by any reasonable measure.) -- - David.Thompson 1 now at worldnet.att.net