943,603 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 5590
  • C RSS
Apr 27th, 2004
0

strtok_r() error on solaris 8

Expand Post »
Hi I am getting an error with some code, it compiles fine on linux but it is throwing an error on solaris, it is to do with strtok_r, the following is the error message:

sku_cache.cpp:150: implicit declaration of function `int strtok_r(...)'
sku_cache.cpp:150: assignment to `char *' from `int' lacks a cast

The code in question is:

  1. char *svptr;
  2. char *s;
  3. char cont[input.length()];
  4. const char *delim = " ";
  5. const char *sdelim = "0123456789";
  6.  
  7. sprintf(cont, "%s", input.c_str());
  8.  
  9. s = strtok_r(cont, delim, &svptr);

As I said this compiles without error on linux but using solaris 8 it complains, on checking the man pages on both machines:

Solaris:
char *
strtok_r(char *str, const char *sep, char **last);

Linux:
char *strtok_r(char *s, const char *delim, char **ptrptr);

Any help would be greatly appreciated.

Thanks

Ben
Reputation Points: 66
Solved Threads: 3
Junior Poster
liliafan is offline Offline
117 posts
since Apr 2004
Apr 28th, 2004
0

Re: strtok_r() error on solaris 8

the compiler is telling u waht is wrong. the manual page apparently has an incorrect prototype, b/c gcc is telling u that it is returning an integer. try loooking at the header file and seeing if it has any notes on the function, or u can always try casting the return to a (char *) - but i dont think it is returning what u think it is.
Reputation Points: 47
Solved Threads: 2
Junior Poster in Training
infamous is offline Offline
77 posts
since Mar 2004
Apr 28th, 2004
0

Re: strtok_r() error on solaris 8

Hi infamous,

Well on looking on /usr/include/string.h I find:
extern char *strtok_r(char *, const char *, char **);

When I attempt to change:

char *s;
to
int s;

I get rid of that error and get the following error:

implicit declaration of function `int strtok_r(...)'

Great isn't it, it says it wants an int even although there is no way I can see how the function would work with an int, when it an int it causes an error still.

Any further advice graciously recieved.

Thanks
Ben
Reputation Points: 66
Solved Threads: 3
Junior Poster
liliafan is offline Offline
117 posts
since Apr 2004
Apr 28th, 2004
0

Re: strtok_r() error on solaris 8

Okay I have solved the problem, one of the other files in this program is using pthreads. which means I am linking with -lpthread, which includes its own thread safe version of strtok_r(), which does return an int value, however, by passing -D_REENTRANT to the compiler it uses the strtok_r in string.h instead of the one from the pthread library.

It is supposed to be a known problem in solaris (but if it is well know it is very well hidden).

Thanks for the help all the same.

Ben
Reputation Points: 66
Solved Threads: 3
Junior Poster
liliafan is offline Offline
117 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Really quick G2++ question!
Next Thread in C Forum Timeline: XP style in DOS !





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC