What to do about Carbon functions that are deprecated in MacOS/X 10.8.x?

こ雲淡風輕ζ 提交于 2020-01-01 11:41:07

问题


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]

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.

Specific questions I have:

  1. Why are these functions deprecated?
  2. What functions should I call instead?
  3. Is there some secret documentation repository that I don't know about that would answer these kinds of questions for me?

回答1:


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

  1. UpTime() can be replaced by a call to mach_absolute_time(), as detailed here.
  2. AbsoluteToNanoseconds() can be replaced by a bit of math, as shown at the above link.
  3. MPProcessors can be replaced by a call to host_info(), like this:
#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;


来源:https://stackoverflow.com/questions/16049181/what-to-do-about-carbon-functions-that-are-deprecated-in-macos-x-10-8-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!