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-Thread: a07f3367d7,17f2366fc6172420 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Access Type Date: Mon, 27 Dec 2010 02:50:13 +0100 Organization: A noiseless patient Spider Message-ID: <87hbe0m1be.fsf@ludovic-brenta.org> References: <8d8e1094-d021-4456-85fb-bbb2f3911334@m7g2000vbn.googlegroups.com> <3af2d3d1-ede9-4255-a31b-c5f66c6cee2e@c2g2000yqc.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx03.eternal-september.org; posting-host="vhtspQ5pQqftjY2c+x4BbQ"; logging-data="8050"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18QSNFqpxBl+C7THUbZHGuQ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:2wxm4yz3kLxIvum4+Rjz+RJqMiQ= sha1:syGLmgICojmBzLBuBrQFv7L0JFo= Xref: g2news2.google.com comp.lang.ada:17119 Date: 2010-12-27T02:50:13+01:00 List-Id: kug1977 writes on comp.lang.ada: > Pointers are an obstacle for most newbies and it takes some time to > understand the principle in the first time. Now I've to learn it the > Ada-way ... The Ada way is not to use pointers at all... you can pass a string of characters to a C function without pointers, like this: with Interfaces.C; procedure P is procedure C_Function (String : in Interfaces.C.char_array); pragma Import (C, C_Function, "foo"); begin C_Function (Interfaces.C.To_C ("Ada string")); end P; This will correctly append a null character to "Ada string" and pass the address of the result to the C_Function. Another idea: if you have a fixed number of service names, maybe you should encapsulate them into a package of their own and only expose an enumerated type and a getter function, like so: with Interfaces.C; package Services is type Service is (Open, ...); function Name (S : in Service) return Interfaces.C.char_array; end Services; with Interfaces.C.Strings; package body Services is type String_Access is access String; All_Services : constant array (Service) of Interfaces.C.Strings.chars_ptr := (Open => Interfaces.C.Strings.New_String ("open"), ... ); function Name (S : in Service) return Interfaces.C.char_array is begin return Interfaces.C.Strings.Value (All_Services (S)); end Name; end Services; HTH -- Ludovic Brenta.