Hi again.

Quite a long time since I last wrote here.

Once again, and as my self-tutoring life progresses, I find myself with some questions which I will ask you.

I've been trying to develop basic Standard C++ (and also C) library functions. About two seconds (wohoo) ago I finished string.h (or cstring or whatefver you may wish).

During the developing of its functions I stumbled across some doubts.
i.e. - In the following piece of code:

Code:
if(*--ptr_str2==*ptr_str1++) ptr_str2=(char*)str2;
else return --ptr_str1-str1;
Alright it's out of context, but picture that only. Is that piece of code faster than:

Code:
if(*--ptr_str2==*ptr_str1) { ptr_str1++; ptr_str2=(char*)str2; }
else return ptr_str1-str1;
Answering myself, I think it depends on the case. If the if statement becomes true, then I _think_ i spare time in doing what I do in the second sample of code, but, when it evaluates to false, I have to decrement it again (or maybe just subtract one to it in a logical expression...), lowering performance.

I would like to post the whole code from all my functions and get an opinion from the 'experts', just to check if I'm going in the right direction. If you allow me to do it, in my next post I will paste the code here. For now, if it wouldn't bother you really much, I'd like you to comment on my implementation of strspn:

Code:
size_t strspn ( const char * str1, const char * str2 ) {
char* ptr_str1=(char*)str1,* ptr_str2=(char*)str2;
while(*ptr_str1) {
while(*ptr_str2++!=*ptr_str1 && (*ptr_str2)) ;
if(*--ptr_str2==*ptr_str1++) ptr_str2=(char*)str2;
else return --ptr_str1-str1;
}
return ptr_str1-str1;
}
Do you think it is ok? How could it be improved? What are the major performance hits?

Also (once again, not posting the WHOLE code), could you also comment on the following, please?

Code:
/* strrchr - Return a pointer to the last occurence of character in str. */
const char * strrchr ( const char * str, int character ) {
char* ptr_str=(char*)str;
while (*ptr_str++) ; /* Go to the end of the string */
while (*--ptr_str!=(char)character && (*ptr_str)) ;
if(*ptr_str!=(char)character) return NULL;
return ptr_str;
}
Thanks in advance, sorry if I sound too 'crazy' or 'rhetorical'.