On 10/15/2011 03:02 PM, Chuck Guzis wrote:
How many new "C" programmers have made the
mistake of thinking that
strlen() returns the total length of a string (including the
delimiter)?
Take the original example in C:
while( *a++=*b++);
Now execute the snippet with two pointers that create an overlapping
move, such that the null terminator of the source string is destroyed
The string move eats its tail, clobbering evertyhing in its path.
That would never happen with descriptor-based strings.
The lesson here isn't that C is bad, but that one shouldn't hire a
"new" (or "old" but incompetent) programmer. People who know what
they're doing simply wouldn't dick around with overlapping copies in the
first place. And if they do it accidentally, they know how to fix it.
That said, also, some strcpy() and memcpy() implementations do deal
with overlapping source/target regions just fine. They're slower,
though...once again spending cycles to compensate for the shortcomings
of programmers who would be better suited to flipping burgers than
writing software.
-Dave
--
Dave McGuire
New Kensington, PA