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

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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.