Skip to main content
Only int*_t and uint*_t are reserved by standard C, but all *_t by POSIX.
Source Link
Toby Speight
  • 81.9k
  • 14
  • 101
  • 309

typedef struct timer_s timer_t collides with a POSIX reserved identifier (all typedef names ending in _t are reserved for future Standard Library use), so probably worth avoiding.

typedef struct timer_s timer_t collides with a reserved identifier (all typedef names ending in _t are reserved for future Standard Library use).

typedef struct timer_s timer_t collides with a POSIX reserved identifier, so probably worth avoiding.

Note the reserved identifier
Source Link
Toby Speight
  • 81.9k
  • 14
  • 101
  • 309

typedef struct timer_s timer_t collides with a reserved identifier (all typedef names ending in _t are reserved for future Standard Library use).


Please don't embed terminal-specific codes like this:

Please don't embed terminal-specific codes like this:

typedef struct timer_s timer_t collides with a reserved identifier (all typedef names ending in _t are reserved for future Standard Library use).


Please don't embed terminal-specific codes like this:

Finish the review
Source Link
Toby Speight
  • 81.9k
  • 14
  • 101
  • 309

Similarly, write -= 1 using --.


We'd like the unit-test program to exit with success status only if all tests succeeded. If any fail, we want to know (e.g. to stop the build at that point). I suggest creating the test function with an int return type to support this, and ending with return tinfo.aborted || tinfo.failed.


The behaviour when CMC_TEST_ABORT() is used is strange. It's the only code that's setting tinfo.aborted, so we could move the if (tinfo.aborted) block directly into that code. OTOH, we shouldn't be printing the elapsed time in that case, as we've skipped the TIMER_STOP(timer); and TIMER_CALC(timer); lines.


Finally, I know it's not really up for review, but I couldn't resist making observations on the gcd() function used for testing:

There's no need for a specific p==0 test - the flow without the test already does the right thing (but the q==0 test is required, as it's used as divisor in the % operation).

We can reduce duplication, by moving p % q into the test:

uintmax_t gcd(uintmax_t p, uintmax_t q)
{
    if (q == 0) {
        return p;
    }

    uintmax_t r;
    while ((r = p % q) != 0) {
        p = q;
        q = r;
    }

    return q;
}

Similarly, write -= 1 using --.


We'd like the unit-test program to exit with success status only if all tests succeeded. If any fail, we want to know (e.g. to stop the build at that point). I suggest creating the test function with an int return type to support this, and ending with return tinfo.aborted || tinfo.failed.


The behaviour when CMC_TEST_ABORT() is used is strange. It's the only code that's setting tinfo.aborted, so we could move the if (tinfo.aborted) block directly into that code. OTOH, we shouldn't be printing the elapsed time in that case, as we've skipped the TIMER_STOP(timer); and TIMER_CALC(timer); lines.


Finally, I know it's not really up for review, but I couldn't resist making observations on the gcd() function used for testing:

There's no need for a specific p==0 test - the flow without the test already does the right thing (but the q==0 test is required, as it's used as divisor in the % operation).

We can reduce duplication, by moving p % q into the test:

uintmax_t gcd(uintmax_t p, uintmax_t q)
{
    if (q == 0) {
        return p;
    }

    uintmax_t r;
    while ((r = p % q) != 0) {
        p = q;
        q = r;
    }

    return q;
}
Source Link
Toby Speight
  • 81.9k
  • 14
  • 101
  • 309
Loading