Should I use macros to inline code?
adam at visix.com
adam at visix.com
Thu Mar 28 15:41:11 AEST 1991
In article <1991Mar27.024602.21399 at visix.com> I wrote:
-> Assuming that's useful, is there any use for subroutines, so that a
-> routine is only inlined once per function?
:
:
-> (Actually, I don't see any way to pass arguments to and return from
-> subroutines that would make them useful in C.)
In article <15601 at smoke.brl.mil>, gwyn at smoke.brl.mil (Doug Gwyn) writes:
> ???
Oops! Normally I am really quite intelligible, sorry about that.
I've been playing with the idea of a toy preprocessor to provide some
automagic premangling of my C source. Among other things, I thought
it would be nice to automatically generate inlining macros from
existing function definitions (if inlining is useful).
Now, given inlining, I wondered, what if a two-line function gets
inlined twenty times in one function? Wouldn't it be more efficient
to inline the actual code only once, with a label, and then expand
calls to it into goto's to the label? Since the goto itself doesn't
push any arguments, I called this option a subroutine, out of analogy
to BASIC's GOSUB.
This gives the programmer three choices:
inlining when time is a lot more important than memory
subroutines when time is a little more important than memory
functions when time is not more important than memory
But subroutines look like a lot of trouble to implement, so before I
even start thinking about it, I have to ask, is it worth it?
Adam
More information about the Comp.lang.c
mailing list