Re: What is the best way to define the Imported C function
- From: "Jeffrey R. Carter" <spam.jrcarter.not@xxxxxxxxxxxxxx>
- Date: Sun, 27 Jan 2008 01:31:46 GMT
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
.
- Follow-Ups:
- Re: What is the best way to define the Imported C function
- From: Adam Beneschan
- Re: What is the best way to define the Imported C function
- References:
- What is the best way to define the Imported C function
- From: qunying
- What is the best way to define the Imported C function
- Prev by Date: Re: What is the best way to define the Imported C function
- Next by Date: Compilation without implementation source
- Previous by thread: Re: What is the best way to define the Imported C function
- Next by thread: Re: What is the best way to define the Imported C function
- Index(es):
Relevant Pages
|