Use UINT64_C instead of "ULL" number suffix.

Avoid hardcoding a "ULL" number suffix, use the more portable and more
correct UINT64_C.
This commit is contained in:
Uwe Hermann 2018-02-20 19:59:16 +01:00
parent 405b9c10eb
commit d9b716fc5f
4 changed files with 27 additions and 30 deletions

View File

@ -84,11 +84,11 @@ enum sr_error_code {
/* Handy little macros */
#define SR_HZ(n) (n)
#define SR_KHZ(n) ((n) * (uint64_t)(1000ULL))
#define SR_MHZ(n) ((n) * (uint64_t)(1000000ULL))
#define SR_GHZ(n) ((n) * (uint64_t)(1000000000ULL))
#define SR_KHZ(n) ((n) * UINT64_C(1000))
#define SR_MHZ(n) ((n) * UINT64_C(1000000))
#define SR_GHZ(n) ((n) * UINT64_C(1000000000))
#define SR_HZ_TO_NS(n) ((uint64_t)(1000000000ULL) / (n))
#define SR_HZ_TO_NS(n) (UINT64_C(1000000000) / (n))
/** libsigrok loglevels. */
enum sr_loglevel {

View File

@ -738,7 +738,7 @@ static void deinterleave_buffer(const uint8_t *src, size_t length,
const uint16_t m = channel_mask >> channel;
if (!m)
break;
if ((m & 1) && ((*word_ptr++ >> bit) & 1ULL))
if ((m & 1) && ((*word_ptr++ >> bit) & UINT64_C(1)))
sample |= 1 << channel;
}
*dst_ptr++ = sample;

View File

@ -803,11 +803,11 @@ SR_API int sr_parse_period(const char *periodstr, uint64_t *p, uint64_t *q)
while (*s == ' ')
s++;
if (!strcmp(s, "fs"))
*q = 1000000000000000ULL;
*q = UINT64_C(1000000000000000);
else if (!strcmp(s, "ps"))
*q = 1000000000000ULL;
*q = UINT64_C(1000000000000);
else if (!strcmp(s, "ns"))
*q = 1000000000ULL;
*q = UINT64_C(1000000000);
else if (!strcmp(s, "us"))
*q = 1000000;
else if (!strcmp(s, "ms"))

View File

@ -251,19 +251,17 @@ END_TEST
START_TEST(test_ghz)
{
/* Note: Numbers > 2^32 need a ULL suffix. */
test_samplerate(1000000000, "1 GHz");
test_samplerate(5000000000ULL, "5 GHz");
test_samplerate(72000000000ULL, "72 GHz");
test_samplerate(388000000000ULL, "388 GHz");
test_samplerate(4417594444ULL, "4.417594444 GHz");
test_samplerate(44175944444ULL, "44.175944444 GHz");
test_samplerate(441759444441ULL, "441.759444441 GHz");
test_samplerate(441759000001ULL, "441.759000001 GHz");
test_samplerate(441050000000ULL, "441.05 GHz");
test_samplerate(441000000005ULL, "441.000000005 GHz");
test_samplerate(441500000000ULL, "441.5 GHz");
test_samplerate(UINT64_C(1000000000), "1 GHz");
test_samplerate(UINT64_C(5000000000), "5 GHz");
test_samplerate(UINT64_C(72000000000), "72 GHz");
test_samplerate(UINT64_C(388000000000), "388 GHz");
test_samplerate(UINT64_C(4417594444), "4.417594444 GHz");
test_samplerate(UINT64_C(44175944444), "44.175944444 GHz");
test_samplerate(UINT64_C(441759444441), "441.759444441 GHz");
test_samplerate(UINT64_C(441759000001), "441.759000001 GHz");
test_samplerate(UINT64_C(441050000000), "441.05 GHz");
test_samplerate(UINT64_C(441000000005), "441.000000005 GHz");
test_samplerate(UINT64_C(441500000000), "441.5 GHz");
/* Again, but now using SR_GHZ(). */
test_samplerate(SR_GHZ(1), "1 GHz");
@ -279,8 +277,8 @@ START_TEST(test_ghz)
test_samplerate(SR_GHZ(441.500000000), "441.5 GHz");
/* Now check the biggest-possible samplerate (2^64 Hz). */
// test_samplerate(18446744073709551615ULL, "18446744073.709551615 GHz");
// test_samplerate(SR_GHZ(18446744073ULL), "18446744073 GHz");
// test_samplerate(UINT64_C(18446744073709551615), "18446744073.709551615 GHz");
// test_samplerate(SR_GHZ(UINT64_C(18446744073)), "18446744073 GHz");
}
END_TEST
@ -303,13 +301,12 @@ END_TEST
START_TEST(test_ghz_period)
{
/* Note: Numbers > 2^32 need a ULL suffix. */
test_period(1, 1000000000, "1 ns");
test_period(1, 5000000000ULL, "200 ps");
test_period(1, 72000000000ULL, "13.889 ps");
test_period(1, 388000000000ULL, "2.577 ps");
test_period(10, 1000000000000, "10 ps");
test_period(200, 1000000000000ULL, "200 ps");
test_period(1, UINT64_C(1000000000), "1 ns");
test_period(1, UINT64_C(5000000000), "200 ps");
test_period(1, UINT64_C(72000000000), "13.889 ps");
test_period(1, UINT64_C(388000000000), "2.577 ps");
test_period(10, UINT64_C(1000000000000), "10 ps");
test_period(200, UINT64_C(1000000000000), "200 ps");
/* Again, but now using SR_GHZ(). */
test_period(1, SR_GHZ(1), "1 ns");