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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,86f62fb0f98ad93e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!feeder.news-service.com!xlned.com!feeder1.xlned.com!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Passing Ada Proc as a C Function Pointer Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Wed, 4 Aug 2010 19:14:25 +0200 Message-ID: <18lgtff9nqvia.bxr7lzz8gk36.dlg@40tude.net> NNTP-Posting-Date: 04 Aug 2010 19:14:21 CEST NNTP-Posting-Host: 2b950ee8.newsspool3.arcor-online.net X-Trace: DXC=]=Hj7RV\GfN74okIm;?DS@McF=Q^Z^V3H4Fo<]lROoRA8kF 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