comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@acm.nospam.org>
Subject: Re: What is the best way to define the Imported C function
Date: Sun, 27 Jan 2008 01:31:46 GMT
Date: 2008-01-27T01:31:46+00:00	[thread overview]
Message-ID: <6aRmj.3192$yE1.490@attbi_s21> (raw)
In-Reply-To: <5db8e5dd-9632-4aef-b1e3-8cc304bcd748@u10g2000prn.googlegroups.com>

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



  parent reply	other threads:[~2008-01-27  1:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-26  5:05 What is the best way to define the Imported C function qunying
2008-01-26 10:15 ` Martin Krischik
2008-01-26 16:24   ` qunying
2008-01-26 10:56 ` Dmitry A. Kazakov
2008-01-26 12:15   ` Stefan Lucks
2008-01-27  1:31 ` Jeffrey R. Carter [this message]
2008-01-28 17:18   ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox