pardo@uw-june.UUCP (David Keppel) (12/28/87)
[ adding the capability to "inline" ] I think the capability to inline would be great. To add to the list of prior art, (wheell, sort of) the C++ compiler does inling. Neat stuff, doesn't have strange effects the way macros do (evaluating arguments with side effects multiple times, etc.) and you can debug the code running the proc version and then do a final run with inline. There are problems tho': What you really want is to be able to inline a function some places and not others [why? if it appears several places, only one of them is time-critical, and the inlined function is large. You also want to be able to do putc/fputc without having two names or 2 copies of identical code] There are lots of fun and games to be had debugging an inlined function with variable names the same as lexically enclosing blocks [whoops! C isn't "flat" anymore!]: int zork inline mork(x) int x { zork = x/2; dork(zork) } void bork() { int zork = y(); mork (zork); } Recursively expanded inline functions should do the right thing e.g., if both "foo" and "bar" are defined as inline and "foo" calls "bar" and "bar" calls "foo" then the compiler will go nuts trying to inline things. If an inline function has static variables do you (a) make the static a global static (with possible name conflicts) (b) give everybody a seperate copy of the static variable (b) certainly breaks if you want to have the static holding a seed for a random number generator. If you "inline" "random_num" twice: int random_num() { int seed = 1; return (++seed) } r1 = random_num(); r2 = random_num() then r1 == r2 always since they have local copies of the seed. You would like to be able to inline functions from libraries. This requires a mechanism for describing the file to fetch from, e.g., #inline <stdio.c> Not that all of this is impossible. I suggested this as a project for a compilers class and was told that it was too easy. (Perhaps if all you guys send mail I can convince my professor to let me do this abuse to pcc and _then_ prior art will be established? ;-) If anybody is interested in doing this, send me mail and I will send you my "proposal", which is basically a longer version of the above list. If anybody has further suggestions on the "right" way to do this, please send me mail. I'm still interested. If there is sufficient interest, I will summarize and post responses. ..!ucbvax!uw-beaver!uw-june!pardo pardo@cs.washington.edu ;-D on (what happens if you try to inline main()?) Pardo
franka@mmintl.UUCP (01/09/88)
In article <3894@uw-june.UUCP> pardo@uw-june.UUCP (David Keppel) writes: >[ adding the capability to "inline" ] >What you really want is to be able to inline a function some places and not >others Try: inline int inline_foo(int bar) { ... } int function_foo(int bar) { return inline_foo(bar) } (I'm not recommending the naming conventions, just the technique.) You have to duplicate the declaration part, but at least the code only has to be written once. This is also useful if you want to take the address of the function, although the compiler can deal with that automatically. -- Frank Adams ihnp4!philabs!pwa-b!mmintl!franka Ashton-Tate 52 Oakland Ave North E. Hartford, CT 06108