Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!hellgate.utah.edu!helios.ee.lbl.gov!ux1.lbl.gov!beard From: beard@ux1.lbl.gov (Patrick C Beard) Newsgroups: comp.lang.c++ Subject: Re: Request for C++ coding "guidelines" Keywords: C++, inlines Message-ID: <4843@helios.ee.lbl.gov> X-Local-Date: 13 Feb 90 19:36:17 PST Date: 14 Feb 90 03:36:17 GMT References: <2754@arran.tcom.stc.co.uk> <25D0B18E.27508@paris.ics.uci.edu> <4446@pegasus.ATT.COM> Sender: usenet@helios.ee.lbl.gov Reply-To: beard@ux1.lbl.gov (Patrick C Beard) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 37 In article <4446@pegasus.ATT.COM> hansen@pegasus.ATT.COM (Tony L. Hansen) writes: #< Regarding the extent to which inline functions should be used, I believe #< that there have been numerous comments here lately pointing out that the #< use of inline functions should be highly restricted. Some radicals among #< us (Who, me?) may say that inline functions should never be used. I am #< reminded of the ending of the movie 2010. # #I think that the comments lately have been pointing out problems with some #current implementations of inline functions: # # When the inline must be outlined, a static version will be created # as needed in EVERY .o file where it is needed. When the .o's are # combined, you suddenly have N occurrences of the static function # which wastes considerable space. Now hold on. The amount of space wasted by outlining inline functions to static functions for every file that needs them will always be <= to the code space taken by correctly inlining the function to begin with. And will likely be much less. So this brings to mind some guidelines for using inline member functions. 1. Inlines should be one line of code. [I use them mainly for read only access to private or protected data]. 2. Inlines should be simple. One convention I use is that all my classes have a method called Error() which returns the most recently encountered operating system error. Since this just looks at the variable error stored in each instance, I always define it as: OSErr Error() { return error; } ------------------------------------------------------------------------------- - Patrick Beard, Macintosh Programmer (beard@lbl.gov) - - Berkeley Systems, Inc. "..............Good day!" - Paul Harvey - -------------------------------------------------------------------------------