From aa5b239824b912c818164ad1ab8cca44d802ef58 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 23 Aug 2021 21:58:19 -0500 Subject: [PATCH] Make CLOCKS_PER_SEC and CLK_TCK work in 50Hz video mode. Previously, they were hard-coded as 60, but the clock tick frequency actually depends on the video mode. They now call a new library function that can detect the video mode and return the proper value. This also makes CLOCKS_PER_SEC have the type clock_t, as C99 and later require. --- ORCACDefs/time.h | 5 +++-- cc.notes | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ORCACDefs/time.h b/ORCACDefs/time.h index 88a1c52..3c5c69a 100644 --- a/ORCACDefs/time.h +++ b/ORCACDefs/time.h @@ -28,10 +28,11 @@ struct tm { int tm_isdst; }; +clock_t __clocks_per_sec(void); #ifndef __KeepNamespacePure__ - #define CLK_TCK 60 + #define CLK_TCK (__clocks_per_sec()) #endif -#define CLOCKS_PER_SEC 60 +#define CLOCKS_PER_SEC (__clocks_per_sec()) #ifndef NULL #define NULL (void *) 0L diff --git a/cc.notes b/cc.notes index 4ed80d8..45e9159 100644 --- a/cc.notes +++ b/cc.notes @@ -254,6 +254,10 @@ p. 344 The atexit() function actually returns zero if the function is registered successfully, and a non-zero value if there is not enough memory to satisfy the request (the reverse of what the manual says). +p. 348 + +The discussion of clock() should mention the standard macro CLOCKS_PER_SEC, which gives the number of clock ticks per second. The CLK_TCK macro also gives the same value, but it is non-standard and should be considered deprecated. Also, CLOCKS_PER_SEC and CLK_TCK may be either 50 or 60, depending on the system's video frequency setting; they now expand to code that will detect the setting and give the appropriate value. + p. 353 The discussion of _exit() should note that the _exit() function is an extension to ANSI C. @@ -1198,6 +1202,8 @@ int foo(int[42]); 158. An "illegal type cast" error would be reported when an illegal operator was used in a constant expression. An appropriate error message is now produced. +159. The CLOCKS_PER_SEC and CLK_TCK macros were hard-coded as 60, but they should actually be 50 if the system is in 50Hz video mode. This could throw off timing code that used these macros in conjunction with clock(). The macros now expand to code that will detect the video mode and give the appropriate value. + -- Bugs from C 2.1.0 that have been fixed ----------------------------------- 1. In some situations, fread() reread the first 1K or so of the file.