4 ms·
First off, with regards to calling strlen multiple times in the loop, the author is just plain wrong. Gnu C has something called __builtin_strlen which is a com
by robot314 13y ago
First off, with regards to calling strlen multiple times in the loop, the author is just plain wrong. Gnu C has something called __builtin_strlen which is a compiler extension that can replace the function calling a statically allocated string with just its length[1] making it essentially zero overhead. Second, strlen is defined with __attribute_pure__, which means that the compiler can optimize to just one function call in all other cases[2]. With these two compiler optimizations, C is at least as efficient as C++ in worst cases, and much better otherwise.
[1] http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
[2] http://ohse.de/uwe/articles/gcc-attributes.html#func-pure http://ohse.de/uwe/articles/gcc-attributes.html#func-pure
- jhasse 13y agoBut what "if the doSomethingWith function takes a non-const pointer"? Also why would C be better otherwise?