qsort seems to accept as its last parameter: (1) a function; (2) the
address of a function; and (3) a function pointer. Therefore, why is (3) in
the declaration? Why not declare its last parameter as a regular function
(therefore (2) and (3) become derivative alternatives)?
If a function is declared in one of the above ways the name of a function passed as argument is implicitly converted to a pointer to the function.
So these calls
PS: great C interview question if the candidate wrote the three-way compare function this way: why is it wrong to compare values of type int using subtraction? (or, softer, "propose a unit test for this function")
@Cubbi
PS: great C interview question if the candidate wrote the three-way compare function this way: why is it wrong to compare values of type int using subtraction? (or, softer, "propose a unit test for this function")
I think you mean two-complement arithmetic with integers. Something as
I'm not sure if this is what you were referring to (I'm obviously a
novice), but is your question related to nasty behavior that results from
subtracting unsigned / signed ints? I found this on Stack Overflow:
"Edit: Actually, I could be wrong about the undefined behavior part.
According to C language specification, the common part of the range of the
corresponding signed and unsigned integer type shall have identical
representation (implying, according to the footnote 31, "interchangeability
as arguments to functions"). So, the result of a - b expression is unsigned
1001 as described above, and unless I'm missing something, it is legal to
print this specific unsigned value with %d specifier, since it falls
withing the positive range of int. Printing (unsigned) INT_MAX + 1 with %d
would be undefined, but 1001u is fine."