473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

strtok

The c99 standard states "The implementation shall behave as if no
library function calls the strtok function." What exactly does this
mean? Does this dictate any requirements to architectures supporting
proccesses or threads?
--
Zack
Mar 15 '07 #1
9 5496
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

Mar 15 '07 #2
In article <h_******************************@comcast.com>,
Zack <go********@gmail.comwrote:
>The c99 standard states "The implementation shall behave as if no
library function calls the strtok function." What exactly does this
mean? Does this dictate any requirements to architectures supporting
proccesses or threads?
Imagine what would happen if your program looked like:

/* Don't need processes or threads for this to be a problem */
x = strtok(...); /* I'm using strtok, with its stateful nature */

y = somelibfunc(...); /* What would happen if somelibfunc called strtok
internally? */

Mar 15 '07 #3
Zack wrote:
>
The c99 standard states "The implementation shall behave as if no
library function calls the strtok function." What exactly does this
mean?
It means that if you call another library function
in between two strtok calls,
that it shouldn't affect the state of the strtok function.

--
pete
Mar 16 '07 #4
Peter Nilsson wrote:
No, it dictates library implementation requirements and gives
programmers greater freedom to mix strtok with other library
functions (e.g. other string library functions).
Okay,
I guess I'm getting OT now but if I have a proccess what is the scope of
strtok? Practically how do you deal with 3rd party libraries? If they
use strtok do you get hosed? The way I'm reading this is that if i link
to any libraries using strtok we can both get chaos mixed in. The only
exemption is std c library functions.
--
Zack
Mar 16 '07 #5
Zack wrote:
Peter Nilsson wrote:
>No, it dictates library implementation requirements and gives
programmers greater freedom to mix strtok with other library
functions (e.g. other string library functions).
Okay,
I guess I'm getting OT now but if I have a proccess what is the scope of
strtok? Practically how do you deal with 3rd party libraries? If they
use strtok do you get hosed? The way I'm reading this is that if i link
to any libraries using strtok we can both get chaos mixed in. The only
exemption is std c library functions.
You are getting OT. :-)

You have to make a distinction between processes and threads
depending on the platform. strtok will probably behave normally
if called from two separate processes at the same time but it
will probably not work correctly with threads. This is just a
hint, notice the two "probably". You'll have to ask in a more
appropriate group and check the documentation for your standard
libary.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Mar 16 '07 #6
Zack wrote:
Peter Nilsson wrote:
>No, it dictates library implementation requirements and gives
programmers greater freedom to mix strtok with other library
functions (e.g. other string library functions).

I guess I'm getting OT now but if I have a proccess what is the
scope of strtok? Practically how do you deal with 3rd party
libraries? If they use strtok do you get hosed? The way I'm
reading this is that if i link to any libraries using strtok we
can both get chaos mixed in. The only exemption is std c library
functions.
It'll work just fine, as long as you don't give other routines the
option of calling it while you want it to preserve status for you.
When you call it with a non-NULL pointer you initialize it.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Mar 16 '07 #7
CBFalconer wrote:
Zack wrote:
>I guess I'm getting OT now but if I have a proccess what is the
scope of strtok? Practically how do you deal with 3rd party
libraries? If they use strtok do you get hosed? The way I'm
reading this is that if i link to any libraries using strtok we
can both get chaos mixed in. The only exemption is std c library
functions.

It'll work just fine, as long as you don't give other routines the
option of calling it while you want it to preserve status for you.
When you call it with a non-NULL pointer you initialize it.
strtok will work for me just fine if I link with a library that uses
strtok?

--
Zack
Mar 17 '07 #8
Zack wrote:
CBFalconer wrote:
>Zack wrote:
>>I guess I'm getting OT now but if I have a proccess what is the
scope of strtok? Practically how do you deal with 3rd party
libraries? If they use strtok do you get hosed? The way I'm
reading this is that if i link to any libraries using strtok we
can both get chaos mixed in. The only exemption is std c library
functions.

It'll work just fine, as long as you don't give other routines the
option of calling it while you want it to preserve status for you.
When you call it with a non-NULL pointer you initialize it.

strtok will work for me just fine if I link with a library that
uses strtok?
The linking doesn't matter. The calling does. Since the library
is a black box, don't call that library while you need the strtok
status preserved.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Mar 17 '07 #9
CBFalconer wrote:
Zack wrote:
>CBFalconer wrote:
>>Zack wrote:

I guess I'm getting OT now but if I have a proccess what is the
scope of strtok? Practically how do you deal with 3rd party
libraries? If they use strtok do you get hosed? The way I'm
reading this is that if i link to any libraries using strtok we
can both get chaos mixed in. The only exemption is std c library
functions.

It'll work just fine, as long as you don't give other routines the
option of calling it while you want it to preserve status for you.
When you call it with a non-NULL pointer you initialize it.

strtok will work for me just fine if I link with a library that
uses strtok?

The linking doesn't matter. The calling does. Since the library
is a black box, don't call that library while you need the strtok
status preserved.
Ok that's what I thought. So if a library is treated as a black box
you have no idea whether strtok is safe or not.
Thanks.
--
Zack
Mar 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ram Laxman | last post by:
Hi all, I have written the following code: /* strtok example */ #include <stdio.h> #include <string.h> static const char * const resultFileName = "param.txt";
13
by: ern | last post by:
I'm using strtok( ) to capture lines of input. After I call "splitCommand", I call strtok( ) again to get the next line. Strtok( ) returns NULL (but there is more in the file...). That didn't...
20
by: bubunia2000 | last post by:
Hi all, I heard that strtok is not thread safe. So I want to write a sample program which will tokenize string without using strtok. Can I get a sample source code for the same. For exp:...
8
by: hu | last post by:
hi, everybody! I'm testing the fuction of strtok(). The environment is WinXP, VC++6.0. Program is simple, but mistake is confusing. First, the below code can get right outcome:"ello world, hello...
4
by: Michael | last post by:
Hi, I have a proble I don't understand when using strtok(). It seems that if I make a call to strtok(), then make a call to another function that also makes use of strtok(), the original call is...
3
by: nomad5000 | last post by:
Hi everybody! I'm having trouble using strtok to fill a matrix with int nrs. from a file. the code that is not working is the following: #include <iostream> #include <fstream> #include...
29
by: Pietro Cerutti | last post by:
Hello, here I have a strange problem with a real simple strtok example. The program is as follows: ### BEGIN STRTOK ### #include <string.h> #include <stdio.h>
11
by: Lothar Behrens | last post by:
Hi, I have selected strtok to be used in my string replacement function. But I lost the last token, if there is one. This string would be replaced select "name", "vorname", "userid",...
11
by: magicman | last post by:
can anyone point me out to its implementation in C before I roll my own. thx
12
by: Pilcrow | last post by:
Here is a quick program, together with its output, that illustrates what I consider to be a deficiency of the standard function strtok from <string.h>: I am using C:\>gcc --version gcc (GCC)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.