[comp.lang.c] Optimizing standard library calls

kruger@whyvax.dec.com (Bear with me) (03/22/88)

>>>       printf("Hello world!\n");
>>>Haven't you ever heard of puts????
>>>       puts("Hello world!");   /* note the newline is appended */
>>
>>        I can't imagine any reasonably competant C compiler not
>>generating the almost same codes for both cases.
> 
>These are not part of the language!!  They are some external routine.  The
>compiler can`t do this kind of optimization.

The ANSI standard allows replacement of standard library functions by macros,
except as noted in certain specific cases. Since names starting with an
underscore are reserved to the implementation, the compiler is allowed to
optimize standard library calls, at a cost in complexity of course.

The definition would look like this:

#define printf	_printf

The compiler knows about the existence of _printf and can optimize that
operator, but if it is undef'd, you have your call back. This is a powerful,
portable method of achieving optimizations, and one we will probably see a
lot of in the future.

dov

If anything I say creates problems, don't call Digital about it. Likewise, if
you are having a problem with your Vax, feel free not to call me.