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.
This commit is contained in:
@@ -102,3 +102,9 @@
|
|||||||
#else
|
#else
|
||||||
#define ISC_ATTR_UNUSED __attribute__((__unused__))
|
#define ISC_ATTR_UNUSED __attribute__((__unused__))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __STDC_VERSION__ >= 202311L
|
||||||
|
#define ISC_CONSTEXPR constexpr
|
||||||
|
#else
|
||||||
|
#define ISC_CONSTEXPR static const
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -18,18 +18,19 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <isc/attributes.h>
|
||||||
#include <isc/lang.h>
|
#include <isc/lang.h>
|
||||||
#include <isc/types.h>
|
#include <isc/types.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define various time conversion constants.
|
* Define various time conversion constants.
|
||||||
*/
|
*/
|
||||||
static const unsigned int MS_PER_SEC = 1000;
|
ISC_CONSTEXPR unsigned int MS_PER_SEC = 1000;
|
||||||
static const unsigned int US_PER_MS = 1000;
|
ISC_CONSTEXPR unsigned int US_PER_MS = 1000;
|
||||||
static const unsigned int NS_PER_US = 1000;
|
ISC_CONSTEXPR unsigned int NS_PER_US = 1000;
|
||||||
static const unsigned int US_PER_SEC = 1000 * 1000;
|
ISC_CONSTEXPR unsigned int US_PER_SEC = 1000 * 1000;
|
||||||
static const unsigned int NS_PER_MS = 1000 * 1000;
|
ISC_CONSTEXPR unsigned int NS_PER_MS = 1000 * 1000;
|
||||||
static const unsigned int NS_PER_SEC = 1000 * 1000 * 1000;
|
ISC_CONSTEXPR unsigned int NS_PER_SEC = 1000 * 1000 * 1000;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ISC_FORMATHTTPTIMESTAMP_SIZE needs to be 30 in C locale and potentially
|
* ISC_FORMATHTTPTIMESTAMP_SIZE needs to be 30 in C locale and potentially
|
||||||
|
|||||||
Reference in New Issue
Block a user