|
From: Jason H. <jas...@bt...> - 2001-10-20 02:16:30
|
As defined in C/C++ Programmers Reference: strcat ------ #include <string.h> char *strcat(char *str1, const char *str2); The strcat() function concatenates a copy of str2 to str1 and terminates str1 with a null. The null terminator originally ending str1 is overwritten by the first character of str2. The string str2 is untouched by the operation. If the arrays overlap, the behavior of strcat() is undefined. In C99, str1 and str2 are qualified by restrict. The strcat() function returns str1. Remember, no bounds checking takes place, so it is the programmer's responsibility to ensure that str1 is large enough to hold both its original contents and also those of str2. ------------------------ The function strcat() is defined in the C, and therefore the C++, standard. It must follow a consistent behaviour. It is feasible that it could have been written in assembler, but it will still have the same basic behaviour. I know it would be slow in large strings, but there isn't really any faster and reliable way to search for the null. Skipping characters opens up the possibility of missing the proper null, and accessing characters after it which will be undefined. In strcat you might not overrun the array containing the string that way, but in a similar function such as strlen you probably would, and that would be an access violation. Without more information about the string being passed then you are pretty much limited to going throught the string from start to finish. Generally if a programmer was dealing with very large string then it would be wise for him/her to find a better way of dealing with them (such as tracking the length), or to just accept the performance hit. Whether the include is an on/off switch or a header won't change the way the function works, just how the compiler adds it to the exe. Regards, Jason. PS: Yet again I've probably gone OTT (Over The Top). LOL! It looks like I've written an essay on a standard function. PPS: Why is it us to always seem to be arguing over silly little things like this? |