HN user

robot314

2 karma
Posts0
Comments1
View on HN
No posts found.

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 [2] http://ohse.de/uwe/articles/gcc-attributes.html#func-pure