Zack <goldszs...@gmail.comwrote:
The c99 standard states "The implementation shall behave as if
no library function calls the strtok function." What exactly
does this mean?
Exactly that. Because the strtok function has its own record
of the string location being scanned, you can't use it to scan
two strings simultaniously.
So, consider a loop that uses strtok to split a given string.
Now suppose that loop uses printf to print each 'token' as it
goes. If printf has the potential to use strtok internally,
then the user loop potentially crumbles into chaos because
printf will have clobbered or undermined strtok's record.
Does this dictate any requirements to architectures
supporting proccesses or threads?
No, it dictates library implementation requirements and gives
programmers greater freedom to mix strtok with other library
functions (e.g. other string library functions).
[Of course, if strtok were better designed, there wouldn't be
an issue.]
--
Peter