Hi, thanks for your answer.
I did check the function and it worked. I've been implementing all of them based on the c++ reference at cplusplus.com. I've tested all of them with the given examples and corrected some bugs when I altered them. I also compared their behavior to the standard ones (talking about GCC and its libs here).
You are right saying it returns NULL. I'm trying to think about what could have happened, I am totally sure it worked. Maybe I just changed the code somewhere, awkward...
Looking at the code I get it. During some of my copy+pasting I added:
Now since we were at 0 it couldn't ever iterate so it just stopped (well, you got it.)
Relating the 'going past the buffer' issue, here's my workaround which I think fixes everything that's mentioned:
Code:
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 && ((char*)str!=ptr_str)) ;
if(*ptr_str==(char)character)
return ptr_str;
else return NULL;
}
Do you think it is ok like this?
Also, I do not think it is undefined behaviour when I think of it as assembly code. Reading from left to right, since I've got to the conclusion that both TenDRA and GCC do this (reading from left to right). I think saying x && y is not the same as y && x. (but that's just me).
Thanks allot.