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,9ce095aba33fe8d0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Thu, 27 Oct 2005 03:04:53 -0500 Date: Thu, 27 Oct 2005 04:05:07 -0400 From: "Robert I. Eachus" User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Negative float problem References: <1130351574.313991.229420@g14g2000cwa.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.147.79.61 X-Trace: sv3-c1W6NwZuMXAByWWV85egHtUwizM2LkmpiTwyO2qcZwFUi5Zp5FL/ETiwGiTY33L4apzYybTf3NfkFzq!oEQOeJf+iHBILeCbuKa02u71sxVHw7gxLfgVOgWQtxpNyJ0t6kyI5Mrh5ab+jjiPBNhBAlI/054= X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:5983 Date: 2005-10-27T04:05:07-04:00 List-Id: Robert A Duff wrote: > But I suggest using the first solution. Really, the "use type" > semantics ought to be turned on by default -- you shouldn't have to say > anything special to use the "-" operator. After all, you don't have > to say anything special to use "1.0" or ":=" on this type! There was an Ada83 AI on this, usually referred to as the "for I in 1..-10" problem. (Yes the loop would be executed zero times, but the problem is that an Ada 83 compiler was required to reject the for statement.) Tucker came up with some preference rules that handle some of the cases, but the case mentioned here is one of the more refractory ones. It could be solved by having a negation symbol that could be part of a numeric literal. But as long as users are allowed to overload operator symbols, the visibility rules will have some edge cases like this one. For example package file1 is type My_Float is digits 6; function "-"(L: My_Float) return My_Float; end file1; package body file1 is function "-"(L: My_Float) return My_Float is begin return L-1.0; end "-"; end file1; with file1; use file1; with Ada.Text_IO; use Ada.Text_IO; procedure file2 is X : file1.My_Float := -1.0; function "-"(L: My_Float) return My_Float is begin return L+1.0; end "-"; Y : file1.My_Float := -1.0; begin if X /= Y then Put_Line("Correct"); end if; end file2; f:\Ada>gnatmake file2 gnatmake file2 gcc -c file2.adb gcc -c file1.adb gnatbind -x file2.ali gnatlink file2.ali f:\Ada>file2 file2 Correct Now in one sense this is a pretty silly example. But it is the way the visibility and overloading rules work in Ada for good reasons that have nothing to do with this example. ;-) Obviously it is better to have one set of visibility rules for all subprograms than for programmers to try to remember which set of visibility rules apply in this case. (Yes, there is a different set of rules for basic operations like numeric literals and assignment. But since these are not overloadable, this doesn't cause a problem.) Finally, there is actually a third way to make the negation operator from file1 visible. But note that this is direct visibility not use visible: function "-"(L: My_Float) return My_Float renames file1."-";