473,796 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5567
Zack <goldszs...@gma il.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********@gma il.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
414
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
4927
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 happen before 'splitCommands' entered the picture. The problem is in splitCommands( ) somehow modifying the pointer, but I HAVE to call that function. Is there a way to make a copy of it or something ? /* HERE IS MY CODE */ char *...
20
17244
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: 0.0.0.0--->I want to tokenize the string using delimiter as as dot. Regards
8
1932
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 dreams." #include <stdafx.h> #include <string.h> #include <stdio.h> int main()
4
2736
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 somehow confused or upset. I have the following code, which I am using to tokenise some input which is in th form x:y:1.2: int tokenize_input(Sale *sale, char *string){
3
3811
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 <string> #include <stdlib.h> using namespace std;
29
2588
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
904
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", "passwort" from "users" order by "users"
11
17179
by: magicman | last post by:
can anyone point me out to its implementation in C before I roll my own. thx
12
2361
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) 3.4.5 (mingw special) I would like there to be a default, to be returned when two delimiters
0
9530
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10017
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.