I'm porting some old C++ code to Java. How old? So old that it doesn't just assume a long is 32 bits, it actually checks to make sure and bails if not. That's 1997 or so, by my guess.
I can already hear the programmers in the audience asking, "Why not just interface with the library using JNI?" We decided to port the code because we must support Unix and 64-bit environments, and the library specifically fails on all our Unix machines. We do have the source, so we could modify it... but then we'd be forced to deliver and maintain it, which carries its own set of headaches. So I'm working on 20,000 SLOC.
(Anybody wondered why the site has been so quiet for so long? It's because I'm porting 20,000 SLOC of OLD C++ to Java.)
Most of the code has been pretty straightforward. There have been the usual problems with C++ unsigned types, which don't have any corresponding Java type, as well as a bit of pointer arithmetic confusion. When I get confused, I just write a quick test program and make sure the C++ does what I expect.
The thing that blew my mind today was the weird use of the "magic number" 0x80000000.
Continue reading "Unsigned Subtraction in Old C++ Code" »


