* Help with ADA and C function pointers.
@ 1996-11-20 0:00 Wendell P Beckwith
1996-11-21 0:00 ` Aaron Quantz
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Wendell P Beckwith @ 1996-11-20 0:00 UTC (permalink / raw)
I have an ada main procedure which needs to pass the address of an ada
function to a C funciton. Using gnat 3.05 the following compiles and
generates an executable, but it cores when you run it. I knew it would
because no where am I assigning a function to be passed. That is what
I'd like to know how to do. Please respond to my work email, since I'm
not in this group alot. Thanks!!
Wendell
-- my test main
with Text_IO, Interfaces.C;
use Text_IO;
Procedure Gmain is
Function func(d : in Integer) return Integer is
Begin
return (2 * d);
End;
type func_type is access Function(d : in Integer) return Integer;
funcptr : func_type;
Procedure Stuff(f : in func_type);
pragma Import(C, Stuff, "stuff");
Begin
Stuff(funcptr);
End;
-- my test C function using the ada callback
#include <stdio.h>
void stuff(int (*function)(int))
{
printf("Value = %d\n", (*function)(10));
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Help with ADA and C function pointers.
1996-11-20 0:00 Help with ADA and C function pointers Wendell P Beckwith
@ 1996-11-21 0:00 ` Aaron Quantz
1996-11-22 0:00 ` THANKS! (was Help with ADA and C function pointers.) Wendell P Beckwith
1996-11-22 0:00 ` Help with ADA and C function pointers Stephen Leake
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Aaron Quantz @ 1996-11-21 0:00 UTC (permalink / raw)
How about the 'address attribute?
Regards,
Aaron Quantz
Mgr Software Development, TCS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HR Textron | Phone: (805) 253-5471
25200 W. Rye Canyon Rd. | Fax: (805) 253-5962
Valencia, CA USA 91355-1265 | Email: aqhrt@ibm.net
Visit the Textron web site: http://www.textron.com
----------------------------------------------------------------------
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Help with ADA and C function pointers.
1996-11-20 0:00 Help with ADA and C function pointers Wendell P Beckwith
1996-11-21 0:00 ` Aaron Quantz
@ 1996-11-22 0:00 ` Stephen Leake
1996-11-26 0:00 ` fd
1996-11-26 0:00 ` fd
3 siblings, 0 replies; 6+ messages in thread
From: Stephen Leake @ 1996-11-22 0:00 UTC (permalink / raw)
Wendell P Beckwith wrote:
>
> [snip]
>
> -- my test main
> with Text_IO, Interfaces.C;
> use Text_IO;
>
> Procedure Gmain is
>
> Function func(d : in Integer) return Integer is
> Begin
> return (2 * d);
> End;
> type func_type is access Function(d : in Integer) return Integer;
> funcptr : func_type;
>
> Procedure Stuff(f : in func_type);
> pragma Import(C, Stuff, "stuff");
>
> Begin
> Stuff(funcptr);
> End;
>
Try:
Stuff (Func'access);
You don't actually need the funcptr variable.
> Please respond to my work email, since I'm
> not in this group alot. Thanks!!
>
Sorry, you'll have to read thru the news just like the rest of us; we
hope you'll be able to contribute something!
--
- Stephe
^ permalink raw reply [flat|nested] 6+ messages in thread
* THANKS! (was Help with ADA and C function pointers.)
1996-11-21 0:00 ` Aaron Quantz
@ 1996-11-22 0:00 ` Wendell P Beckwith
0 siblings, 0 replies; 6+ messages in thread
From: Wendell P Beckwith @ 1996-11-22 0:00 UTC (permalink / raw)
To all those who responded to my post I'd like to say thanks!
Wendell
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Help with ADA and C function pointers.
1996-11-20 0:00 Help with ADA and C function pointers Wendell P Beckwith
` (2 preceding siblings ...)
1996-11-26 0:00 ` fd
@ 1996-11-26 0:00 ` fd
3 siblings, 0 replies; 6+ messages in thread
From: fd @ 1996-11-26 0:00 UTC (permalink / raw)
Wendell P Beckwith (wbeckwit@rsa.hisd.harris.com) wrote:
: I have an ada main procedure which needs to pass the address of an ada
: function to a C funciton. Using gnat 3.05 the following compiles and
: generates an executable, but it cores when you run it. I knew it would
: because no where am I assigning a function to be passed. That is what
: I'd like to know how to do. Please respond to my work email, since I'm
: not in this group alot. Thanks!!
: Wendell
: -- my test main
: with Text_IO, Interfaces.C;
: use Text_IO;
: Procedure Gmain is
: Function func(d : in Integer) return Integer is
: Begin
: return (2 * d);
: End;
: type func_type is access Function(d : in Integer) return Integer;
: funcptr : func_type;
Here funcptr value is NULL
:
: Procedure Stuff(f : in func_type);
: pragma Import(C, Stuff, "stuff");
:
: Begin
: Stuff(funcptr);
there is a problem, funcptr is still equal to NULL
I will try Stuff(func'adress) and you don't need funcptr.
Hope it will help.
: End;
: -- my test C function using the ada callback
: #include <stdio.h>
: void stuff(int (*function)(int))
: {
: printf("Value = %d\n", (*function)(10));
: }
franck.duluc@avions.aerospatiale.fr
Regards.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Help with ADA and C function pointers.
1996-11-20 0:00 Help with ADA and C function pointers Wendell P Beckwith
1996-11-21 0:00 ` Aaron Quantz
1996-11-22 0:00 ` Help with ADA and C function pointers Stephen Leake
@ 1996-11-26 0:00 ` fd
1996-11-26 0:00 ` fd
3 siblings, 0 replies; 6+ messages in thread
From: fd @ 1996-11-26 0:00 UTC (permalink / raw)
Wendell P Beckwith (wbeckwit@rsa.hisd.harris.com) wrote:
: I have an ada main procedure which needs to pass the address of an ada
: function to a C funciton. Using gnat 3.05 the following compiles and
: generates an executable, but it cores when you run it. I knew it would
: because no where am I assigning a function to be passed. That is what
: I'd like to know how to do. Please respond to my work email, since I'm
: not in this group alot. Thanks!!
: Wendell
: -- my test main
: with Text_IO, Interfaces.C;
: use Text_IO;
: Procedure Gmain is
: Function func(d : in Integer) return Integer is
: Begin
: return (2 * d);
: End;
: type func_type is access Function(d : in Integer) return Integer;
: funcptr : func_type;
Here funcptr value is NULL
:
: Procedure Stuff(f : in func_type);
: pragma Import(C, Stuff, "stuff");
:
: Begin
: Stuff(funcptr);
there is a problem, funcptr is still equal to NULL
I will try Stuff(func'adress) and you don't need funcptr.
Hope it will help.
: End;
: -- my test C function using the ada callback
: #include <stdio.h>
: void stuff(int (*function)(int))
: {
: printf("Value = %d\n", (*function)(10));
: }
franck.duluc@avions.aerospatiale.fr
Regards.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1996-11-26 0:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-20 0:00 Help with ADA and C function pointers Wendell P Beckwith
1996-11-21 0:00 ` Aaron Quantz
1996-11-22 0:00 ` THANKS! (was Help with ADA and C function pointers.) Wendell P Beckwith
1996-11-22 0:00 ` Help with ADA and C function pointers Stephen Leake
1996-11-26 0:00 ` fd
1996-11-26 0:00 ` fd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox