* Passing an Ada array to a C function
@ 2001-09-11 1:21 Lin
2001-09-11 2:32 ` David Botton
0 siblings, 1 reply; 5+ messages in thread
From: Lin @ 2001-09-11 1:21 UTC (permalink / raw)
If an Ada array holds the pointers pointing to a String (char_array),
how can I pass the Ada array to an C funtion with an array as formal
parameter? Is the "char_array" of Ada occupies the same bytes as the
"char" of C?
Many thnks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Passing an Ada array to a C function
2001-09-11 1:21 Passing an Ada array to a C function Lin
@ 2001-09-11 2:32 ` David Botton
2001-09-18 13:37 ` Thierry Bernier
[not found] ` <3BA74E07.60E105C2@fr.thalesgroup.com>
0 siblings, 2 replies; 5+ messages in thread
From: David Botton @ 2001-09-11 2:32 UTC (permalink / raw)
To: comp.lang.ada
procedure My_C_Func (S : Interfaces.C.char_array);
pragma Import (C, My_C_Func);
is equal to
void My_C_Func (char* s);
A Char_Array contains more information than a char* and does not per se
occupy the same number of bytes, but take a look at the ref manual where it
describes that compilers must make the above possible.
The Ada interface to C in most code and bindings I have seen highly
underused. There is all kinds of neat stuff you can do by just setting up
the procedure specs properly. Take a look at the body of some of the
GWindows packages (http://www.adapower.com/gwindows) for some good ideas. I
chose not to write a set stand alone thin Win32 bindings since that would
cripple the power of the Ada interface to C and instead tailored each import
spec in the function body to match what I wanted to accomplish.
David Botton
----- Original Message -----
From: "Lin" <lin@post.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Monday, September 10, 2001 9:21 PM
Subject: Passing an Ada array to a C function
> If an Ada array holds the pointers pointing to a String (char_array),
> how can I pass the Ada array to an C funtion with an array as formal
> parameter? Is the "char_array" of Ada occupies the same bytes as the
> "char" of C?
>
> Many thnks.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Passing an Ada array to a C function
2001-09-11 2:32 ` David Botton
@ 2001-09-18 13:37 ` Thierry Bernier
[not found] ` <3BA74E07.60E105C2@fr.thalesgroup.com>
1 sibling, 0 replies; 5+ messages in thread
From: Thierry Bernier @ 2001-09-18 13:37 UTC (permalink / raw)
To: comp.lang.ada
David Botton a écrit :
> procedure My_C_Func (S : Interfaces.C.char_array);
> pragma Import (C, My_C_Func);
>
> is equal to
>
> void My_C_Func (char* s);
void My_C_Func (const char *s);
--
Thierry Bernier
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Passing an Ada array to a C function
[not found] ` <3BA74E07.60E105C2@fr.thalesgroup.com>
@ 2001-09-20 2:31 ` David Botton
2001-09-20 12:07 ` Robert Dewar
0 siblings, 1 reply; 5+ messages in thread
From: David Botton @ 2001-09-20 2:31 UTC (permalink / raw)
To: comp.lang.ada
Depends on the age of your compiler. C and C++ were designed by committee
(to "have fun") unlike Ada so things are very rarely concrete.
> void My_C_Func (char* s);
> void My_C_Func (const char *s);
David Botton
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Passing an Ada array to a C function
2001-09-20 2:31 ` David Botton
@ 2001-09-20 12:07 ` Robert Dewar
0 siblings, 0 replies; 5+ messages in thread
From: Robert Dewar @ 2001-09-20 12:07 UTC (permalink / raw)
"David Botton" <David@Botton.com> wrote in message news:<mailman.1000953137.8671.comp.lang.ada@ada.eu.org>...
> Depends on the age of your compiler. C and C++ were designed by committee
> (to "have fun") unlike Ada so things are very rarely concrete.
>
> > void My_C_Func (char* s);
>
> > void My_C_Func (const char *s);
>
>
> David Botton
I don't think it is fair to claim that C and C++ were
designed by committee any more than Ada was.
In all three cases, the basic language design was the work
of a single coherent design team (in the Ada case, this was
more of a team, in the C++ case, more of an individual).
The preliminary design was then debated and (significantly)
modified by a committee (Ada 95 would not have looked the
same if the design team had been able to follow only its
own preference :-)
Let's not make the mistake of bashing C and C++ where
the bashing is not fair :-)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-09-20 12:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-11 1:21 Passing an Ada array to a C function Lin
2001-09-11 2:32 ` David Botton
2001-09-18 13:37 ` Thierry Bernier
[not found] ` <3BA74E07.60E105C2@fr.thalesgroup.com>
2001-09-20 2:31 ` David Botton
2001-09-20 12:07 ` Robert Dewar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox