如何编写可移植 C/C++/Objective-C++针对 Apple iPhone/Mac OSX 的代码?

发布于 2024-09-12 00:02:40 字数 319 浏览 1 评论 0 原文

我正在处理一些在 Win32 和 VxWorks 上运行的 C/C++ 代码。它使用#ifdef WIN32 切换到特定于平台的实现。

我一直在 iPhone 上使用该代码,我想更新它并使其尽可能便携,但我不确定最佳实践是什么。到目前为止,我一直在使用 #ifdef __APPLE__ 块。

我应该使用什么来定位 Apple iPhone 和 Mac OS X?

  • #ifdef __APPLE__ 是最好的方法吗?
  • 有什么需要注意的问题吗?

I'm working with some C/C++ code that runs on Win32 and also VxWorks. It uses #ifdef WIN32 to switch to platform specific implementations.

I've been using the code on the iPhone and I want to update it and keep it as portable as possible, but I'm not sure what's the best practice. So far I've been using #ifdef __APPLE__ blocks.

What should I be using to target Apple iPhone and Mac OS X?

  • Is #ifdef __APPLE__ the best approach?
  • Are there any gotchas to be aware of?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£冰雨忧蓝° 2024-09-19 00:02:40

您可以查看 __IPHONE_OS_VERSION_MIN_REQUIRED 来为不同版本的 iOS 划分代码。您还可以查看分区 基于 CPU,例如 32 位和 64 位 Intel 应用程序之间。

You might look at __IPHONE_OS_VERSION_MIN_REQUIRED to partition code for different versions of iOS. You might also look at partitioning based on CPU, e.g. between 32- and 64-bit Intel apps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文