MacOS / X 10.8.x中不推荐使用的Carbon函数怎么办? [英] What to do about Carbon functions that are deprecated in MacOS/X 10.8.x?

查看:161
本文介绍了MacOS / X 10.8.x中不推荐使用的Carbon函数怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已经存在了一段时间(超过10年)的C ++代码库,并且可以正常运行,但是我注意到当我在OS / X 10.8.x(Mountain Lion)下进行编译时,编译器会发出关于它调用的某些Carbon函数的弃用警告:

I have a C++ codebase that has been around for a while (10+ years) and it compiles and runs fine, but I notice that when I compile it under OS/X 10.8.x (Mountain Lion), the compiler emits deprecation warnings about some of the Carbon functions it calls:

../system/SetupSystem.cpp:575:44: warning: 'UpTime' is deprecated: first
  deprecated in OS X 10.8 [-Wdeprecated-declarations]
../system/SetupSystem.cpp:575:22: warning: 'AbsoluteToNanoseconds' is
  deprecated: first deprecated in OS X 10.8 [-Wdeprecated-declarations]
../system/SystemInfo.cpp:249:25: warning: 'MPProcessors' is deprecated: first deprecated in OS X 10.7 [-Wdeprecated-declarations]

我想将此代码库升级为Apple批准的新工作方式(因此如果/当苹果最终删除这些功能时,避免警告和将来的痛苦),但我不知道新标准是什么。我浏览了developer.apple.com上的OS / X文档,但是缺少搜索技能或者缺少他们的文档,因为我几乎找不到这些功能,也没有替换它们。

I'd like to upgrade this codebase to the new Apple-approved way of doing things (and thus avoid the warnings and future pain if/when Apple finally removes these functions), but I can't figure out what the new standard is. I looked through the OS/X documentation at developer.apple.com, but either my searching skills are lacking or their documentation is, as I find next to nothing about these functions and nothing about their replacements.

我遇到的特定问题:


  1. 为什么不推荐使用这些功能?

  2. 应该改用什么函数?

  3. 是否存在一些我不知道的秘密文档存储库,可以为我回答这些问题?


推荐答案

我找到了上面列出的功能的可用替代品:

I've found usable replacements for the functions listed above:


  1. UpTime()可以替换为对mach_absolute_time()的调用,详情请参见此处

  2. AbsoluteToNanoseconds()可以用一点数学代替,如上面的链接所示。

  3. MPProcessors可以通过调用来代替host_info(),如下所示:




#include <mach/mach_host.h>

mach_msg_type_number_t infoCount = HOST_BASIC_INFO_COUNT;
host_info(gHostPort, HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
int numProcessors = hostInfo.avail_cpus;

这篇关于MacOS / X 10.8.x中不推荐使用的Carbon函数怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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