comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Passing Ada Proc as a C Function Pointer
Date: Wed, 4 Aug 2010 19:14:25 +0200
Date: 2010-08-04T19:14:21+02:00	[thread overview]
Message-ID: <18lgtff9nqvia.bxr7lzz8gk36.dlg@40tude.net> (raw)
In-Reply-To: bc887840-ef75-405a-8019-8e44552a92d3@i28g2000yqa.googlegroups.com

On Wed, 4 Aug 2010 09:40:29 -0700 (PDT), Warren wrote:

> I some types defined as:
> 
>   type Thread_Context is private;

pragma Convention (C, Thread_Context);

>   type Stack_Area is new String;

pragma Convention (C, Stack_Area);  -- Won't work with String

>   type Thread_Proc is access procedure;

pragma Convention (C, Thread_Proc);  -- Called from C
 
> and an Ada API function:
> 
>     procedure Thread_Start(Context : out Thread_Context;

Context : access Thread_Context;
    -- Prevent temp object, if the type is not limited

> Proc : Thread_Proc;
> Stack : out Stack_Area) is

Stack : access Stack_Area

>         procedure avr_thread_start(Context : System.Address;
>                     Proc : C_Func_Ptr;

Proc : Thread_Proc;

>                     Stack : System.Address;
>                     Size : Unsigned_16);
>         pragma import(C,avr_thread_start,"avr_thread_start");
> 
>         Func : C_Func_Ptr := Proc.all'Access;
>     begin
> 
> avr_thread_start(Context'Address,Func,Stack(Stack'First)'Address,Stack'Length);
> 
>     end Thread_Start;
> 
> Because this part of the Ada code is not working, I'm suspicious that
> the passed function pointer is incorrect (I have an all-C thread
> example working).

You have to pass a pointer to a procedure of C convention. You also must
ensure that other parameters aren't passed by copy.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2010-08-04 17:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-04 16:40 Passing Ada Proc as a C Function Pointer Warren
2010-08-04 17:14 ` Dmitry A. Kazakov [this message]
2010-08-05  0:24   ` Warren
2010-08-04 18:46 ` Jeffrey Carter
2010-08-04 19:36   ` Dmitry A. Kazakov
2010-08-05  0:42   ` Warren
2010-08-05  0:55     ` Warren
2010-08-04 19:46 ` Simon Wright
2010-08-05  0:45   ` Warren
2010-08-05  7:33     ` Rolf
2010-08-05 20:50       ` Simon Wright
  -- strict thread matches above, loose matches on Subject: below --
2010-08-05 14:31 Warren
2010-08-05 15:37 ` Warren
2010-08-05 16:51   ` Warren
replies disabled

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