Topic: References in C++
Author: schuenem@Informatik.TU-Muenchen.DE (Ulf Schuenemann)
Date: 2 Mar 1995 17:55:31 GMT Raw View
In article <3ikf08$2pf@pheidippides.axion.bt.co.uk>, John Reah <reahj@mlb371.btlabsmh.bt.co.uk> writes:
[..]
|> The pass-by-value approach is slightly more efficient in an
|> environment where integers are smaller than pointers. You
|> can also manipulate the by-value argument as a local variable
|> in the called function if you don't declare it const (I can't
|> see the benefit in declaring a by-val integer as const).
Constness of value-parameters is a matter of implementation
(e.g. you can't overload on it). For some implementations it might
be important to not accidentially modify a parameter, as its
original value is still needed.
|> Whether these issues are important from a style/consistency point
|> of view is of course up to you.
|>
Ulf Schuenemann
--------------------------------------------------------------------
Ulf Sch nemann
Institut f r Informatik, Technische Universit t M nchen.
email: schuenem@informatik.tu-muenchen.de
Author: stidev@gate.net (Solution Technology)
Date: 2 Mar 1995 18:58:22 GMT Raw View
P Billington (paulfwb@festival.ed.ac.uk) wrote:
: Can anyone tell me weather there are any particular benefits
: in using const referecnce over copy const parameters for simple types.
if the object is big, it doesn't need to be copied.
void P( const someBigThing& x ) as opposed to void P( someBigThing x );
which would require copying it.
Ken Walter
Author: paulfwb@festival.ed.ac.uk (P Billington)
Date: Thu, 23 Feb 1995 09:41:29 GMT Raw View
Hello,
Can anyone tell me weather there are any particular benefits
in using const referecnce over copy const parameters for simple types.
eg. x(const int &val) or x(const int val)
My thoughts, at the present time, are that the former leads to more
consistent code and the latter is an obselete C form maybe loved by C
programmers but with no future.
I would be most interested to know anyones ideas or
references to texts on this subject.
Many Thanks,
Paul
--
******************************************************************************
* Department of Computer Science
* From: Paul Billington E-Mail paulfwb@festival.ed.ac.uk
*
Author: jason@cygnus.com (Jason Merrill)
Date: Fri, 24 Feb 1995 07:23:47 GMT Raw View
>>>>> P Billington <paulfwb@festival.ed.ac.uk> writes:
> Can anyone tell me weather there are any particular benefits
> in using const referecnce over copy const parameters for simple types.
None. Using pass-by-value will tend to get better performance for types
that fit nicely in a register, as the compiler doesn't have to worry about
aliasing.
Jason
Author: John Reah <reahj@mlb371.btlabsmh.bt.co.uk>
Date: 24 Feb 1995 11:13:12 GMT Raw View
> Can anyone tell me weather there are any particular benefits
> in using const referecnce over copy const parameters for simple types.
>
> eg. x(const int &val) or x(const int val)
>
> My thoughts, at the present time, are that the former leads to more
> consistent code and the latter is an obselete C form maybe loved by C
> programmers but with no future.
The pass-by-value approach is slightly more efficient in an
environment where integers are smaller than pointers. You
can also manipulate the by-value argument as a local variable
in the called function if you don't declare it const (I can't
see the benefit in declaring a by-val integer as const).
Whether these issues are important from a style/consistency point
of view is of course up to you.