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:
- Why are these functions deprecated?
- What functions should I call instead?
- Is there some secret documentation repository that I don't know about that would answer these kinds of questions for me?
I've found usable replacements for the functions listed above:
- UpTime() can be replaced by a call to mach_absolute_time(), as detailed here.
- AbsoluteToNanoseconds() can be replaced by a bit of math, as shown at the above link.
- 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