From: Ondřej Surý Date: Wed, 14 Aug 2024 14:10:18 +0000 (+0200) Subject: Use constexpr for NS_PER_SEC and friends constants X-Git-Tag: v9.21.1~42^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=122a142241ae197816490499e208526eca37361e;p=thirdparty%2Fbind9.git Use constexpr for NS_PER_SEC and friends constants The contexpr introduced in C23 standard makes perfect sense to be used instead of preprocessor macros - the symbols are kept, etc. Define ISC_CONSTEXPR to be `constexpr` for C23 and `static const` for the older C standards. Use the newly introduced macro for the NS_PER_SEC and friends time constants. --- diff --git a/lib/isc/include/isc/attributes.h b/lib/isc/include/isc/attributes.h index eb1bb53e2ed..4ed540f5a8c 100644 --- a/lib/isc/include/isc/attributes.h +++ b/lib/isc/include/isc/attributes.h @@ -102,3 +102,9 @@ #else #define ISC_ATTR_UNUSED __attribute__((__unused__)) #endif + +#if __STDC_VERSION__ >= 202311L +#define ISC_CONSTEXPR constexpr +#else +#define ISC_CONSTEXPR static const +#endif diff --git a/lib/isc/include/isc/time.h b/lib/isc/include/isc/time.h index 3e944352b3b..ad74be92705 100644 --- a/lib/isc/include/isc/time.h +++ b/lib/isc/include/isc/time.h @@ -18,18 +18,19 @@ #include #include +#include #include #include /* * Define various time conversion constants. */ -static const unsigned int MS_PER_SEC = 1000; -static const unsigned int US_PER_MS = 1000; -static const unsigned int NS_PER_US = 1000; -static const unsigned int US_PER_SEC = 1000 * 1000; -static const unsigned int NS_PER_MS = 1000 * 1000; -static const unsigned int NS_PER_SEC = 1000 * 1000 * 1000; +ISC_CONSTEXPR unsigned int MS_PER_SEC = 1000; +ISC_CONSTEXPR unsigned int US_PER_MS = 1000; +ISC_CONSTEXPR unsigned int NS_PER_US = 1000; +ISC_CONSTEXPR unsigned int US_PER_SEC = 1000 * 1000; +ISC_CONSTEXPR unsigned int NS_PER_MS = 1000 * 1000; +ISC_CONSTEXPR unsigned int NS_PER_SEC = 1000 * 1000 * 1000; /* * ISC_FORMATHTTPTIMESTAMP_SIZE needs to be 30 in C locale and potentially