From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,86f62fb0f98ad93e,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!i28g2000yqa.googlegroups.com!not-for-mail From: Warren Newsgroups: comp.lang.ada Subject: Passing Ada Proc as a C Function Pointer Date: Wed, 4 Aug 2010 09:40:29 -0700 (PDT) Organization: http://groups.google.com Message-ID: NNTP-Posting-Host: 216.121.235.102 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1280940029 20140 127.0.0.1 (4 Aug 2010 16:40:29 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 4 Aug 2010 16:40:29 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i28g2000yqa.googlegroups.com; posting-host=216.121.235.102; posting-account=ENgozAkAAACH-stq5yXctoDQeZQP2E6J User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:12856 Date: 2010-08-04T09:40:29-07:00 List-Id: I some types defined as: type Thread_Context is private; type Stack_Area is new String; type Thread_Proc is access procedure; and an Ada API function: procedure Thread_Start(Context : out Thread_Context; Proc : Thread_Proc; Stack : out Stack_Area) is type C_Func_Ptr is access procedure; pragma Convention(Convention => C, Entity => C_Func_Ptr); procedure avr_thread_start(Context : System.Address; Proc : C_Func_Ptr; 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). Is it vital that the Thread_Proc procedure also be declared as pragma import(C,Proc) ? I'd prefer not to, if possible. There are no arguments passed-- I only need to launch the passed Ada procedure from the C side (in a thread). The avr_thread_start C routine is declared as: void avr_thread_start( avr_thread_context* context, void (*fn)(void), uint8_t* stack, uint16_t stack_size ); Warren