Valhalla Legends Forums Archive | General Programming | 64 bit programs

AuthorMessageTime
I_Smell_Tuna
To port a program from 32 to 64 bits do you just have to recompile it with a 64 bit compiler?
May 10, 2005, 6:50 PM
Myndfyr
There's potentially a lot more to it than that.
May 10, 2005, 9:09 PM
Yoni
Sometimes that's all you have to do.
A 64-bit compiler will compile all pointer variables as 64-bit stack variables/registers.

Note that if you code in Win32, you have to code intelligently.
Ever since Microsoft became 64-bit-aware, the Platform SDK has changed slightly. Functions and macros were added that have the word "Ptr" on the end, and it's a best practice to use them always, instead of the old ones.

Do not blindly assume in your code that the sizeof(pointer) is 4 bytes. Whenever needed, specify the sizeof operator explicitly. Don't ever perform a reinterpret cast to "long", for instance.

Example: They defined new types, "LONG_PTR" and "ULONG_PTR", that are signed/unsigned integers, respectively, with an amount of bits that depends on whether compiled in 32-bit or 64-bit mode. By definition, it will be safe to cast a pointer to ULONG_PTR and back without losing bits.

Example: Instead of GetWindowLong, use GetWindowLongPtr. This gives your window a value associated with an index label, except now the value is a LONG_PTR and not a LONG like it used to be. (You use GWLP_label instead of GWL_label, etc.)

Programmers used to assume things about pointers, such as that the most significant bit (which may falsely assumed to be "bit 31") of the pointer is always 0 in user mode and always 1 in kernel mode, and therefore it is not necessary, and something else can make good use of this bit. 64-bit compatibility is not the only reason that this assumption is terrible. Do not assume anything about the bit layout of your pointer.

A program coded intelligently, with the programmer considering the possibility of the sizeof(pointer) changing, will probably be as easy to port to a 64-bit environment as simply compiling with the compiler in 64-bit mode.
May 11, 2005, 11:52 AM
Adron
[quote author=Yoni link=topic=11548.msg112046#msg112046 date=1115812377]
Do not assume anything about the bit layout of your pointer.
[/quote]

What you may need to do bitwise on a pointer is check for pointer alignment.
May 11, 2005, 4:35 PM
Yoni
Hmm, true. When I was writing that, I was thinking of the more significant bits, not the less significant bits.

Ok, assume something about the bit layout of your pointer if and only if it is required by the situation. :P
May 12, 2005, 7:53 PM

Search