Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!uunet!convex!ssimmons From: ssimmons@convex.com (Steve Simmons) Newsgroups: comp.lang.c++ Subject: >>> Virtual functions and inline ... Message-ID: Date: 1 Mar 91 14:11:06 GMT Sender: news@convex.com (news access account) Organization: Convex Computer Corporation, Richardson, Tx. Lines: 35 Nntp-Posting-Host: pixel.convex.com >From: gas@cs.nott.ac.uk (Alan Shepherd) > Organization: Nottingham University > Date: 28 Feb 91 14:15:48 GMT > Subject: Virtual functions and inline > Is it okay to declare virtual functions inline ? Even though the code > to be excuted is substituted rather than a function call made, does > the correct method still get called ? This is not a wise thing to do although the language will allow it. In the first place, you are never guaranteed that a routine is inlined. It is only a suggestion to the compiler. If the routine is either too complicated or a virtual function, then a static copy of the routine will be placed in the compiled module. Thus, a routine that was coded as inline may cause a performance degradation because it may consume much more space when it is not physically inlined. With a virtual function, a copy of that routine will be created for every module that has at least one instantiation of that class. The language allows it but you would not be deriving any better performance. I have become very negative towards the inline feature of a language like Ada's inline pragma or C++'s inline definition. After all, inlining is not part of the algorithm, just a performance enhancement. Inlining should be done as part of the optimizing phase. Thank you. Steve Simmons