I’ve almost finished the mostly-mechanical first pass of converting the C GNU Chess code to Java syntax. I haven’t tried to compile yet, but there’s about six files out of thirty-plus that IDEA (world’s greatest IDE) says contain syntax errors. Most of them are complicated printf() calls that I put off, thinking I might just start using Java 5, which comes with a printf() of its own. Also remaining are some threading issues like the use of the signal() function.
The most common C features in C GNU Chess that needed converting to Java:
- primitive typedefs
- better readability and type-checking by using
BitBoardinstead oflong. I started using Java classes for these typedefs, butBitBoardoperations much be fast, and I’ve have to deal with translating between the different semantics for assignment of primitives and objects. - macros
- most were just constants; I made functions for most of the others, except a few like
CLEARBITthat seemed easier to inline. - primitive reference parameters
- I used the return value if possible; otherwise I passed the params in an array.
printfandscanf- only a few of these we hard to convert; Java 5’s
printfwill help enum- something else that’s available in Java 5
- implicit bools
- I can’t count how many times I converted “
if (c)” to “if (c!=0)“ goto- Java doesn’t have
goto, but it does allow labels onbreakandcontinue, which sometimes resulted in creating dummy loops just so I could use a labeledbreakinstead of agoto.
Did you give any of the c -> java converters a try? Like Jazillian or Ephedra?
(Regardless, shouldn’t you be moving that mulch pile instead of sitting in front of the computer?)
NOW you tell me! I looked for such tools without much luck a while back — maybe my searches were focusing too much on C++ to Java translators. Anyway Jazillian is pretty expensive for hobbyists use, and the online demo didn’t work too well on a non-trivial printf() that I tried. Ephedra looks promising, but it’s only available in C++ source that only compiles with Visual Age C++.