Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!sdd.hp.com!uakari.primate.wisc.edu!aplcen!uunet!munnari.oz.au!bunyip!brolga!uqcspe!batserver.cs.uq.oz.au!rhys From: rhys@batserver.cs.uq.oz.au (Rhys Weatherley) Newsgroups: comp.lang.c++ Subject: Re: Why use reference type over pointer type? Message-ID: <4677@uqcspe.cs.uq.oz.au> Date: 26 Aug 90 06:41:59 GMT Sender: news@uqcspe.cs.uq.oz.au Reply-To: rhys@batserver.cs.uq.oz.au Distribution: comp Lines: 60 sakkinen@tukki.jyu.fi (Markku Sakkinen) writes: >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: >> >> ... [ description of how '&' in calls can tell you what's happening ] ... >> >>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. The problem is not that you have to look up the prototypes, but the mechanism for looking them up is very annoying. e.g. quit editor, start up broswer, quit browser, startup editor and figure out where the heck you were!! (or something like that :-). In actual fact it is probably a GOOD idea to look up the prototype of a function you haven't seen before just to make sure!! What is needed instead is a totally new way of looking at C and C++ programming using more integrated programming environments that by just clicking the mouse, or pressing a key, you can instantaneouly see the prototype and then go straight back to where you were. Some environments such as Turbo C/Turbo C++ already provide some facilites for this for their standard library routines, but this needs to be extended to programs you write as well. Some work is already been done around the world in this area, but they still haven't REALLY reached the mass market yet. So, environment writers, hop to it - us programmers need much better support at our end. >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. Unfortunately, it is probably very difficult to deal with this in environments :-(. Maybe the format argument could be inspected to try and determine whether the programmer has used correct types, but this does not cope with code like the following: char format[3]; int x; sprintf (format,"%%d"); scanf (format,x); So although environments will greatly help, there are still some warts! But they'd be better than what we are using now!! I would be very interested if anyone is doing some serious work in the C/C++ programming environment area, as would be many others in this newsgroup I expect. Rhys. +===============================+==============================+ || Rhys Weatherley | University of Queensland, || || rhys@batserver.cs.uq.oz.au | Australia. G'day!! || +===============================+==============================+