Sender: nate AT cartsys DOT com Message-ID: <35F2BA6C.F2015C97@cartsys.com> Date: Sun, 06 Sep 1998 09:38:04 -0700 From: Nate Eldredge MIME-Version: 1.0 To: Ilya Ryzhenkov CC: djgpp workers list Subject: Re: Preventing compiler from expanding inline References: <35F1B0BD DOT 707A60C7 AT inetlab DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Ilya Ryzhenkov wrote: > > Hi again, I hope I don't annoy anyone ;-) > > Just a simple question - is there any method to prevent > specific function from expanding inline ? I don't mean > global -f option, I think of something like function > attribute or #pragma or whatever else. If you don't declare it `inline' and optimize with less than `-O3', AFAIK, it won't be inlined. But if you need it declared `inline' for other occurences, I don't know how you can force a call in some place. Except of course inline void foo() { /* ... */ } ... ((void (volatile *)())&foo)(); > Does anybody knows how gcc decides (under normal conditions, i.e > no overrides like inline keyword or inline restrictions) > when to expand function (class member) inline ? Is it size > condition, or complexity or something else ? Okay. To even consider inlining a function, one of the following must be true: * The function is declared `inline'. * The file is being compiled with `-O3' or `-finline-functions'. That is true in C, at least. In C++, I assume defining the function inside the class will do it too. And: * It must already have been defined at the point where it's used. Then, the test for whether a function may be inlined is in `integrate.c', in function `function_cannot_inline_p'. Basically, if any of the following are true, the function will not be inlined. * Uses varargs. * Uses alloca. * Has nested functions. * Returns a structure in registers. * Has an argument of a varying-size structure, or returns one. (I don't know what that means.) * Has more than INTEGRATE_THRESHOLD insns. This seems to be something like 8 * (number of args + 8). * Has a nonlocal goto. * Several other complicated cases. Read the source. If you compile with `-Winline', the compiler will warn when a function that should be inlined cannot be (i.e. passes the first test but fails the second), and it will explain why. > I need it to prevent constructors of some classes from > expanding inline. I need a real call instruction to them > everywhere they are used. You could define it outside the class, perhaps? -- Nate Eldredge nate AT cartsys DOT com