Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Cookies in boxes - algorithmic challenge Date: Fri, 10 Apr 2026 22:41:08 -0700 Organization: A noiseless patient Spider Lines: 65 Message-ID: <861pgmawaz.fsf@linuxsc.com> References: <20260401163447.000052de@yahoo.com> <86tstlwjak.fsf@linuxsc.com> <20260408222330.00005cf8@yahoo.com> <865x5zbg10.fsf@linuxsc.com> <20260410122314.000063c5@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sat, 11 Apr 2026 05:41:09 +0000 (UTC) Injection-Info: dont-email.me; posting-host="21f9f6d525ecd04de8977c5f6117a238"; logging-data="1694545"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vrONRMwruF6MWEqZISt+OLscjuHomBrI=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:43Y6Uap2YmOjjMDJio5uBri6zfE= sha1:UiPxt2rzmVBkOfcBOsEJVbmTo5w= Xref: csiph.com comp.lang.c:397476 Michael S writes: > Tim Rentsch wrote: >> Michael S writes: >>> Tim Rentsch wrote: [...] >>>> I ran into trouble when I tried to work within the posted framework >>>> to drive a solver. The difficulties were of several kinds. The >>>> code didn't compile in my standard compilation environment, which >>>> is roughly this (the c99 might be c11 but that made no difference): >>>> >>>> gcc -x c -std=c99 -pedantic ... >>> >>> What were the problems? >>> My gcc 14.2.0 on msys2 produces no warnings or errors with above >>> flags. >> >> These source lines >> >> struct timespec t0; >> clock_gettime(CLOCK_MONOTONIC, &t0); >> >> produced these diagnostics >> >> tb.c:134:21: error: storage size of 't0' isn't known >> tb.c:135:5: warning: implicit declaration of function >> 'clock_gettime' [...] tb.c:135:19: error: 'CLOCK_MONOTONIC' >> undeclared (first use in this function) >> >> under -std=c99. Apparently the first diagnostic, about >> struct timespec, is fixed under -std=c11. It wasn't hard >> to fix these, but it was irksome. > > Sounds like under Linux and with -std=c99 flag function clock_gettime() > and related structures and constants are not declared/defined by default > in time.h. Yes, gcc follows the ISO standard exactly, and does not define symbols like clock_gettime, because the C standard does not allow conforming impementations to do so. > Man page suggests magic pixie dust: > > #define _XOPEN_SOURCE 600 > #include > #include It is my practice not to mix ISO-conformant and non-ISO-conformant code in the same translation unit. It wasn't hard to find the necessary tweak for a separate source file used to get the current time: #define _POSIX_C_SOURCE 199309L #include after which both the 'struct timespec' and 'clock_gettime()' were quite okay. I packaged the time in a way so it could get across the function call interface and back to the main program. > If you ask why I used clock_gettime() instead of C standard > timespec_get() then the answer is that on Windows, eps. on older > versions like Win7 and WS2008 (which I prefer over newer stuff for > reasons unrelated to quality of C RTL), precision of timespec_get() is > poor. clock_gettime(CLOCK_MONOTONIC,) is much better. Makes sense.