comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
Subject: Re: Overlapping ranges
Date: Mon, 23 Jun 2003 05:46:19 -0500
Date: 2003-06-23T05:46:19-05:00	[thread overview]
Message-ID: <PGAJa.19179$bH3.5754@fe02.atl2.webusenet.com> (raw)
In-Reply-To: kszJa.45970$JA5.800915@news.xtra.co.nz

Neither example will compile because the declaration
subtype x1_and_x2_range is range x1(x2'first)..x1'last;
is illegal;

Example 2 will not compile because the declaration
function f(x1_an_x2_range) return boolean;
is illegal.  Did you mean this?
function f(x : x1_and_x2_range) return boolean;

Both examples would give constraint error at runtime because
abc = f (0); has an argument outside the range of x1_and_x1_range.

"AG" <ang@xtra.co.nz> wrote in message
news:kszJa.45970$JA5.800915@news.xtra.co.nz...
> "Robert I. Eachus" <rieachus@attbi.com> wrote in message
> news:3EF5EDA1.1010702@attbi.com...
>
> > Now let's see which problem requirements seem silly:
> >
> > Why are X1 and X2 different types rather than subtypes?
>
> Because I'd rather keep them separate except in the case
> of that one specialised function which knows enough about
> them to handle either. Declaring them as subtypes makes
> all sorts of other things available too.
>
> > Why is X1 not a modular type?
>
> I'm afraid I didn't follow you there: I'm not interested
> in modular or wrap-around semantics, so why should it be?
>
> >
> > Why do you need the Constraint_Error to be raised outside the function
> > call?  Wouldn't raising it inside OR outside work just fine?
>
> No. Because it results in an externally visible different behaviour.
> Let's see an example (a bit silly as all examples are but an example
> nevertheless):
>
> package overlap is
> type x1 is range 0..255;
> type x2 is range 127..2**15-1;
> subtype x1_and_x2_range is range x1(x2'first)..x1'last;
> -- function f(x1_an_x2_range) return boolean;     -- *1*
> -- function f(x: x1) return boolean;                       -- *2*
> end;
>
> with ada.text_io; use ada.text_io;
> package body overlap is
> -- *1*
>   function f(x1_and_x2_range) return boolean is
>     a: x1_and_x2_range;
>   begin
>      put_line("Here");
>      a := x;
>      return false;
>   end;
>
> -- *2*
>   function f(x: x1) return boolean is
> -- same code as above;
>   end;
>
> Finally, the use:  abc := f(0);
>
> The result (running it under GNAT):
>
> Uncommenting version *2* compiles fine
> and generates constraint error when run.
>
> Uncommenting version *1* generates
> exactly the same error when run but also
> provides two compile-time warnings.
> Seems to be a valuable addition, doesn't it?
>
> > Why do you want one function which accepts parameters of two different
> > types?  My solution has the call to one calling the other, but still...
>
> Someone else has already suggested the overloading solution.
> Thanks, that seems like a good idea
> .
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
>





  reply	other threads:[~2003-06-23 10:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-22  0:40 Overlapping ranges AG
2003-06-22  1:23 ` Mark A. Biggar
2003-06-22  2:58   ` AG
2003-06-22  3:17     ` tmoran
2003-06-22 17:55   ` Robert I. Eachus
2003-06-23  9:05     ` AG
2003-06-23 10:46       ` David C. Hoos [this message]
2003-06-24  8:09         ` AG
2003-06-29  0:36 ` Richard Riehle
2003-06-29  6:24   ` AG
2003-06-29  6:42     ` AG
2003-06-29 18:40       ` Richard Riehle
2003-06-29 18:49     ` Richard Riehle
replies disabled

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