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-Thread: 103376,60fe876e7675f11,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Received: by 10.68.135.231 with SMTP id pv7mr14627614pbb.8.1328635499756; Tue, 07 Feb 2012 09:24:59 -0800 (PST) Path: lh20ni271184pbb.0!nntp.google.com!news2.google.com!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Weird behavior with modular type Date: Tue, 07 Feb 2012 18:24:57 +0100 Organization: Ada @ Home Message-ID: NNTP-Posting-Host: eQxAA/sqYBHh2aCJsHQRLA.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/11.61 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable Date: 2012-02-07T18:24:57+01:00 List-Id: Hi all, I expect the test to be shortened enough. The following compiles and run without an error: with Ada.Text_IO; procedure Bug is type Modular_Type is mod 256; subtype Index_Type is Natural range 1 .. 3; E : Modular_Type :=3D 255; I : Index_Type :=3D 3; B : Boolean; begin B :=3D E < 10 ** I; Ada.Text_IO.Put_Line (Boolean'Image (B)); end Bug; It prints "FALSE" Now, the following, with added =E2=80=9CNatural'Pos (...)=E2=80=9D, did = not even compile: with Ada.Text_IO; procedure Bug is type Modular_Type is mod 256; subtype Index_Type is Natural range 1 .. 3; E : Modular_Type :=3D 255; I : Index_Type :=3D 3; B : Boolean; begin B :=3D E < Natural'Pos (10 ** I); Ada.Text_IO.Put_Line (Boolean'Image (B)); end Bug; That's counter intuitive. I would expect the first to behave as the = second, with either a failure to compile or range error at run=E2=80=91t= ime. Someone remember a pointer to the most relevant part in the RM? I may be= a = bit tired, could not find it. Seems in the first case, the left=E2=80=91side of =E2=80=9CE < 10 ** I=E2= =80=9D has a modulo = applied, or else, I see no way to explain the result, "FALSE". But why = would this modulo be applied with a subtype of Natural and not with an = Universal_Integer? I don't like it (and must be idiot in some way, don't you think?). -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity