I have a function that looks like this:
int div_round_up(int x, int y) { /** * This function only works for positive divisor and non-negative dividend!! */ assert(y > 0 && x >= 0); if (x == 0) return 0; return (x - 1) / y + 1; } It won't work with y <= 0 or x < 0. That's ok with me, I can even dynamically check for right values, but I would like to check statically, when someone feeds it wrong values. If I defined x and y as unsigned, they would get silently converted from negative values to huge positive values which would produce erroneous result, so I don't want that. I would like to make compilation fail when someone attempts to feed it negative values like in div_round_up(variable, -7). What should I do?
7and-7have the same type, right?_Ret_range_(0, INT_MAX) int div_round_up(_In_range_(0, INT_MAX) int x, _In_range_(1, INT_MAX) int y). msdn.microsoft.com/en-us/library/hh916382.aspx