comp.lang.ada
 help / color / mirror / Atom feed
From: "David Thompson" <david.thompson1@worldnet.att.net>
Subject: Re: type declaration and storage requirements
Date: Tue, 11 Jun 2002 07:18:10 GMT
Date: 2002-06-11T07:18:10+00:00	[thread overview]
Message-ID: <SuhN8.35344$UT.2423738@bgtnsc05-news.ops.worldnet.att.net> (raw)
In-Reply-To: bebbba07.0206021321.a3bbfac@posting.google.com

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 <float.h>
...
#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 <G>
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








      parent reply	other threads:[~2002-06-11  7:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-02 21:21 type declaration and storage requirements Russ
2002-06-02 23:54 ` martin.m.dowie
2002-06-03  0:40   ` Dale Stanbrough
2002-06-03 11:10     ` martin.m.dowie
2002-06-04  2:40       ` Dale Stanbrough
2002-06-03  6:58   ` Russ
2002-06-03  7:57     ` AG
2002-06-03 11:19     ` martin.m.dowie
2002-06-03 12:40     ` Larry Kilgallen
2002-06-03 13:12     ` Gautier
2002-06-03  2:26 ` Jeffrey Carter
2002-06-04 10:35 ` Simon Wright
2002-06-04 13:04   ` Martin Dowie
2002-06-06  8:06     ` Simon Wright
2002-06-11  7:18 ` David Thompson [this message]
replies disabled

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