[PROPOSED 1/2] Simplify function parameter decl style
* localtime.c (time2sub, time2, time1): Use simpler style for declaring function parameters. Although this style has worked since C89, I didn’t know about it until reading Jens Gustedt’s book Modern C. Switching to this style now can simplify future future changes that also use a functional programming style. --- localtime.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/localtime.c b/localtime.c index 63b8ea0a..24972b20 100644 --- a/localtime.c +++ b/localtime.c @@ -2442,8 +2442,8 @@ mktmcpy(struct tm *dest, struct tm const *src) static time_t time2sub(struct tm *const tmp, - struct tm *(*funcp)(struct state const *, time_t const *, - int_fast32_t, struct tm *), + struct tm *funcp(struct state const *, time_t const *, + int_fast32_t, struct tm *), struct state const *sp, const int_fast32_t offset, bool *okayp, @@ -2661,8 +2661,8 @@ label: static time_t time2(struct tm * const tmp, - struct tm *(*funcp)(struct state const *, time_t const *, - int_fast32_t, struct tm *), + struct tm *funcp(struct state const *, time_t const *, + int_fast32_t, struct tm *), struct state const *sp, const int_fast32_t offset, bool *okayp) @@ -2680,8 +2680,8 @@ time2(struct tm * const tmp, static time_t time1(struct tm *const tmp, - struct tm *(*funcp)(struct state const *, time_t const *, - int_fast32_t, struct tm *), + struct tm *funcp(struct state const *, time_t const *, + int_fast32_t, struct tm *), struct state const *sp, const int_fast32_t offset) { -- 2.48.1
* localtime.c (tzloadbody): Move recently-added static_assert to the top level. This pacifies some pre-C23 compilers, so that they do not warn about nested extern declarations. * private.h (static_assert): Comment about this. Also, do not define if already defined; this can happen if a wrapper source file includes <assert.h> before us in C11. --- localtime.c | 4 +++- private.h | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/localtime.c b/localtime.c index 24972b20..a78962a6 100644 --- a/localtime.c +++ b/localtime.c @@ -756,6 +756,9 @@ ATTRIBUTE_NONSTRING #endif static char const tzdirslash[sizeof TZDIR + OPENAT_TZDIR] = TZDIR "/"; enum { tzdirslashlen = sizeof TZDIR }; +#ifdef PATH_MAX +static_assert(tzdirslashlen <= PATH_MAX); /* Sanity check; assumed below. */ +#endif /* Local storage needed for 'tzloadbody'. */ union local_storage { @@ -866,7 +869,6 @@ tzloadbody(char const *name, struct state *sp, char tzloadflags, char *cp; size_t fullnamesize; #ifdef PATH_MAX - static_assert(tzdirslashlen <= PATH_MAX); size_t namesizemax = PATH_MAX - tzdirslashlen; size_t namelen = strnlen (name, namesizemax); if (namesizemax <= namelen) diff --git a/private.h b/private.h index befa6db1..2008660d 100644 --- a/private.h +++ b/private.h @@ -82,8 +82,9 @@ # include <stdbool.h> #endif -#if __STDC_VERSION__ < 202311 -# undef static_assert +/* For pre-C23 compilers, a substitute for static_assert. + Some of these compilers may warn if it is not used at the top level. */ +#if __STDC_VERSION__ < 202311 && !defined static_assert # define static_assert(cond) extern int static_assert_check[(cond) ? 1 : -1] #endif -- 2.48.1
participants (1)
-
Paul Eggert