C Builtin Functions

KW Heuer kwh at bentley.UUCP
Mon May 5 08:20:14 AEST 1986


In article <1700010 at umn-cs.UUCP> umn-cs!herndon writes:
>I feel compelled to go on record as being VERY MUCH AGAINST having reserved
>procedure names in C.  For those of us who have ever written stand-alone
>code for PDP-11s, VAXen, ..., it is a simple matter, as things stand, to
>compile our programs, and then have them linked with our own versions of
>'putc', 'read', etc. stashed in stand-alone libraries.

Fine, if you replace *all* of libc.  Otherwise you may find surprises (some
of the stdio function behave as though they call each other, but have been
optimized to use the system calls directly in some cases).

>One of the (in my opinion) great strengths of the C language is that it
>does not have 'built-in' functions.

After rethinking this question, I've decided that it *does*.  However, the
builtins are all punctuation ("%"), whereas the library functions are all
alphanumeric ("abs").  The only exception is "sizeof", which is something of
a special case anyway.  (Let's not quibble about "sizeof" again.  And yes, I
know "%" is an "operator", but doesn't that just mean "builtin function with
builtin syntax"?)

>If one user doesn't like the interface that 'printf' provides, or a whole
>bunch of users don't, they are free to write their own functions and use
>those instead.

As has been mentioned before, if you're changing the semantics it's wise to
change the name too.

>Building those functions into the language implies that there will be much
>code [within the compiler] for special casing those functions.

But the standard doesn't *require* them to be special-cased; you could port
the compiler by commenting out that code.

>On the flip side, the language may not be as efficient.  If the compiler
>writers want to allow these procedures to be built-in to allow in-line
>procedures, I think this should be an option (DEFAULT=OFF), and then the
>capabilities of the language will be compromised as little as possible.

If they make it an option, the default will probably be ON.

Here's my opinion.  Using punctuation for builtins (and alphanumerics for
library functions) is a nice way to keep them straight; let's keep it that
way.  If certain functions are so trivial that it's worthwhile for them to
be expanded inline (are there any besides abs(), min(), and max()?), then
they should have non-alphanumeric spellings; i.e. they should be operators.

I can feel the flames ("More operators?  It's getting as bad as APL!").

Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint



More information about the Comp.lang.c mailing list