[PLUG] Converting C to java

Phil Tomson ptkwt at aracnet.com
Mon Jun 9 13:09:02 UTC 2003



On Mon, 9 Jun 2003, Rich Shepard wrote:

>   Has anyone here done this? I'm looking for 1) tools (such as C2J and
> ephedra) that can automate at least part of the port and 2) estimates of how
> much time might be required (for the non-UI portions of the program). That
> is, would 100 lines/hour be reasonable for mathematical functions and the
> like?
>

Does Java have some sort of extention mechanism that lets you wrap your C
code into a shared lib that can be loaded into Java?  Actually, I think it
does since the swig page lists java (http://www.swig.org) as a supported
language.  That way you can just use your C code unchanged - AND since
you're talking about mathematical functions they'll be a lot faster in C
than in Java. I'd recommend checking out swig (Simple wrapper
interface generator) for doing this for you automatically.  Swig is a
great tool.  I used it to wrap a computational geometry C++ lib so that I
could access it's objects from Ruby.  I suspect you can do the same with
your code to access the C functions from Java.  Another advantage of swig
is that if you decide that you want to use another language later (like
Perl or Ruby or Python instead of Java) then you can very easily use the
same C code and by changing a commandline argument to swig, generate a
wrapper for the language of your choice.

BTW: I'm doing a talk at OSCON on mixed language development with Swig.

Phil







More information about the PLUG mailing list