diff --git a/stl/src/filesys.cpp b/stl/src/filesys.cpp index ac16cf6f794..1e74200637d 100644 --- a/stl/src/filesys.cpp +++ b/stl/src/filesys.cpp @@ -267,9 +267,10 @@ _FS_DLL unsigned long long __CLRCALL_PURE_OR_CDECL _File_size(const wchar_t* _Fn // 1908 is leap year #2 // 1968 is leap year #17 -#define WIN_TICKS_PER_SECOND 10000000ULL -#define WIN_TICKS_FROM_EPOCH (((1970 - 1601) * 365 + 3 * 24 + 17) * 86400ULL * WIN_TICKS_PER_SECOND) +constexpr uint64_t _Win_ticks_per_second = 10000000ULL; +constexpr uint64_t _Win_ticks_from_epoch = ((1970 - 1601) * 365 + 3 * 24 + 17) * 86400ULL * _Win_ticks_per_second; + _FS_DLL int64_t __CLRCALL_PURE_OR_CDECL _Last_write_time(const wchar_t* _Fname) { // get last write time WIN32_FILE_ATTRIBUTE_DATA _Data; @@ -281,7 +282,7 @@ _FS_DLL int64_t __CLRCALL_PURE_OR_CDECL _Last_write_time(const wchar_t* _Fname) // success, convert time unsigned long long _Wtime = static_cast(_Data.ftLastWriteTime.dwHighDateTime) << 32 | _Data.ftLastWriteTime.dwLowDateTime; - return static_cast(_Wtime - WIN_TICKS_FROM_EPOCH); + return static_cast(_Wtime - _Win_ticks_from_epoch); } @@ -294,7 +295,7 @@ _FS_DLL int __CLRCALL_PURE_OR_CDECL _Set_last_write_time(const wchar_t* _Fname, } // convert to FILETIME and set - unsigned long long _Wtime = static_cast(_When) + WIN_TICKS_FROM_EPOCH; + unsigned long long _Wtime = static_cast(_When) + _Win_ticks_from_epoch; FILETIME _Ft; _Ft.dwLowDateTime = static_cast(_Wtime); // intentionally discard upper bits _Ft.dwHighDateTime = static_cast(_Wtime >> 32); diff --git a/stl/src/ios.cpp b/stl/src/ios.cpp index 4f0be30a97d..91ee2363d34 100644 --- a/stl/src/ios.cpp +++ b/stl/src/ios.cpp @@ -7,7 +7,7 @@ #include _STD_BEGIN -#define NSTDSTR 8 // cin, wcin, cout, wcout, cerr, wcerr, clog, wclog +constexpr int _Nstdstr = 8; // cin, wcin, cout, wcout, cerr, wcerr, clog, wclog // TRANSITION, ABI: _BADOFF is preserved for binary compatibility #if defined(_M_CEE_PURE) @@ -22,8 +22,8 @@ __PURE_APPDOMAIN_GLOBAL int ios_base::_Index = 0; // initialize source of unique __PURE_APPDOMAIN_GLOBAL bool ios_base::_Sync = true; // initialize synchronization flag -__PURE_APPDOMAIN_GLOBAL static ios_base* stdstr[NSTDSTR + 2] = {0}; // [1, NSTDSTR] hold pointers to standard streams -__PURE_APPDOMAIN_GLOBAL static char stdopens[NSTDSTR + 2] = {0}; // [1, NSTDSTR] hold open counts for standard streams +__PURE_APPDOMAIN_GLOBAL static ios_base* stdstr[_Nstdstr + 2] = {0}; // [1, _Nstdstr] hold pointers to standard streams +__PURE_APPDOMAIN_GLOBAL static char stdopens[_Nstdstr + 2] = {0}; // [1, _Nstdstr] hold open counts for standard streams // void __CLR_OR_THIS_CALL ios_base::clear(iostate state, bool reraise) { // set state, possibly reraise exception // _Mystate = (iostate)(state & _Statmask); @@ -74,7 +74,7 @@ void __CLRCALL_PURE_OR_CDECL ios_base::_Ios_base_dtor(ios_base* _This) { // dest void __CLRCALL_PURE_OR_CDECL ios_base::_Addstd(ios_base* _This) { // add standard stream to destructor list _BEGIN_LOCK(_LOCK_STREAM) - for (_This->_Stdstr = 0; ++_This->_Stdstr < NSTDSTR;) { + for (_This->_Stdstr = 0; ++_This->_Stdstr < _Nstdstr;) { if (stdstr[_This->_Stdstr] == 0 || stdstr[_This->_Stdstr] == _This) { break; // found a candidate } diff --git a/stl/src/iosptrs.cpp b/stl/src/iosptrs.cpp index 4f7626d8f68..1390583e078 100644 --- a/stl/src/iosptrs.cpp +++ b/stl/src/iosptrs.cpp @@ -30,11 +30,11 @@ __PURE_APPDOMAIN_GLOBAL extern _CRTDATA2_IMPORT wostream* _Ptr_wclog = 0; _STD_END // FINALIZATION CODE -#define NATS 10 // fclose, xgetloc, locks, facet free, etc. +constexpr int _Nats = 10; // fclose, xgetloc, locks, facet free, etc. // static data -__PURE_APPDOMAIN_GLOBAL static void(__cdecl* atfuns_cdecl[NATS])() = {0}; -__PURE_APPDOMAIN_GLOBAL static size_t atcount_cdecl = {NATS}; +__PURE_APPDOMAIN_GLOBAL static void(__cdecl* atfuns_cdecl[_Nats])() = {0}; +__PURE_APPDOMAIN_GLOBAL static size_t atcount_cdecl = {_Nats}; _MRTIMP2 void __cdecl _Atexit(void(__cdecl* pf)()) { // add to wrapup list if (atcount_cdecl == 0) { abort(); // stack full, give up @@ -45,7 +45,7 @@ _MRTIMP2 void __cdecl _Atexit(void(__cdecl* pf)()) { // add to wrapup list struct _Init_atexit { // controller for atexit processing __CLR_OR_THIS_CALL ~_Init_atexit() noexcept { // process wrapup functions - while (atcount_cdecl < NATS) { + while (atcount_cdecl < _Nats) { void(__cdecl * pf)() = (void(__cdecl*)()) DecodePointer(atfuns_cdecl[atcount_cdecl++]); if (pf) { (*pf)(); diff --git a/stl/src/xlock.cpp b/stl/src/xlock.cpp index 80eafb295b1..bbd37779368 100644 --- a/stl/src/xlock.cpp +++ b/stl/src/xlock.cpp @@ -11,12 +11,12 @@ _STD_BEGIN -#define MAX_LOCK 8 // must be power of two +constexpr int _Max_lock = 8; // must be power of two #pragma warning(disable : 4074) #pragma init_seg(compiler) -static _Rmtx mtx[MAX_LOCK]; +static _Rmtx mtx[_Max_lock]; static long init = -1; #if !defined(MRTDLL) @@ -70,7 +70,7 @@ __thiscall _Lockit::_Lockit() noexcept : _Locktype(0) { // lock default mutex __thiscall _Lockit::_Lockit(int kind) noexcept : _Locktype(kind) { // lock the mutex if (_Locktype == _LOCK_LOCALE) { _lock_locales(); - } else if (_Locktype < MAX_LOCK) { + } else if (_Locktype < _Max_lock) { _Mtxlock(&mtx[_Locktype]); } } @@ -78,7 +78,7 @@ __thiscall _Lockit::_Lockit(int kind) noexcept : _Locktype(kind) { // lock the m __thiscall _Lockit::~_Lockit() noexcept { // unlock the mutex if (_Locktype == _LOCK_LOCALE) { _unlock_locales(); - } else if (_Locktype < MAX_LOCK) { + } else if (_Locktype < _Max_lock) { _Mtxunlock(&mtx[_Locktype]); } } @@ -93,7 +93,7 @@ void __cdecl _Lockit::_Lockit_ctor(_Lockit* _This, int kind) noexcept { // lock if (kind == _LOCK_LOCALE) { _lock_locales(); } else { - _This->_Locktype = kind & (MAX_LOCK - 1); + _This->_Locktype = kind & (_Max_lock - 1); _Mtxlock(&mtx[_This->_Locktype]); } } @@ -107,7 +107,7 @@ void __cdecl _Lockit::_Lockit_ctor(int kind) noexcept { // lock the mutex if (kind == _LOCK_LOCALE) { _lock_locales(); } else { - _Mtxlock(&mtx[kind & (MAX_LOCK - 1)]); + _Mtxlock(&mtx[kind & (_Max_lock - 1)]); } } @@ -116,16 +116,17 @@ void __cdecl _Lockit::_Lockit_dtor(int kind) noexcept { // unlock the mutex if (kind == _LOCK_LOCALE) { _unlock_locales(); } else { - _Mtxunlock(&mtx[kind & (MAX_LOCK - 1)]); + _Mtxunlock(&mtx[kind & (_Max_lock - 1)]); } } -extern "C" void _Lock_at_thread_exit_mutex() { // lock the at-thread-exit mutex +_EXTERN_C +void _Lock_at_thread_exit_mutex() { // lock the at-thread-exit mutex _Mtxlock(&mtx[_LOCK_AT_THREAD_EXIT]); } - -extern "C" void _Unlock_at_thread_exit_mutex() { // unlock the at-thread-exit mutex +void _Unlock_at_thread_exit_mutex() { // unlock the at-thread-exit mutex _Mtxunlock(&mtx[_LOCK_AT_THREAD_EXIT]); } +_END_EXTERN_C _STD_END diff --git a/stl/src/xnotify.cpp b/stl/src/xnotify.cpp index 1a4b0fb9e9e..c3e87255399 100644 --- a/stl/src/xnotify.cpp +++ b/stl/src/xnotify.cpp @@ -9,7 +9,7 @@ #include -#define NITEMS 20 +constexpr int _Nitems = 20; namespace { struct _At_thread_exit_data { // data for condition-variable slot @@ -20,7 +20,7 @@ namespace { }; struct _At_thread_exit_block { // block of condition-variable slots - _At_thread_exit_data data[NITEMS]; + _At_thread_exit_data data[_Nitems]; int num_used; _At_thread_exit_block* next; }; @@ -40,14 +40,14 @@ void _Cnd_register_at_thread_exit( _Lock_at_thread_exit_mutex(); while (block != 0) { // loop through list of blocks - if (block->num_used == NITEMS) { // block is full; move to next block and allocate + if (block->num_used == _Nitems) { // block is full; move to next block and allocate if (block->next == 0) { block->next = (_At_thread_exit_block*) calloc(1, sizeof(_At_thread_exit_block)); } block = block->next; } else { // found block with available space - for (int i = 0; i < NITEMS; ++i) { // find empty slot + for (int i = 0; i < _Nitems; ++i) { // find empty slot if (block->data[i].mtx == 0) { // store into empty slot block->data[i].id._Id = GetCurrentThreadId(); block->data[i].mtx = mtx; @@ -69,7 +69,7 @@ void _Cnd_unregister_at_thread_exit(_Mtx_t mtx) { // unregister condition variab _Lock_at_thread_exit_mutex(); while (block != 0) { // loop through list of blocks - for (int i = 0; block->num_used != 0 && i < NITEMS; ++i) { + for (int i = 0; block->num_used != 0 && i < _Nitems; ++i) { if (block->data[i].mtx == mtx) { // release slot block->data[i].mtx = 0; --block->num_used; @@ -88,7 +88,7 @@ void _Cnd_do_broadcast_at_thread_exit() { // notify condition variables waiting _Lock_at_thread_exit_mutex(); while (block != 0) { // loop through list of blocks - for (int i = 0; block->num_used != 0 && i < NITEMS; ++i) { + for (int i = 0; block->num_used != 0 && i < _Nitems; ++i) { if (block->data[i].mtx != 0 && block->data[i].id._Id == currentThreadId) { // notify and release slot if (block->data[i].res) { *block->data[i].res = 1; diff --git a/stl/src/xstoflt.cpp b/stl/src/xstoflt.cpp index 16199533a2f..9ef65dfe932 100644 --- a/stl/src/xstoflt.cpp +++ b/stl/src/xstoflt.cpp @@ -10,25 +10,25 @@ _EXTERN_C_UNLESS_PURE -#define BASE 10 // decimal -#define NDIG 9 // decimal digits per long word -#define MAXSIG (5 * NDIG) // maximum significant digits to keep +constexpr int _Base = 10; // decimal +constexpr int _Ndig = 9; // decimal digits per long word +constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep int _Stoflt(const char* s0, const char* s, char** endptr, long lo[], int maxsig) { // convert string to array of long plus exponent - char buf[MAXSIG + 1]; // worst case, with room for rounding digit + char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen int sticky = 0; // note any nonzero digits discarded int word = 0; // just before current long word to fill - maxsig *= NDIG; // convert word count to digit count - if (MAXSIG < maxsig) { - maxsig = MAXSIG; // protect against bad call + maxsig *= _Ndig; // convert word count to digit count + if (_Maxsig < maxsig) { + maxsig = _Maxsig; // protect against bad call } lo[0] = 0; // power of ten exponent - lo[1] = 0; // first NDIG-digit word of fraction + lo[1] = 0; // first _Ndig-digit word of fraction while (*s == '0') { // strip leading zeros seen = 1; @@ -69,7 +69,7 @@ int _Stoflt(const char* s0, const char* s, char** endptr, long lo[], } if (sticky) { - buf[maxsig - 1] += 1; // okay if digit becomes BASE + buf[maxsig - 1] += 1; // okay if digit becomes _Base } for (; 0 < nsig && buf[nsig - 1] == '\0'; --nsig) { @@ -82,14 +82,14 @@ int _Stoflt(const char* s0, const char* s, char** endptr, long lo[], if (seen) { // convert digit sequence to words int bufidx = 0; // next digit in buffer - int wordidx = NDIG - nsig % NDIG; // next digit in word (% NDIG) + int wordidx = _Ndig - nsig % _Ndig; // next digit in word (% _Ndig) - word = wordidx % NDIG == 0 ? 0 : 1; + word = wordidx % _Ndig == 0 ? 0 : 1; for (; bufidx < nsig; ++wordidx, ++bufidx) { - if (wordidx % NDIG == 0) { + if (wordidx % _Ndig == 0) { lo[++word] = buf[bufidx]; } else { - lo[word] = lo[word] * BASE + buf[bufidx]; + lo[word] = lo[word] * _Base + buf[bufidx]; } } diff --git a/stl/src/xstoul.cpp b/stl/src/xstoul.cpp index df57338efb7..d43dbc91dbe 100644 --- a/stl/src/xstoul.cpp +++ b/stl/src/xstoul.cpp @@ -14,7 +14,7 @@ _EXTERN_C_UNLESS_PURE // macros -#define BASE_MAX 36 // largest valid base +constexpr int _Base_max = 36; // largest valid base // static data static const char digits[] = // valid digits @@ -22,11 +22,11 @@ static const char digits[] = // valid digits #if (ULONG_MAX >> 16) >> 16 == 0xffffffff // 64-bits! -static const char ndigs[BASE_MAX + 1] = {0, 0, 65, 41, 33, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 17, 16, 16, 16, +static const char ndigs[_Base_max + 1] = {0, 0, 65, 41, 33, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 17, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13}; #else // (ULONG_MAX >> 16) >> 16 == 0xffffffff // 32-bits! -static const char ndigs[BASE_MAX + 1] = {0, 0, 33, 21, 17, 14, 13, 12, 11, 11, 10, 10, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, +static const char ndigs[_Base_max + 1] = {0, 0, 33, 21, 17, 14, 13, 12, 11, 11, 10, 10, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}; #endif // (ULONG_MAX >> 16) >> 16 == 0xffffffff @@ -49,7 +49,7 @@ _CRTIMP2_PURE unsigned long __CLRCALL_PURE_OR_CDECL _Stoulx( } sign = *sc == '-' || *sc == '+' ? *sc++ : '+'; - if (base < 0 || base == 1 || BASE_MAX < base) { // silly base + if (base < 0 || base == 1 || _Base_max < base) { // silly base if (endptr != 0) { *endptr = (char*) s; } diff --git a/stl/src/xstoull.cpp b/stl/src/xstoull.cpp index d236cc8c030..1c5ceb13fb7 100644 --- a/stl/src/xstoull.cpp +++ b/stl/src/xstoull.cpp @@ -13,14 +13,13 @@ _EXTERN_C_UNLESS_PURE -// macros -#define BASE_MAX 36 // largest valid base +constexpr int _Base_max = 36; // largest valid base // static data static const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; // valid digits // 64-bits! -static const char ndigs[BASE_MAX + 1] = {0, 0, 65, 41, 33, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 17, 16, 16, 16, +static const char ndigs[_Base_max + 1] = {0, 0, 65, 41, 33, 28, 25, 23, 22, 21, 20, 19, 18, 18, 17, 17, 17, 16, 16, 16, 15, 15, 15, 15, 14, 14, 14, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13}; _CRTIMP2_PURE unsigned long long __CLRCALL_PURE_OR_CDECL _Stoullx( @@ -41,7 +40,7 @@ _CRTIMP2_PURE unsigned long long __CLRCALL_PURE_OR_CDECL _Stoullx( } sign = (char) (*sc == '-' || *sc == '+' ? *sc++ : '+'); - if (base < 0 || base == 1 || BASE_MAX < base) { // silly base + if (base < 0 || base == 1 || _Base_max < base) { // silly base if (endptr != 0) { *endptr = (char*) s; } diff --git a/stl/src/xstoxflt.cpp b/stl/src/xstoxflt.cpp index db63479d596..f679521d601 100644 --- a/stl/src/xstoxflt.cpp +++ b/stl/src/xstoxflt.cpp @@ -11,13 +11,13 @@ _EXTERN_C_UNLESS_PURE -#define BASE 16 // hexadecimal -#define NDIG 7 // hexadecimal digits per long element -#define MAXSIG (5 * NDIG) // maximum significant digits to keep +constexpr int _Base = 16; // hexadecimal +constexpr int _Ndig = 7; // hexadecimal digits per long element +constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep int _Stoxflt(const char* s0, const char* s, char** endptr, long lo[], int maxsig) { // convert string to array of long plus exponent - char buf[MAXSIG + 1]; // worst case, with room for rounding digit + char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen int word = 0; // current long word to fill @@ -27,13 +27,13 @@ int _Stoxflt(const char* s0, const char* s, char** endptr, long lo[], static const char vals[] = {// values of hex digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}; - maxsig *= NDIG; // convert word count to digit count - if (MAXSIG < maxsig) { - maxsig = MAXSIG; // protect against bad call + maxsig *= _Ndig; // convert word count to digit count + if (_Maxsig < maxsig) { + maxsig = _Maxsig; // protect against bad call } lo[0] = 0; // power of ten exponent - lo[1] = 0; // first NDIG-digit word of fraction + lo[1] = 0; // first _Ndig-digit word of fraction while (*s == '0') { // strip leading zeros ++s; @@ -69,8 +69,8 @@ int _Stoxflt(const char* s0, const char* s, char** endptr, long lo[], } if (maxsig < nsig) { // discard excess digit after rounding up - if (BASE / 2 <= buf[maxsig]) { - ++buf[maxsig - 1]; // okay if digit becomes BASE + if (_Base / 2 <= buf[maxsig]) { + ++buf[maxsig - 1]; // okay if digit becomes _Base } nsig = maxsig; @@ -88,14 +88,14 @@ int _Stoxflt(const char* s0, const char* s, char** endptr, long lo[], lo[0] <<= 2; // change hex exponent to binary exponent if (seen) { // convert digit sequence to words int bufidx = 0; // next digit in buffer - int wordidx = NDIG - nsig % NDIG; // next digit in word (% NDIG) + int wordidx = _Ndig - nsig % _Ndig; // next digit in word (% _Ndig) - word = wordidx % NDIG == 0 ? 0 : 1; + word = wordidx % _Ndig == 0 ? 0 : 1; for (; bufidx < nsig; ++wordidx, ++bufidx) { - if (wordidx % NDIG == 0) { + if (wordidx % _Ndig == 0) { lo[++word] = buf[bufidx]; } else { - lo[word] = lo[word] * BASE + buf[bufidx]; + lo[word] = lo[word] * _Base + buf[bufidx]; } } diff --git a/stl/src/xtime.cpp b/stl/src/xtime.cpp index ecc3ffd9569..f39d35031e0 100644 --- a/stl/src/xtime.cpp +++ b/stl/src/xtime.cpp @@ -8,19 +8,18 @@ #include #include -#define NSEC_PER_SEC 1000000000L -#define NSEC_PER_MSEC 1000000L -#define NSEC_PER_USEC 1000L -#define MSEC_PER_SEC 1000 +constexpr long _Nsec_per_sec = 1000000000L; +constexpr long _Nsec_per_msec = 1000000L; +constexpr int _Msec_per_sec = 1000; static void xtime_normalize(xtime* xt) { // adjust so that 0 <= nsec < 1 000 000 000 while (xt->nsec < 0) { // normalize target time xt->sec -= 1; - xt->nsec += NSEC_PER_SEC; + xt->nsec += _Nsec_per_sec; } - while (NSEC_PER_SEC <= xt->nsec) { // normalize target time + while (_Nsec_per_sec <= xt->nsec) { // normalize target time xt->sec += 1; - xt->nsec -= NSEC_PER_SEC; + xt->nsec -= _Nsec_per_sec; } } @@ -30,7 +29,7 @@ static xtime xtime_diff(const xtime* xt, xtime_normalize(&diff); if (diff.nsec < now->nsec) { // avoid underflow diff.sec -= now->sec + 1; - diff.nsec += NSEC_PER_SEC - now->nsec; + diff.nsec += _Nsec_per_sec - now->nsec; } else { // no underflow diff.sec -= now->sec; diff.nsec -= now->nsec; @@ -43,28 +42,26 @@ static xtime xtime_diff(const xtime* xt, } -#define EPOCH 0x19DB1DED53E8000i64 - -#define NSEC100_PER_SEC (NSEC_PER_SEC / 100) -#define NSEC100_PER_MSEC (NSEC_PER_MSEC / 100) +constexpr long long _Epoch = 0x19DB1DED53E8000LL; +constexpr long _Nsec100_per_sec = _Nsec_per_sec / 100; _EXTERN_C long long _Xtime_get_ticks() { // get system time in 100-nanosecond intervals since the epoch FILETIME ft; __crtGetSystemTimePreciseAsFileTime(&ft); - return ((static_cast(ft.dwHighDateTime)) << 32) + static_cast(ft.dwLowDateTime) - EPOCH; + return ((static_cast(ft.dwHighDateTime)) << 32) + static_cast(ft.dwLowDateTime) - _Epoch; } static void sys_get_time(xtime* xt) { // get system time with nanosecond resolution unsigned long long now = _Xtime_get_ticks(); - xt->sec = static_cast<__time64_t>(now / NSEC100_PER_SEC); - xt->nsec = static_cast(now % NSEC100_PER_SEC) * 100; + xt->sec = static_cast<__time64_t>(now / _Nsec100_per_sec); + xt->nsec = static_cast(now % _Nsec100_per_sec) * 100; } long _Xtime_diff_to_millis2(const xtime* xt1, const xtime* xt2) { // convert time to milliseconds xtime diff = xtime_diff(xt1, xt2); - return static_cast(diff.sec * MSEC_PER_SEC + (diff.nsec + NSEC_PER_MSEC - 1) / NSEC_PER_MSEC); + return static_cast(diff.sec * _Msec_per_sec + (diff.nsec + _Nsec_per_msec - 1) / _Nsec_per_msec); } long _Xtime_diff_to_millis(const xtime* xt) { // convert time to milliseconds diff --git a/stl/src/xwstoflt.cpp b/stl/src/xwstoflt.cpp index 3cbfce6c705..983723c4c4a 100644 --- a/stl/src/xwstoflt.cpp +++ b/stl/src/xwstoflt.cpp @@ -10,24 +10,24 @@ _EXTERN_C_UNLESS_PURE -#define BASE 10 // decimal -#define NDIG 9 // decimal digits per long element -#define MAXSIG (5 * NDIG) // maximum significant digits to keep +constexpr int _Base = 10; // decimal +constexpr int _Ndig = 9; // decimal digits per long element +constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep int _WStoflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, long lo[], int maxsig) { // convert wide string to array of long plus exponent - char buf[MAXSIG + 1]; // worst case, with room for rounding digit + char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen int word = 0; // current long word to fill - maxsig *= NDIG; // convert word count to digit count - if (MAXSIG < maxsig) { - maxsig = MAXSIG; // protect against bad call + maxsig *= _Ndig; // convert word count to digit count + if (_Maxsig < maxsig) { + maxsig = _Maxsig; // protect against bad call } lo[0] = 0; // power of ten exponent - lo[1] = 0; // first NDIG-digit word of fraction + lo[1] = 0; // first _Ndig-digit word of fraction while (*s == L'0') { // strip leading zeros ++s; @@ -68,8 +68,8 @@ int _WStoflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, long lo[], } if (maxsig < nsig) { // discard excess digit after rounding up - if (BASE / 2 <= buf[maxsig]) { - ++buf[maxsig - 1]; // okay if digit becomes BASE + if (_Base / 2 <= buf[maxsig]) { + ++buf[maxsig - 1]; // okay if digit becomes _Base } nsig = maxsig; @@ -86,14 +86,14 @@ int _WStoflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, long lo[], if (seen) { // convert digit sequence to words int bufidx = 0; // next digit in buffer - int wordidx = NDIG - nsig % NDIG; // next digit in word (% NDIG) + int wordidx = _Ndig - nsig % _Ndig; // next digit in word (% _Ndig) - word = wordidx % NDIG == 0 ? 0 : 1; + word = wordidx % _Ndig == 0 ? 0 : 1; for (; bufidx < nsig; ++wordidx, ++bufidx) { - if (wordidx % NDIG == 0) { + if (wordidx % _Ndig == 0) { lo[++word] = buf[bufidx]; } else { - lo[word] = lo[word] * BASE + buf[bufidx]; + lo[word] = lo[word] * _Base + buf[bufidx]; } } diff --git a/stl/src/xwstoxfl.cpp b/stl/src/xwstoxfl.cpp index ab17bfab5b1..4b5aceb4480 100644 --- a/stl/src/xwstoxfl.cpp +++ b/stl/src/xwstoxfl.cpp @@ -11,13 +11,13 @@ _EXTERN_C_UNLESS_PURE -#define BASE 16 // hexadecimal -#define NDIG 7 // hexadecimal digits per long element -#define MAXSIG (5 * NDIG) // maximum significant digits to keep +constexpr int _Base = 16; // hexadecimal +constexpr int _Ndig = 7; // hexadecimal digits per long element +constexpr int _Maxsig = 5 * _Ndig; // maximum significant digits to keep int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, long lo[], int maxsig) { // convert wide string to array of long plus exponent - char buf[MAXSIG + 1]; // worst case, with room for rounding digit + char buf[_Maxsig + 1]; // worst case, with room for rounding digit int nsig = 0; // number of significant digits seen int seen = 0; // any valid field characters seen int word = 0; // current long word to fill @@ -29,13 +29,13 @@ int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, long lo[], static const char vals[] = {// values of hex digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15}; - maxsig *= NDIG; // convert word count to digit count - if (MAXSIG < maxsig) { - maxsig = MAXSIG; // protect against bad call + maxsig *= _Ndig; // convert word count to digit count + if (_Maxsig < maxsig) { + maxsig = _Maxsig; // protect against bad call } lo[0] = 0; // power of ten exponent - lo[1] = 0; // first NDIG-digit word of fraction + lo[1] = 0; // first _Ndig-digit word of fraction while (*s == L'0') { // strip leading zeros ++s; @@ -74,8 +74,8 @@ int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, long lo[], } if (maxsig < nsig) { // discard excess digit after rounding up - if (BASE / 2 <= buf[maxsig]) { - ++buf[maxsig - 1]; // okay if digit becomes BASE + if (_Base / 2 <= buf[maxsig]) { + ++buf[maxsig - 1]; // okay if digit becomes _Base } nsig = maxsig; @@ -93,14 +93,14 @@ int _WStoxflt(const wchar_t* s0, const wchar_t* s, wchar_t** endptr, long lo[], lo[0] <<= 2; // change hex exponent to binary exponent if (seen) { // convert digit sequence to words int bufidx = 0; // next digit in buffer - int wordidx = NDIG - nsig % NDIG; // next digit in word (% NDIG) + int wordidx = _Ndig - nsig % _Ndig; // next digit in word (% _Ndig) - word = wordidx % NDIG == 0 ? 0 : 1; + word = wordidx % _Ndig == 0 ? 0 : 1; for (; bufidx < nsig; ++wordidx, ++bufidx) { - if (wordidx % NDIG == 0) { + if (wordidx % _Ndig == 0) { lo[++word] = buf[bufidx]; } else { - lo[word] = lo[word] * BASE + buf[bufidx]; + lo[word] = lo[word] * _Base + buf[bufidx]; } }