On 10/21/2010 7:40 PM, Stefan Ram wrote:
> [...]
> In C, to skip two space-separated integral numerals
> (under certain circumstances):
>
> while( isnum( *++c )); while( isspace( *++c )); while( isnum( *++c ));
>
> , this is obvious and intelligible. [...]
... and wrong, unless the "certain circumstances" happen to
include foreknowledge that the string is exactly of the given form,
and not, for example, "a23z" (which would cause the third loop to
wander drunkenly past the end of the string, inspecting whatever
random bytes it happened to find in the rest of memory).
Personally, I cannot recall a single occasion in more than forty
years of programming when I (1) wanted to skip over two numbers this
way and (2) wanted to ignore what those numbers were and (3) had such
complete trust that no oddly-formatted strings could ever show up.
(I've had (1) and (2) together, but not along with (3); (3) almost
never holds.) That is, I have never had the slightest urge to write
three such loops, do not expect that I ever will, and do not intend
to let them influence my style. YMMV, but I hope sincerely that it
doesn't V appreciably.
--
Eric Sosman
lid