Path: utzoo!attcan!uunet!mcvax!ukc!strath-cs!glasgow!orr From: orr@cs.glasgow.ac.uk (Fraser Orr) Newsgroups: comp.lang.c++ Subject: Re: goodbye cpp ??? (macros vs. inline functions) Keywords: cpp inline functions Message-ID: <1931@crete.cs.glasgow.ac.uk> Date: 23 Nov 88 18:13:44 GMT References: <6590072@hplsla.HP.COM> <1757@dataio.Data-IO.COM> <3637@pt.cs.cmu.edu> Reply-To: orr@cs.glasgow.ac.uk (Fraser Orr) Organization: Comp Sci, Glasgow Univ, Scotland Lines: 50 In article <3637@pt.cs.cmu.edu> agn@unh.cs.cmu.edu (Andreas Nowatzyk) writes: >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: > Summary of critisims - a) Produce poor code b) Produce large numbers of temporary variables c) They have a lot of restrictions (loops etc) d) Lack control of instansiation e) There is no reasonalble substitute for conditional compilation. Firstly, it seems points a) and b) are a fair critisism of the compilers that we have at present. I would just say, write a better compiler. Restrictions - There are some unfortunate restrictions, and there is no easy solution to this. But then again, I never could write recursive macros anyway so its no great loss to me. Lack of control of instansiation, I don't see where the problem could be. The whole point of inline functions is that they should be semantically identical to a function call. I'd be interested to see an example of this problem. There is a reasonable substitute for conditional compilation, its called modularisation. You write a system dependent file for each system, and then link the appropriate one to a file called "sys_depends.h". Simple, eh? What about if I want one of my functions to do this for system A and that for system B, you may ask. Simple, you write two functions, one for each system. This might require you to have something like SYS5= ... BSD= ... VMS= ... SYSDEPENDS = SYS5 in your makefile, and you have to edit a line of it - big deal! In fact with all these configure programs that seem to be distributed with sources these days, you probably wouldn't even have to do that. > -- Andreas Nowatzyk (DC5ZV) ==Fraser Orr ( Dept C.S., Univ. Glasgow, Glasgow, G12 8QQ, UK) UseNet: {uk}!cs.glasgow.ac.uk!orr JANET: orr@uk.ac.glasgow.cs ARPANet(preferred xAtlantic): orr%cs.glasgow.ac.uk@nss.cs.ucl.ac.uk