Converting 32-bit Application Into 64-bit Application in C

前端 未结 9 1069
悲&欢浪女
悲&欢浪女 2020-12-04 17:02

I am presently working on converting a 32bits application into a 64bits application in C. This application is currently working on x86 architecture (Windows, osx, Unix, Linu

9条回答
  •  离开以前
    2020-12-04 17:35

    1. Find out who wrote it. Are they an idiot? Are they you from a few years ago? Can you ask them questions? Are they familiar with the existence of multiple platforms and systems? Knowing the mind-set of the author(s) of the program will help you understand problems when you run into them.
    2. Get a 64-bit machine/build environment up and running.
    3. Replace long with int. Be perfectly aware that LONG is not long.
    4. Replace (int)&x casts and typing with intptr_t and (unsigned int)&x with uintptr_t
    5. Audit anything that relies on casting structures to char* to do pointer arithmetic with it.
    6. Regex search for \<4\> in case you assumed 4 = sizeof(void*)
    7. Be patient. When you find a problem, look elsewhere if the same problem exists, and wrap the solution in a macro.
    8. Try not to use #ifdef RUN64 or anything similar. You'll regret it if 128-bit platforms ever go into vogue.
    9. Encapsulate all of your changes in terms of some centralized macros that'll hide the portability differences elsewhere in your program.
    10. Use a coverage tester to help make sure you've covered everything (if appropriate)

    EDIT added uintptr_t note as suggested by comment.

提交回复
热议问题