Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!uunet!mcsun!ukc!dcl-cs!aber-cs!athene!pcg From: pcg@cs.aber.ac.uk (Piercarlo Grandi) Newsgroups: comp.lang.c++ Subject: Re: >>> Virtual functions and inline ... Message-ID: Date: 2 Mar 91 19:36:32 GMT References: Sender: aro@aber-cs.UUCP Organization: Coleg Prifysgol Cymru Lines: 34 Nntp-Posting-Host: odin In-reply-to: ssimmons@convex.com's message of 1 Mar 91 14:11:06 GMT On 1 Mar 91 14:11:06 GMT, ssimmons@convex.com (Steve Simmons) said: From: gas@cs.nott.ac.uk (Alan Shepherd) gas> Is it okay to declare virtual functions inline ? Even though the gas> code to be excuted is substituted rather than a function call made, gas> does the correct method still get called ? ssimmons> This is not a wise thing to do although the language ssimmons> will allow it. You can do it, and if your virtuals are usually resolvable at compile time (because the class of the relevant object is known statically) they will be inlined. Indeed this is a very frequent case, so it may well be wise. In theory the compiler can generate an inline switch statement if the virtual is not resolvable at compile time, but I know of no compilers that do so. ssimmons> In the first place, you are never guaranteed that a routine ssimmons> is inlined. It is only a suggestion to the compiler. If ssimmons> the routine is either too complicated or a virtual function, ssimmons> then a static copy of the routine will be placed in the ssimmons> compiled module. [ ... ] This need not happen with GNU C++, which has #pragma interface and implementation, and does noit happen with recent versions of cfront 2.x either (no direct experience), as it chooses one of the relevant objects for dumping all the virtuals once and for all. It used to happen, with horrid results, with cfront 1.x. -- Piercarlo Grandi | ARPA: pcg%uk.ac.aber.cs@nsfnet-relay.ac.uk Dept of CS, UCW Aberystwyth | UUCP: ...!mcsun!ukc!aber-cs!pcg Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk