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: 103376,f23882dec7858ff X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.glorb.com!wns13feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: What is the best way to define the Imported C function References: <5db8e5dd-9632-4aef-b1e3-8cc304bcd748@u10g2000prn.googlegroups.com> In-Reply-To: <5db8e5dd-9632-4aef-b1e3-8cc304bcd748@u10g2000prn.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <6aRmj.3192$yE1.490@attbi_s21> NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1201397506 12.201.97.213 (Sun, 27 Jan 2008 01:31:46 GMT) NNTP-Posting-Date: Sun, 27 Jan 2008 01:31:46 GMT Organization: AT&T ASP.att.net Date: Sun, 27 Jan 2008 01:31:46 GMT Xref: g2news1.google.com comp.lang.ada:19608 Date: 2008-01-27T01:31:46+00:00 List-Id: qunying wrote: > > I am learning Ada and try to test the interface with C. I would suggest that you learn Ada before trying to interface it to C. But if you are going to do it, use the types in Interfaces.C and its children, or types declared Convention C, not String and Integer; and don't pass explicit pointer values when Ada's interfacing rules will do the right thing for you. > for this function, what is the best way to define the function in Ada? > > int xcb_parse_display(const char *name, char **host, int *display, int > *screen); I can't help you (and really, neither can those who have replied to you) because the C specification isn't a specification; it doesn't tell us how the function uses its parameters. Without that information, we can't tell how to interface to it. The problem is that C uses the same construct for many conceptually different things. For example: void f (char* c); may represent something that is conceptually equivalent to Ada's procedure F (C : in Character); [unlikely, but possible] procedure F (C : in out Character); procedure F (C : out Character); procedure F (C : in String); procedure F (C : in out String); procedure F (C : out String); Given the common practice of using "char" to represent what Ada calls a Storage_Element, and "char[]" or "char*" for Storage_Array, this single C declaration may mean any of 12 different things. -- Jeff Carter "C++ is like jamming a helicopter inside a Miata and expecting some sort of improvement." Drew Olbrich 51