Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!umich!samsung!sol.ctr.columbia.edu!emory!hubcap!ncrcae!PEDEV!rogerson From: rogerson@PEDEV.Columbia.NCR.COM (Dale Rogerson) Newsgroups: comp.lang.c++ Subject: Re: Passing by reference (was Re: C++ coding standards (Comment needed)) Keywords: standard,variables Message-ID: <3233@PEDEV.Columbia.NCR.COM> Date: 23 Aug 90 19:56:13 GMT References: <2161@runxtsa.runx.oz.au> <183@logo.procase.UUCP> <15361@reed.UUCP> Reply-To: rogerson@PEDEV.Columbia.NCR.COM (Dale Rogerson) Organization: NCR Corp., Engineering & Manufacturing - Columbia, SC Lines: 43 In article <15361@reed.UUCP> minar@reed.bitnet (Nelson Minar) writes: >However, I find it really nice to know in C that 'hey, in this function call >that variable is passed by value. The function can't be changing the value >of that variable, and thus the bug is elsewhere.' Its useful when debugging >other's arcane code. >In C++, this information is not available merely from the function call. >Who knows if > int a = 0; > foo(a); >will change the value of a or not in C++, without finding the prototype for >the function and looking carefully. >Is there any sort of nice convention to make this easier to deal with? I assume >not. Modula-2 (and Pascal) have always had passing by reference just specify the parameter as VAR (i.e. foo( VAR a ) ). I have never found this to be a problem in Modula-2. However, Modula-2 has a very well defined idea of a module. Each module must have a Definition file and an Implementation file. It is really easy to find out which file a function call is in and a quick look at the Definition file will tell you what it modifies. It is very quick and painless. I have never been bitten by this, but I have been bitten by the missing & operator in C. If you have well chosen filenames and classnames and provide good header files this should not be too bad in C++. Remember that most(?) function calls will probably be through a class pointer so finding the class should be easy. A nice solution would be to adopt the Modula-2 idea of Definition and Implementation files which would cure many of the header file problems. However, most C programmers are already accepting a suprising amount of Modula-2 ideas so I probably better not push my luck. :-) The best solution is probably to get a good code browser which would get you the function prototype at the press of a key. This requires no changes to the language definition. It might require coding practice changes. None of these solutions will help for arcane code. -----Dale Rogerson-----