🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #319

Re: How does a reference differ from a const *const?

#319
From: Ron Guilmette
Date: Tue, 31 Jul 1990 21:37
53 lines
2261 bytes
In article <3679@husc6.harvard.edu> ngo@tammy.harvard.EDU (Thomas Ngo) writes:
>
>    How does a reference differ from a const pointer to a const
>    object (besides the obvious need to dereference the latter)?
>
>    I hope this question is in the spirit of this newsgroup.

As you note, the first difference is that references are implicitly
dereferenced (in almost all contexts - including sizeof).

Also, since you cannot change the value of a reference (once it has been
initialized) it seems that references are (in this respect) very much like
const pointers.

Note however that the referent object of a reference could be either
const or non-const, just as the referent of a pointer variable could be.

Some differences that come to mind are:

	1) Pointers to pointers are allowed. Pointers to references are not.

	2) References to pointers are allowed. References to references are not.

	3) Arrays of pointers are allowed.  Arrays of references are not.
	(At least the last time I asked Bjarne, he said that he put that
	in the language but then decided that it was a mistake and that
	it ought to be taken out again.)

	4) Given the declarations:

		extern int array[], func();

	and the function call:

		foobar (array, func);

	the following possible declarations for foobar() will "match":

		extern void foobar (int* const arg1, int (* const arg2)());

	it is not at all clear however (to me anyway) whether or not the
	following declaration would also "match" the call above:

		extern void foobar (int& arg1, int (& arg2)());

I'm sure that there are more, but I have forgotten them.


-- 
// Ron Guilmette
// C++ Entomologist
// Internet: rfg@ncd.com      uucp: ...uunet!lupine!rfg
// Motto:  If it sticks, force it.  If it breaks, it needed replacing anyway.
Technical Details
Message-ID: <1027@lupine.NCD.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!wuarchive!uunet!lupine!rfg
References: <3679@husc6.harvard.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!wuarchive!uunet!lupine!rfg
From: rfg@NCD.COM (Ron Guilmette)
Newsgroups: comp.std.c++
Subject: Re: How does a reference differ from a const *const?
Keywords: reference
Message-ID: <1027@lupine.NCD.COM>
Date: 31 Jul 90 21:37:24 GMT
References: <3679@husc6.harvard.edu>
Distribution: usa
Organization: Network Computing Devices, Inc., Mt. View, CA
Lines: 53