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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,50137bb64a119cfc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-15 17:50:32 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeed.berkeley.edu!ucberkeley!newsfeed.mathworks.com!cyclone.swbell.net!newsfeed1.easynews.com!easynews.com!easynews!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail Newsgroups: comp.lang.ada From: "Eric G. Miller" Subject: Re: "access constant" discriminant References: <_TO1a.14664$9y2.6601@nwrddc01.gnilink.net> <3CS1a.55972$2H6.1357@sccrnsc04> <3E4E9248.3E71D984@adaworks.com> <3E4ED2FC.3310564A@adaworks.com> Message-ID: User-Agent: slrn/0.9.7.4 (Linux) Date: Sun, 16 Feb 2003 01:50:31 GMT NNTP-Posting-Host: 216.119.28.190 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 1045360231 216.119.28.190 (Sat, 15 Feb 2003 17:50:31 PST) NNTP-Posting-Date: Sat, 15 Feb 2003 17:50:31 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:34143 Date: 2003-02-16T01:50:31+00:00 List-Id: In article <3E4ED2FC.3310564A@adaworks.com>, Richard Riehle wrote: > Larry Kilgallen wrote: > >> Why is it necessary to have the parameter be an access type ? Not long ago, I wrote a C library wrapper that takes advantage of being able to modify the contents of a function via an access parameter. Being able to specify "constant" seems like a good thing for safety and for clarifying the "contract" in the API. The "C" library has functions like: typedef struct Foo { /* whatever */} Foo; long Get_Foo (Foo *); long Set_Foo (Foo); So, the Ada wrapper is like: type Foo is record -- whatever... end record; pragma Convention (Convention => C_Pass_By_Copy, Entity => Foo); function Get_Foo (Self : access Foo) return Error_Code; pragma Import (Convention => C, Entity => Get_Foo, External_Name => "Get_Foo"); function Set_Foo (Self : Foo) return Error_Code; pragma Import (Convention => C, Entity => Set_Foo, External_Name => "Set_Foo"); But, maybe there's a function like: #define FOO_NAME_LENGTH 42 typedef char Foo_Name[FOO_NAME_LENGTH]; long Get_Foo_Name (const Foo *, Foo_Name); So, I might want a wrapper function that mirrors this: Foo_Name_Length : constant := 42; subtype Foo_Name is C.Char_Array(1..Foo_Name_Length); function Get_Foo_Name (Self : access constant Foo; Name : access Foo_Name) return Error_Code; pragma Import (Convention => C, Entity => Get_Foo_Name, External_Name => "Get_Foo_Name"); Seems like a reasonable thing. The downside of pointers to constant parameters is functions that are declared using "constant", calling functions or procedures that aren't so marked even if such functions actually treat the parameter as a constant. I've encountered this enough times in the "C" world to see that it diminishes the utility of "const". Still, overall it's probably better to have it available than not. -- echo ">gra.fcw@2ztr< eryyvZ .T pveR" | rot13 | reverse