linux-sysprog · beginner · ~15 min

Clamp to a soft limit

Apply a resource ceiling.

Challenge

Implement long clamp_to_limit(long want, long soft_limit) returning want capped at soft_limit (i.e. min of the two).

Starter code

long clamp_to_limit(long want, long soft_limit) {
    /* TODO */
    return want;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.