q for the C hackers
Erik Price
eprice at ptc.com
Tue Aug 19 10:45:30 EDT 2003
Tom Fogal wrote:
>>I'm just interested in hearing about whether one is more appropriate
>>than the other in some contexts. Thanks.
>
>
> Generally, I would use #defines for anything but function parameters.
> Passing things as a constant reference (const type &val) is a good way to
> avoid passing a large value without the overhead of actual passing it.
I understand what you are saying, about passing a reference to something
rather than passing the thing itself. My understanding is that this is
because the value of a reference is a memory address, which is usually
smaller than say, some large value (please correct me if this is
incorrect). But why does it have to have "const" placed there? This
seems like it should prevent the value from being modified in the body
of the function somehow, but is it required or are you suggesting it as
good practice?
> Unfortunately, references do not exist in C alone (they were introduced in C++)
I seem to be confused about the difference between references and a
type's address. Are you saying that
&val
is a reference, and that this is different from the address of 'val'? I
thought that this meant "the address of 'val'".
Thanks everyone for contributing to this discussion.
Erik
More information about the gnhlug-discuss
mailing list