11 ms·
How can compilers optimize a printf() call without format strings involved towards a simple puts() call? Sure it would be easy in C++, roughly like inline vo
by ktpsns 8y ago
How can compilers optimize a printf() call without format strings involved towards a simple puts() call? Sure it would be easy in C++, roughly like
inline void printf(const char* const s) { puts(s); }
void printf(const char* const s, ...); /* non-trivial implementation */
but that's not possible in C.
- detaro 8y agoThey treat it as a built-in function, instead of always linking it to system libraries. Built-in functions they can implement however they want. If you insist on using the library implementation (e.g. because you have your own), you have to tell the compiler not to use its internal one. E.g. gcc docs on this: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html