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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d0452dbe16ac0df4 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: ObjectAda vs Gnat -- bugs Date: 1997/05/16 Message-ID: #1/1 X-Deja-AN: 242809936 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <337B65FC.98D@gsfc.nasa.gov> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1997-05-16T00:00:00+00:00 List-Id: Stephen Leake (Stephen.Leake@gsfc.nasa.gov) wrote: : granger wrote: : > : > Here is a shortened version of a package that I wrote. : > : > It compiles without any error with ObjectAda. : > With gnat3.09, I have the following errors: : > : > rgbcolor.ads:18:41: expect object name in renaming : > rgbcolor.ads:19:49: expect object name in renaming : > : > Which of the compilers is correct ? : gnat; see below Actually, Gnat is wrong and Object Ada is correct ;-). In Ada 95, the result of calling a function is a constant object (per RM95 3.3(10,21)), and it may be renamed (8.5.1(4)). This fact is mentioned in AARM 3.3(26.b). : > package rgbcolor is : > package RGB_Value is : > type Color3 is : > record : > red, green, blue : Float; : > end record; : > Gray0 : constant Color3 := ( 0.000, 0.000, 0.000 ); : > Grey0 : Color3 renames Gray0; : > Gray1 : constant Color3 := ( 0.012, 0.012, 0.012 ); : > Grey1 : Color3 renames Gray1; : > end RGB_Value; : > : > type Color_Type is ( Gray0, Gray1 ); : > : > subtype Grey_Color_Type is Color_Type range Gray0 .. Gray1; : > : > Grey0 : Color_Type renames Gray0; -- line in error--------------- : > Grey1 : Color_Type renames Gray1; -- line in error--------------- : replace the error lines with: : function Grey0 return Color_Type renames Gray0; : function Grey1 return Color_Type renames Gray1; This will also work, but it is not required in Ada 95. One advantage of this approach is that these new declarations are parameterless functions, which allows them to be overloaded and inherited by derived type. : > end rgbcolor; : An enumeration literal acts like a function with no parameters, so you : can rename it as a function. Your original renaming was trying to : declare an object, which GNAT correctly forbids; submit an error report : to Aonix! No, don't bother. GNAT should interpret the renaming as a renaming of the result of calling the parameterless "function." : However, if you are expecting rbbcolor.Grey0 to return the same value as : rgbcolor.RBG_Value.Grey0, you are confused; one is a scalar enumeration : type, the other is a record type with three components. You could add : the declarations: : Grey0 : RGB_Value.Color3 renames RGB_Value.Gray0; : Grey1 : RGB_Value.Color3 renames RGB_Value.Gray1; : But I'm not clear what you are after. : -- : - Stephe -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA