kk_oop@yahoo.com wrote: > James Alan Farrell wrote: > >>We have a similar problem with C, and found it is pretty straight >>forward to wrap Ada in C calls. Could you do that, then call the C >>calls from Java? >> >>JAF > > > JNI seems to support the Java/C connection. So this may work. In your > problem space, did you have bi-directional communication between C and > Ada? In other words, were you able to have C invoke Ada calls and Ada > invoke C calls? > > Thanks! > > Ken > Yes. Our Ada compiler is the gnat (gcc) compiler, and our main program is in C. The tool runs on linux, so we use gcc all around and the tools work very nicely together. We call ada_init() in the C code (you will probably have to do the same). From there it is mostly a matter of making sure both languages have the correct interface and calling in either direction is really pretty easy. In Ada, use pragma(C, ...). On the C side things are a bit messy. Out and in/out parameters become pointers. This works rather better than I would've thought (probably the pragma forces such parameters to be pointers where they would not always be otherwise). But even so, we have a lot of C functions with void * parameters instead of typed pointers and ints instead of Boolean, etc. When an Ada function returns an unsized array (such as Wide_String(<>)) we wrap it in an Ada procedure that returns a wchar_t and string size. (There is a way to ensure the string is null terminated so C does not need the size, but this method is good for any array type. See ARM B.3.1) One interesting problem we had was converting Ada access types to C pointers. An Ada access type is a higher level construct than a C pointer, which means it may or might not actually "point" to the desired location in memory. What we found in practice is that arrays that are sized dynamically have a 64 bit entity in which the first 32 bits do point to the object of interest. I'm not sure I'm happy with our solution and others here probably have better ideas than we, so instead of saying what we did, I'll look to see if anyone posts any suggestions ;) For exceptions raised in Ada, we catch them in Ada and call a C function that passes to C information on the raised exception. (I wouldn't want to mess with anything like trying to pass the exception itself to C++ then on to Java) I can't think of any other gotcha's that we experienced. It really has been a lot easier than I thought coming in to the project. Have fun! James