I was using -1 as a flag value for a function whose return type is size_t (an unsigned type).
I didn't notice it at first, particularly because it wasn't causing any errors in my code (I was checking it with x == -1, not x < 0).
Are there any subtle reasons I shouldn't leave it as is? When might this behave unexpectedly? Is this commonly used?
ptrdiff_t is less common, takes longer to type, and anyway it's not really the appropriate type since the function returns an index into an array.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…