CBFalconer said:
Mr Gordon seems to be unaware of the fact that this newsgroup deals
_strictly_ with standard C, as defined in the various ISO C
standards, and K&R for pre-standardization versions. Material not
included in those standards is off-topic, unless full std C code to
implement them is included. For system dependent material, go to a
newsgroup that deals with that system.
Dear Mr Falconer,
Let me sum up the sequence on events leading to my losing my temper.
The OP asked about the inner workings of strtok, starting his post with: "As
I know strtok_r is re-entrant version of strtok." and further enquiring
about the difference between the two.
Jacob Navia immediately posted a GNU implementation of strtok_r with
attribution of source, but his explanation of the inner workings was quite
terse.
Ben Pfaff hinted that strtok_r is POSIX specific, along with a slightly more
informative answer.
I, Charlie Gordon, posted a very short explanation, along with my own
implementation of the POSIX function strtok_r, implemented concisely in
terms of Standard library functions.
You, Charles B Falconer, posted a response dismissing strtok_r as
non-standard, along with the source of your own function tknsplit, presented
as a "suitable replacement function". You did not address the OPs question
at all. Your post was largely irrelevant. The OPs question is at least
partly on topic since it discusses an undocumented shortcomming of a
Standard library function.
I then contented that better answers had already been posted, that strtok_r
implementations had been posted, that strtok_r was indeed standardized by a
different body, POSIX. The OPs question was unambiguous and your answer was
not helpful... I also posted comments on your code, as I always do,
pointing at some inconsistencies, semantical differences, potentially
misleading API, and last but not least, a semantical advantage over strtok.
I
Martien Verbruggen insisted that POSIX functions be only discussed on
comp.unix.programmer, but did not set a followup.
I then insisted that discussing strtok's shortcommings and a widely
available solution available in POSIX, with source code already posted
upstream was definitely on topic. I started to lose it, and expressed my
opinion on the Standard's Committee for not fixing known issues in the
library, and forum regulars for not answering simple OP questions.
Then, there was an amazing digression about strdup, thanks to a proud
Fortune 500 coder.
Jacob Navia sided with me on the issue, opening other digressions and the
usual display of collective grief.
Then you responded to my code review, insisted strtok_r could not be
discussed here without source (which had been posted at least twice
already), and finally concluded with a definitive "I have no idea what
strtok_r is, except that it invades user namespace".
I responded to this bold statement in a ironic tone, given that nobody can
believe you never came across Unix in your 50+ years of programming
experience.
Richard Heathfield added to this, confirming the comp.lang.c hard line. Yet
there is a difference between his "there is *no such function* as strtok_r
in Standard C" and your "I have no idea what strtok_r is".
I then lost my temper and called you names. I regret that.
I at least tried to answer the OP who was inquiring about strtok and a
decent alternative. I am quite disappointed that strtok_r was not made part
of C99. I know the proper place for discussing inclusion in the Standard is
comp.std.c, but the proper place to help C programmers is here.
The strtok function specified in the Standard is error prone as it is non
reentrant, causing surprising if not undefined behaviour when used
improperly, even in single threaded programs. I was referring to nested
use, which is incorrect, but not even mentioned in the non-normative
examples or footlines of the Standard.
If advocating people to use a simple documented alternative, with source
code, is not on topic here, where is it ? comp.lang.real.life.c.programming
?
Thanks for your time, and dont use strtok anymore ;-)