comp.lang.ada
 help / color / mirror / Atom feed
From: anon@att.net
Subject: Re: Calling Ada from C (linux/gnat 4.3.2)
Date: Wed, 2 Nov 2011 04:17:42 +0000 (UTC)
Date: 2011-11-02T04:17:42+00:00	[thread overview]
Message-ID: <j8qg94$g58$1@speranza.aioe.org> (raw)
In-Reply-To: 8ba649f0-7ca1-4f05-a158-74b074e401ee@o19g2000vbk.googlegroups.com

Within C use normal external calling

extern <name> <arg list>


And in Ada use a specification file to declare routine.

 procedure <name> ( arg list ) ;
   pragma Export ( C, <name> ) ;

or you could use
   pragma Export ( C, <name>, "<linked name>" ) ;

In Ada the routine may or may not be in a package.


In <8ba649f0-7ca1-4f05-a158-74b074e401ee@o19g2000vbk.googlegroups.com>, awdorrin <awdorrin@gmail.com> writes:
>I am trying to port a program originally written on VxWork to Linux.
>The main program is written in C and spawns new threads and in the new
>threads calls are made to Ada procedures.
>
>In the original program, written with GreenHills AdaMulti, it appears
>that there was a call being made that I am assuming was initializing
>the Ada Runtime's task stack/control block (rts_init_task()) - however
>this is just a guess.
>
>In the version of the program I am migrating, I was seeing things that
>made me believe that the Ada thread's did not have their stacks setup
>properly, so I added the -fstack-check flag to the build.
>
>Now, the C program creates the new thread, which calls the ada
>procedure - and the moment the thread has an opportunity to run - the
>application exits with 'raised STORAGE_ERROR : stack overflow
>detected'
>
>I cannot get gdb to provide me a backtrace, since the program exits.
>If I try to break on the ada procedure name, I get a break, but trying
>to 'step' or 'next' keeps me in the main thread until a 'sleep' call
>lets the other thread run - at which point it raises the exception.
>
>I am assuming that the ada runtime is initializing and the
>STORAGE_ERROR is raised before it gets to execute any of the code in
>my Ada procedure.
>
>I have been trying to search to find what the proper way would be to
>call an Ada procedure from a C pthread, but have had zero luck. I also
>have been unable to determine what the equivalent of the
>'rts_init_task' would be with Gnat.
>
>Any have any ideas?




  parent reply	other threads:[~2011-11-02  4:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-01 18:46 Calling Ada from C (linux/gnat 4.3.2) awdorrin
2011-11-01 20:44 ` Jeffrey Carter
2011-11-01 23:38 ` Simon Wright
2011-11-02  4:17 ` anon [this message]
2011-11-02 16:05 ` Stephen Leake
2011-11-03 16:17   ` awdorrin
2011-11-08 23:22     ` awdorrin
2011-11-09 10:46       ` Pascal Obry
2011-11-09 21:10         ` Ludovic Brenta
2012-02-28 16:28 ` Matt Grochowalski
replies disabled

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