Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?
like image 646
Jeremy Friesner Avatar asked Nov 03 '22 23:11

Jeremy Friesner


1 Answers

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;
like image 119
Jeremy Friesner Avatar answered Nov 08 '22 02:11

Jeremy Friesner