Path: utzoo!attcan!uunet!peregrine!elroy!ames!mailrus!tut.cis.ohio-state.edu!rutgers!rochester!pt.cs.cmu.edu!unh.cs.cmu.edu!agn From: agn@unh.cs.cmu.edu (Andreas Nowatzyk) Newsgroups: comp.lang.c++ Subject: Re: goodbye cpp ??? (macros vs. inline functions) Message-ID: <3637@pt.cs.cmu.edu> Date: 21 Nov 88 22:58:39 GMT References: <6590072@hplsla.HP.COM> <1757@dataio.Data-IO.COM> Organization: Carnegie-Mellon University, CS/RI Lines: 45 Bjarne Strousrup's C++ book claims that inline functions eliminate the need for most uses of macros and other cpp-features. I find that statement overly optimistic and plain false in many actual cases. Using the ATT version 1.2.1 of C++, I found inline functions to be inadequate because: a) They produce poor code: Everything becomes one large comma-expression. Even optimized, the resulting assembly code is awful. b) They lack control of temporary variables and/or objects. Numerous temporary variables are being added - frequently without need. Since my C-compiler doesn't optimize the use of registers, it is not possible to force inline functions to keep certain temporary variables in registers. c) They have a lot of restrictions (inability to use functions that don't return values, no loops, troublesome nesting, etc.). d) They lack control of instantiation: 2 (identical) int inline function appear as the operands to an "==": the left inlines normally, the right is replaced by a function call! In this case, replacing an inline with an function call is fatal to the program (1), but the compiler doesn't even issue a warning. e) No reasonable substitute for conditional compilation: in some modules certain functions have to be modified and parts of the function would not compile in that environment. The bottom line is - for now - that inline-function are not even close to replacing cpp. Note that performance is not the only reason: lacking control on when and how to expand can result in incorrect code. -- Andreas (1): In case you wondered how this can happen: the inline-function needs to know the line-number of where it appears in the source code. Is is part of an instrumentation package for parallel code running on a simulated multiprocessor. -- -- Andreas Nowatzyk (DC5ZV) Carnegie-Mellon University Arpa-net: agn@unh.cs.cmu.edu Computer Science Department Usenet: ...!seismo!unh.cs.cmu.edu!agn --