将 32 位应用程序转换为 C 中的 64 位应用程序 [英] Converting 32-bit Application Into 64-bit Application in C

查看:42
本文介绍了将 32 位应用程序转换为 C 中的 64 位应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在用 C 语言将 32 位应用程序转换为 64 位应用程序.该应用程序目前正在 x86 架构(Windows、osx、Unix、Linux)上工作.所以,在开始编码之前,我想知道在转换应用程序时我需要考虑什么.

I am presently working on converting a 32-bit application into a 64-bit application in C. This application is currently working on x86 architecture (Windows, osx, Unix, Linux). So, before starting coding, I wanted to know what do I need to consider while converting the application.

推荐答案

  1. 找出是谁写的.他们是白痴吗?他们是几年前的吗?你能问他们问题吗?他们是否熟悉多个平台和系统的存在?了解程序作者的心态将有助于您在遇到问题时理解问题.
  2. 启动并运行 64 位机器/构建环境.
  3. 用 int 替换 long.完全意识到 LONG 不是 long.
  4. (int)&x 转换和输入替换为 intptr_t 并将 (unsigned int)&x 替换为 uintptr_t
  5. 审计任何依赖于将结构转换为 char* 以对其进行指针运算的内容.
  6. 正则表达式搜索 <4>,以防您假设 4 = sizeof(void*)
  7. 要有耐心.当你发现问题时,如果存在同样的问题,请查看其他地方,并将解决方案包装在一个宏中.
  8. 尽量不要使用 #ifdef RUN64 或任何类似的东西.如果 128 位平台流行起来,你会后悔的.
  9. 将所有更改封装在一些集中式宏中,这些宏将隐藏程序中其他地方的可移植性差异.
  10. 使用覆盖测试人员来帮助确保您已覆盖所有内容(如果适用)
  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 根据评论的建议添加了 uintptr_t 注释.

EDIT added uintptr_t note as suggested by comment.

这篇关于将 32 位应用程序转换为 C 中的 64 位应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆