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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bdd718faa7c79f29 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-06-23 02:08:32 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news.mel.connect.com.au!news.xtra.co.nz!53ab2750!not-for-mail From: "AG" Newsgroups: comp.lang.ada References: <3EF5EDA1.1010702@attbi.com> Subject: Re: Overlapping ranges X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: Date: Mon, 23 Jun 2003 21:05:09 +1200 NNTP-Posting-Host: 219.88.61.164 X-Complaints-To: newsadmin@xtra.co.nz X-Trace: news.xtra.co.nz 1056359312 219.88.61.164 (Mon, 23 Jun 2003 21:08:32 NZST) NNTP-Posting-Date: Mon, 23 Jun 2003 21:08:32 NZST Organization: Xtra Xref: archiver1.google.com comp.lang.ada:39585 Date: 2003-06-23T21:05:09+12:00 List-Id: "Robert I. Eachus" 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 .