Sujet : Re: Buffer contents well-defined after fgets() reaches EOF ?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 16. Feb 2025, 18:59:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vot923$mrt1$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 16.02.2025 07:04, James Kuyper wrote:
On 2/15/25 22:29, Janis Papanagnou wrote:
But since I don't use threads - neither here nor did I ever needed
them generally in my "C" contexts - that's unnecessary. Isn't it?
No. What makes strtok() problematic can come up without any use of
threads. Consider for the moment a bug I had to investigate. A function
that was looping through strtok() calls to parse a string called a
utility function during each pass through the loop. The utility function
also called strtok() in a loop to parse an entirely different string for
a different purpose. [...]
You can construct any situations that don't apply to my application.
All relevant things I can infer from strtok() is that it has to use
static state information (which naturally doesn't support re-entrant
code). I see that this obviously also consequently implies that it's
not-thread safe and that you also obviously cannot nest calls as you
depicted it above (and I think this is even documented for those to
whom it may not be obvious).
So again; if it's unnecessary here why should I prefer using a more
clumsy code than necessary that makes the code less clear?
If I'd write (for example) a library function to parse tokens then
I'd certainly not use this function because I don't want conflicts
and dependencies on the surrounding context of other code that uses
this library function.
But, again, in my application context its makes no sense.
Janis