What is this code doing? (size_t)-1
(size_t)-1
is in fact the equivalent of size_t(-1)
See also the following question c cast syntax styles
This code (unnecessarily) casts -1
to size_t
. The most probable intent was getting the largest possible value of size_t
on this system.
Although this code doesn't have Undefined Behavior, this code is ugly - in C++ you should use std::numeric_limits<size_t>::max()
and in C use SIZE_MAX
macro for exactly a purpose of getting the largest size_t
value.