"Dimitrie O. Paun" dpaun@rogers.com writes:
If we know for sure that size_t is unsigned (is it always?), than the min() will work just fine.
Oh yes, now I get it! It works because -1 is the largest unsigned integer! Amazing... not too transparent, though.
Otherwise, we can rewrite that line as:
size = n < 0 ? size*2 : n+1;
We should probably should anyway, as it makes it a lot more clearer WTF is going on.
Even I could understand this code... And this also handles the case when the string exactly fits the buffer but the closing zero does not. Great, the original code is actally correct, I am simply too dumb to understand it. :)
Just use libc calls, don't link against msvcrt. Any reason we need to link against msvcrt at all?
This will be a windows application after all... Running on native Windows. We can not use Unixism, or can we? By the way, why does the scanf test work? Because msvcrt is linked before libc? What decides which sscanf will be called?
Feri.