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.
This commit is contained in:
Stephen Heumann 2021-08-23 21:58:19 -05:00
parent 2b9d332580
commit aa5b239824
2 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -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.