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=-0.9 required=5.0 tests=BAYES_00,FROM_NUMERIC_TLD autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,4ff929aa5c2b2834 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!news.glorb.com!peer1.news.newnet.co.uk!213.210.46.30.MISMATCH!peernews.inweb.co.uk!zen.net.uk!dedekind.zen.co.uk!news-peer-lilac.gradwell.net!not-for-mail From: "Stuart" Newsgroups: comp.lang.ada References: <1msd2xaahtsgv.f8io255x4f0n$.dlg@40tude.net> <455db67b_1@glkas0286.greenlnk.net> Subject: Re: Ranges and (non)static constraints Date: Mon, 20 Nov 2006 14:08:14 -0000 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 Message-ID: <4561b3d2$1_1@glkas0286.greenlnk.net> X-Original-NNTP-Posting-Host: glkas0286.greenlnk.net NNTP-Posting-Host: 20.133.0.1 X-Trace: 1164031706 news.gradwell.net 633 dnews/20.133.0.1:47003 X-Complaints-To: news-abuse@gradwell.net Xref: g2news2.google.com comp.lang.ada:7578 Date: 2006-11-20T14:08:14+00:00 List-Id: "Dmitry A. Kazakov" wrote in message news:pu08fww26xs9$.jctxs7a23inh.dlg@40tude.net... > On Fri, 17 Nov 2006 13:30:34 -0000, Stuart wrote: > >> "Dmitry A. Kazakov" wrote in message >> news:1msd2xaahtsgv.f8io255x4f0n$.dlg@40tude.net... >> >>> These are sufficiently different. Consider this example: >>> >>> N : constant := 2**64; -- Legal in GNAT >>> type T is range 1..N; -- Illegal in GNAT >>> >>> (This is not a bug) >>> >>> I would at least require the second be legal when the first is. >> >> Why? The first is a named value declaration (rather than a constant >> object >> declaration). In the type declaration I think the semantics of Ada >> require >> that the base type be a signed type, which thus introduces issues of >> symmetry around zero. > > So? Let it allocate two 64-bit words! It is not my business, Ada is a > higher-level language. There is nothing in Ada that stops this, however compiler's typically draw a line somewhere. Ada is a higher-level language - but it also acknowledges the practicalities of compiler design, efficient implementation and the 'broad spectrum' of what users may want to achieve. Compiler writers set out their product for the market place they want. There is nothing in Ada that prevents what you seem to be wanting - but compiler writers don't seem to be operating in that area. Adopting a 'no compromise' approach they might say - "It's not my business, choose a compiler that does support it". >> Unfortunately I am in a bit of a rush at the moment so I don't have a >> chance >> to test an idea like: >> type T is mod N range 1..N-1; > You mean: > type T is mod N; > subtype S is T range 1..N; Well, almost subtype S is T range 1..N-1; (my apologies - in my haste to go home I repeated the semantics which have already been shown to be inappropriate for various reasons). > No, that won't work. Because N is not a value in the modular type, or for some other reason? Earlier I had noted: > Surely there is System.Max_Int! > [ARM 13.7 (23)] The largest (most positive) value allowed for the > expression of a signed_integer_type_definition. > > So you would have: > type Biggest_T is range 1..System.Max_Int; > subtype T is Biggest_T range 1..N; There is also System.Max_Binary_Modulus, which (on the system I have checked with) is larger than System.Max_Int (2**32 vs 2**31 - 1). But that then starts getting into other areas where Ada is treading a fine line between language concepts and practical implementations (note System.Max_Nonbinary_Modulus). [So upon reflection the whole 'mod' thing is possibly a bad idea unless you consider the likely practical implementation issues - which DK seems to be trying to avoid]. However, from my point of view, Ada seems to be giving me - through these constants - the means to write practical routines, without 'undue' artificial constraints. I can even set minimum levels of support by doing something like: type Biggest_T is range 1..System.Max_Int; subtype Minimum is Biggest_T range 1..10_000; subtype T is Biggest_T range 1..N; I accept that at the very fringes I might need to play carefully with Max_Int and Max_Binary_Modulus, but then I consider that playing close to the edge is always fraught with danger - so I accept the risks with portability. -- Stuart