Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!wuarchive!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!tut!tukki.jyu.fi!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.lang.c++ Subject: Re: Why use reference type over pointer type? Message-ID: <1990Aug17.123626.8660@tukki.jyu.fi> Date: 7 Aug 90 07:24:33 GMT References: <1676@dinl.mmc.UUCP> <5720@darkstar.ucsc.edu> <21810@lute.com> Reply-To: sakkinen@jytko.jyu.fi (Markku Sakkinen) Organization: University of Jyvaskyla, Finland Lines: 39 Note2: Third trial to post! Note1: This is the second posting of an article that apparently disappeared while the news software was out of order here for three days. Sorry if somebody receives it twice. In article <21810@lute.com> frose@synoptics.COM (Flavio Rose) writes: >The beauty of the C way of doing call-by-reference is the >following: > >Suppose you are reading or debugging someone else's code (a >very common activity), and you come across a call > > foo(a,b,&c); > >and a, b, c are of scalar type. Then you can say >immediately, without bothering to look up foo's function >prototype anywhere, "aha, foo munges c but not a or b." >Often you don't care to know more about foo() than that, so >this saves time and doesn't make you interrupt your train >of thought to look up a prototype. Perhaps you should have stressed more that this is an argument _against_ using reference declarations in the function prototype. It is a good argument! However, there are also cases in which the C way is very dangerous. A prime example is the 'scanf' library function: anything may happen if you forget to write '&' before all appropriate arguments, and there is no possibility for compile-time checking because the function has a variable number of arguments. > ... Markku Sakkinen Department of Computer Science University of Jyvaskyla (a's with umlauts) Seminaarinkatu 15 SF-40100 Jyvaskyla (umlauts again) Finland SAKKINEN@FINJYU.bitnet (alternative network address)