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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cea502f7b2820a37 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!cyclone1.gnilink.net!spamkiller2.gnilink.net!gnilink.net!trndny07.POSTED!0f19ed38!not-for-mail From: "Frank J. Lhota" Reply-To: NOSPAM.lhota@adarose.com User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Enumeration literals and their associated functions References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 20 Oct 2005 15:35:47 GMT NNTP-Posting-Host: 141.154.56.84 X-Complaints-To: abuse@verizon.net X-Trace: trndny07 1129822547 141.154.56.84 (Thu, 20 Oct 2005 11:35:47 EDT) NNTP-Posting-Date: Thu, 20 Oct 2005 11:35:47 EDT Xref: g2news1.google.com comp.lang.ada:5817 Date: 2005-10-20T15:35:47+00:00 List-Id: Maciej Sobczak wrote: > Hi, > > , paragraph 6 > states that for each enumeration literal specification there is an > appropriate parameterless function declated. > > type Color is (RED, GREEN, BLUE); > > type Function_Access is access function return Color; > > Fa : Function_Access := RED'Access; > > The compiler reports an error in the last line: > > "prefix of "Access" attribute cannot be enumeration literal" The problem here is that enumeration literals are Intrinsic functions (See ARM 6.3.1). Intrinsic subprograms are "built in" to the compiler. When an intrinsic subprogram is called, the compiler will typically in-line some pre-defined code for the call. In other words, Intrinsic subprograms are always inlined. The basic arithmetic operations declared in Standard, e.g. function "+" (Left : Integer; Right : Integer) return Integer; are intrinsic functions. The compiler simply uses the one assembler instruction for calls to these functions. Enumeration literals are always intrinsic functions: the compiler simply uses the internal representation value as the result of the call. The 'Access attribute, when applied to a subprogram, returns the location of the code for that subprogram in memory. For intrinsic subprograms, however, this code does not exist! Therefore, the 'Access attribute cannot be applied to an intrinsic function. If I declare function Add (Left, Right : in Integer) return Integer renames Standard."+"; then I cannot use Add'Access either. If you really do need a pointer to a function that always returns a certain enumeration value, you can always write you own function, as follows function Always_Red return Color is begin return RED; end Always_Red; Fa : Function_Access := Always_Red'Access; > I understand that the use of "RED" in this line is not resolved to be a > name of the function. If that is the case, then how can I use this > function? Basically, the only use of the function notation for enumeration literals is in renaming declarations. > Another example: > > Some_Function_That_Expects_Color(RED); > > Is the use of "RED" above considered to be a function call? If yes, then > why in RED'Access it is resolved to be a literal? > If instead "RED" above is considered to be a literal, then what's the > sense of having an associated function at all? > > -- "All things extant in this world, Gods of Heaven, gods of Earth, Let everything be as it should be; Thus shall it be!" - Magical chant from "Magical Shopping Arcade Abenobashi" "Drizzle, Drazzle, Drozzle, Drome, Time for the this one to come home!" - Mr. Lizard from "Tutor Turtle"