"Dr. Nikolaus Klepp" <[email protected]> writes:
> Am Freitag, 22. Januar 2016 schrieb Rainer Weikusat:

[...]

>>     name_len = strlen(name);
>>     what_len = strlen(what);
>>     total = name_len + what_len + 3;
>>     
>>     p = buf = alloca(total);
>>     memcpy(p, name, name_len);
>>     p += name_len;
>>     *p++ = ' ';
>>     memcpy(p, what, what_len);
>>     p += what_len;
>>     *p++ = ':';

[...]

> just out of couriosity: why don't you use "strcat"?

Because strcat is A Seriously Bizarre Invention[tm].

        Programmers using the strcat or wcscat function (or the
        following strncat or wcsncar functions for that matter) can
        easily be recognized as lazy and reckless. In almost all
        situations the lengths of the participating strings are known
        (it better should be since how can one otherwise ensure the
        allocated size of the buffer is sufficient?) Or at least, one
        could know them if one keeps track of the results of the various
        function calls. But then it is very inefficient to use
        strcat/wcscat. A lot of time is wasted finding the end of the
        destination string so that the actual copying can start.

        
https://www.gnu.org/software/libc/manual/html_node/Copying-and-Concatenation.html#Copying-and-Concatenation
_______________________________________________
Dng mailing list
[email protected]
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng

Reply via email to