Optimization I'd like to see compilers be able to make: if (strlen(s)>100) -> if (strnlen(s,101)>100)
I don't think size_t is required to be the same size as a pointer. You might not be able to create such a large string yourself on the heap, but that doesn't mean it can't already exist...
-
-
Related issue: What if there is not a single zero byte in memory? What is the expected behavior of strlen(s)>100 in this case? If it has to never return then it isn't equivalent to strnlen(s, 101)>100.
-
strlen is only defined when the parameter points to a zero-terminated string. If there's no zero byte in memory, you don't have a string, and calling strlen invokes undefined behavior.
End of conversation
New conversation -
-
-
they aren't. I think on DOS, a far pointer is 32 bits while size_t is 16. Sure, you can wrangle more than 64KB of consecutive memory together. But C still doesn't have a concept of such a large object, so I think calling the standard library functions on it are going to cause UB.
-
In the large or huge model size_t should be 32-bit.
End of conversation
New conversation -
-
-
size_t is an unsigned integer type for representing the size of an object. The standard is poorly vague about what requirements that imposes, but any interpretation allowing objects whose size it can't represent is a critically broken one.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.