Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!lll-tis!ames!hao!boulder!sunybcs!bingvaxu!leah!itsgw!batcomputer!cornell!uw-beaver!uw-june!pardo From: pardo@uw-june.UUCP (David Keppel) Newsgroups: comp.lang.c Subject: Re: C blocks [ inlining ] Message-ID: <3894@uw-june.UUCP> Date: 28 Dec 87 07:11:44 GMT References: <470@PT.CS.CMU.EDU> <1966@chinet.UUCP> <970@csun.UUCP> <1313@sugar.UUCP> Reply-To: pardo@uw-june.UUCP (David Keppel) Organization: U of Washington, Computer Science, Seattle Lines: 60 [ 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 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