DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   strtok_r() error on solaris 8 (http://www.daniweb.com/forums/thread5587.html)

liliafan Apr 27th, 2004 11:28 pm
strtok_r() error on solaris 8
 
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:

    char *svptr; 
    char *s;   
    char cont[input.length()];
    const char *delim = " "; 
    const char *sdelim = "0123456789";
   
    sprintf(cont, "%s", input.c_str());
     
    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

infamous Apr 28th, 2004 12:35 pm
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.

liliafan Apr 28th, 2004 2:46 pm
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

liliafan Apr 28th, 2004 3:19 pm
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


All times are GMT -4. The time now is 6:22 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC