[net.lang.c] in-line functions

chris@umcp-cs.UUCP (Chris Torek) (02/09/85)

jss@sjuvax (J. Shapiro) suggests that we consider inline functions,
rather than ridiculously complex macros.  It's a good idea.  MESA has
an INLINE keyword which does the obvious thing.  One could use
``register'' functions in C to do the same thing.

One point (which is obvious when you think about it) is that the
function definition must be available to all routines that use it; the
straightforward approach of generating no code for a register function
breaks the existing scope rules in C.  Two solutions come to mind:
either put the definition in a header file (which might fail if
compilers were allowed to ignore the register keyword when applied to
functions), or instead, generate code but expand in-line anyway (that
is, for

	register foo() {
		return bar();
	}

generate a true foo function, but just call bar() directly for
instances of calls to foo() within the rest of that source file).

Unfortunately, this defeats the purpose of register functions if they
are to be called from outside that particular source file, and adds
extra space if they are not.  (One could use "static register foo()"
functions, but this seems to be getting ridiculous...)
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris@umcp-cs		ARPA:	chris@maryland

guy@rlgvax.UUCP (Guy Harris) (02/09/85)

> jss@sjuvax (J. Shapiro) suggests that we consider inline functions,
> rather than ridiculously complex macros.  It's a good idea.  MESA has
> an INLINE keyword which does the obvious thing.  One could use
> ``register'' functions in C to do the same thing.

C++ has an "inline" keyword as well; I first saw the inline function idea
in the Mesa Reference Manual, and though it was a neat idea - I was glad
to see C++ picking it up.  (But wouldn't a "register" function be one that
was copied to the general registers and executed on a PDP-10? :-))

> One point (which is obvious when you think about it) is that the
> function definition must be available to all routines that use it; the
> straightforward approach of generating no code for a register function
> breaks the existing scope rules in C.  Two solutions come to mind:
> either put the definition in a header file (which might fail if
> compilers were allowed to ignore the register keyword when applied to
> functions)...

C++ takes this approach; since all C++ compilers support the "inline"
keyword, the problem you mention doesn't occur.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy