Wed 18 May 2011
Things I Learned During the 64-bit Port – Volume 1
Posted by Dan H under Programming, SlickEdit Products
[5] Comments
I haven’t written a ton of posts for the SlickEdit blog. I tend to save it for instances where I find something humorous that I can cross-reference. I actually do not have a lot of humor to offer this time, but having worked through our 64-bit port in the last few months I do have a few interesting observations that are worth sharing. Also, my manager asked if I would write something, and assured me that something noteworthy must have occurred during the 64-bit port. He also mentioned that it should not involve any of the colorful string of adjectives that came out of of my cubical during that period of time. It occurs to me as I write this that he might ask this again, so I’ve gone with the “Volume 1″ naming scheme… of course if I never write about this topic again it wouldn’t be the first time that something named “Volume 1″ is never followed up with a “Volume 2″.
As we began the 64-bit port we faced the same challenges as any company dealing with a large established code base. A lot of typing issues. In the 64-bit world, long means different things on different platforms. In some cases it doesn’t make any difference, in others it does. These cases have to be carefully examined. In some cases the solution was not to use long at all. There were cases where we had used long because it seemed like the right thing to do, but on careful examination, int is completely sufficient.
However, the most interesting case we came up against was a call to the X-Windows library. The specific call had looked like this for years:
XtVaSetValues(xftXtTopLevelShell,
XtNx, -1000,
XtNy, -1000,
XtNwidth, 100,
XtNheight, 100,
XtNmappedWhenManaged, False,
0);
And it was fine in our initial builds and testing. But as we approached our first beta and started to compile our release configuration, the editor would crash on this line. I spent an evening trying different compiler options, and different versions of the compiler, because I simply did not see a problem with this line. But there is one.
The functions that start with XtVa take a variable number of arguments. In this case, that last argument – the ’0′ – is a pointer. On a 32-bit system, a pointer is 32-bits wide, and an int is 32-bits wide. So passing 0 works just fine. On a 64-bit system, pointers are 64-bits wide, and NULL is a 64-bit unsigned number. 0, however, is a 32-bit signed number. Which actually works fine… until you turn on compiler optimizations.
Here is the corrected code:
XtVaSetValues(xftXtTopLevelShell,
XtNx, -1000,
XtNy, -1000,
XtNwidth, 100,
XtNheight, 100,
XtNmappedWhenManaged, False,
NULL);
This wasn’t the most confusing problem I encountered, in fact I’m sure to a seasoned 64-bit Linux guru it should not have a been a problem at all. But it was one of the things I felt was interesting enough to share here.
Anybody have a good 64-bit porting horror story? Let’s hear them.
5 Responses to “ Things I Learned During the 64-bit Port – Volume 1 ”
Comments:
Leave a Reply
Trackbacks & Pingbacks:
-
Trackback from Windows 8 ARM Processors
August 17th, 2011 at 7:03 amRelated……
[...] Despite the fact that it didnt win, we feel this web site should receive a mention [...]…
May 25th, 2011 at 3:40 pm
I feel with you Dan.. Had to port some SW to x64 but providing a binary compatible interface to 32 and 64 bit worlds. I’ve also encountered funny surprises…
I’m sure this ’0′ effect will be a problem for a number of applications.
Regards, HS2
June 5th, 2011 at 8:31 pm
Maybe better advice would be to actually *read* a decent 64-bit porting guide before actually trying to port your code, as any decent one would deal with this basic and well-known issue.
But hey, why do that when you can in fact dedicate an entire blog post to some small piece of technical errata just to show how smart you are?
March 23rd, 2012 at 10:15 am
I found it quite easy to port 32-bit applications to 64-bit after doing just as “zzz” said. Read. Sorry for the late response, but I had to include my two cents.
March 23rd, 2012 at 10:16 am
32 to 64 is hard for me. I don’t read good english so now it is difficult to gain smarts about the topics.