17 Apr 06:13
CLK_TCK
From: Solar Designer <solar@...>
Subject: CLK_TCK
Newsgroups: gmane.comp.misc.xvendor
Date: 2006-04-17 04:16:24 GMT
Subject: CLK_TCK
Newsgroups: gmane.comp.misc.xvendor
Date: 2006-04-17 04:16:24 GMT
Hi, CLK_TCK has been obsolescent for years, yet many programs (including some of mine) continued to use it - until very recently. glibc 2.4 no longer defines CLK_TCK by default. Unfortunately, what most package maintainers appear to be doing is replace uses of CLK_TCK with CLOCKS_PER_SEC. This is wrong. CLK_TCK is for times(), whereas CLOCKS_PER_SEC is for clock(). These can actually be different values (100 vs. 1000000 is a practical example) - although often they're the same, meaning that the problem might not be noticed on the maintainer's system. The fix I've used for my own programs is as follows: #include <unistd.h> long clk_tck; #if defined(_SC_CLK_TCK) || !defined(CLK_TCK) clk_tck = sysconf(_SC_CLK_TCK); #else clk_tck = CLK_TCK; #endif ...then replace all uses of CLK_TCK with clk_tck. This takes into consideration the fact that _SC_CLK_TCK or CLK_TCK might be an enum rather than a cpp macro (although many systems define these in both ways, which is fine). If neither is defined as a cpp macro, _SC_CLK_TCK is preferred.(Continue reading)
RSS Feed