Topic: Why is "this" a pointer, not a reference? [was: NULL "this" pointers]
Author: scott douglass <sdouglass@arm.com>
Date: 2000/10/04 Raw View
Francis Glassborow wrote:
>In article <39D8DA5D.BD22D873@jps.net>, Dennis Yelle <dennis51@jps.net>
>writes
> >> Largely a matter of history. Actually if you look at it carefully you
> >> will find that this isn't really a pointer.
> >
> >OK. I give up. In what sense is "this" not a pointer?
>
>In the sense that it is more akin to a reference in semantics, though it
>has the syntax of a pointer.
Meaning, I think, that 'this' is never legally NULL.
Also 'this' is not an lvalue so '&this', is ill-formed and a 'T*&r = this;'
can't bind 'r' directly to 'this'.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: David R Tribble <david@tribble.com>
Date: 2000/10/05 Raw View
Niels Dekker <ndekker@REMOVETHISnki.nl> wrote:
>> Why hasn't C++ defined "this" to be a reference, instead of a
>> pointer?
Jim Hyslop wrote:
> I believe the D&E explains this. As I understand it, Stroustrup hadn't
> yet come up with references when he invented 'this'. By the time he
> invented references, changing the type of 'this' would be quite
> difficult.
I asked the same question in this NG several months ago, and got
essentially the same answer: history.
Of course, if you really want to, you can simulate a "this reference"
entity with (gasp!) a little preprocessor magic:
#define self (*this)
--
David R. Tribble, mailto:david@tribble.com, http://david.tribble.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Dennis Yelle <dennis51@jps.net>
Date: 2000/10/03 Raw View
Francis Glassborow wrote:
>
> In article <39D7501C.D5BEE0DC@REMOVETHISnki.nl>, Niels Dekker
> <ndekker@REMOVETHISnki.nl> writes
> >Why hasn't C++ defined "this" to be a reference, instead of a pointer?
> >
> Largely a matter of history. Actually if you look at it carefully you
> will find that this isn't really a pointer.
OK. I give up. In what sense is "this" not a pointer?
Dennis Yelle
--
I am a computer programmer and I am looking for a job.
There is a link to my resume here:
http://table.jps.net/~vert/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 2000/10/03 Raw View
In article <39D8DA5D.BD22D873@jps.net>, Dennis Yelle <dennis51@jps.net>
writes
>> Largely a matter of history. Actually if you look at it carefully you
>> will find that this isn't really a pointer.
>
>OK. I give up. In what sense is "this" not a pointer?
In the sense that it is more akin to a reference in semantics, though it
has the syntax of a pointer.
Francis Glassborow Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Marco Manfredini" <marquise2000@gmx.net>
Date: Wed, 4 Oct 2000 06:25:05 GMT Raw View
"Francis Glassborow" <francis.glassborow@ntlworld.com> wrote in message
news:PMbW$VAyTf25Ew9V@ntlworld.com...
> In article <39D8DA5D.BD22D873@jps.net>, Dennis Yelle <dennis51@jps.net>
> writes
> >> Largely a matter of history. Actually if you look at it carefully you
> >> will find that this isn't really a pointer.
> >
> >OK. I give up. In what sense is "this" not a pointer?
>
> In the sense that it is more akin to a reference in semantics, though it
> has the syntax of a pointer.
>
Example: The behaviour of the program is undefined, if -this- does not point
to an object of -this-type, similar to a reference, but unlike pointers
which may point to NULL.
Marco
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: alexo@bigfoot---filter---.com (Alex Oren)
Date: 2000/10/04 Raw View
On Tue, 3 Oct 2000 15:33:49 GMT, Francis Glassborow
<francis.glassborow@ntlworld.com> wrote:
} In article <39D8DA5D.BD22D873@jps.net>, Dennis Yelle <dennis51@jps.net>
} writes
} >> Largely a matter of history. Actually if you look at it carefully you
} >> will find that this isn't really a pointer.
} >
} >OK. I give up. In what sense is "this" not a pointer?
}
} In the sense that it is more akin to a reference in semantics, though it
} has the syntax of a pointer.
As far as I remember, 'this' was in C++ before references were part of the
language. After that, there was too much existing code to change the
behaviour.
Have fun,
Alex.
--
My email address is intentionally mangled to foil spambots.
Please remove the "---filter---" from the address for replying.
Sorry for the inconvenience.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
[ Note that the FAQ URL has changed! Please update your bookmarks. ]
Author: Niels Dekker <ndekker@REMOVETHISnki.nl>
Date: 2000/10/02 Raw View
Why hasn't C++ defined "this" to be a reference, instead of a pointer?
I'm just curious...
Thanks in advance,
Niels Dekker
ndekker "at" nki "dot" nl
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Jim Hyslop <jim.hyslop@leitch.com>
Date: 2000/10/02 Raw View
In article <39D7501C.D5BEE0DC@REMOVETHISnki.nl>,
Niels Dekker <ndekker@REMOVETHISnki.nl> wrote:
> Why hasn't C++ defined "this" to be a reference, instead of a pointer?
I believe the D&E explains this. As I understand it, Stroustrup hadn't
yet come up with references when he invented 'this'. By the time he
invented references, changing the type of 'this' would be quite
difficult.
--
Jim
This message was posted using plain text only. Any hyperlinks you may
see were added by other parties without my permission.
I do not endorse any products or services that may be hyperlinked to
this message.
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: 2000/10/02 Raw View
In article <39D7501C.D5BEE0DC@REMOVETHISnki.nl>, Niels Dekker
<ndekker@REMOVETHISnki.nl> writes
>Why hasn't C++ defined "this" to be a reference, instead of a pointer?
>
Largely a matter of history. Actually if you look at it carefully you
will find that this isn't really a pointer.
Francis Glassborow Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]