 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
christopher diggins Guest
|
Posted: Mon Apr 11, 2005 11:23 pm Post subject: separation of pointer types |
|
|
What is currently referred to as a pointer in C++ is in my opinion several
different types inappropriately amalgamated as one. Consider how there are
four very clear categories of pointers with entirely different interfaces:
1) the result of an address-of operation
- supports indirection
- supports comparison
- increment/decrement undefined
- delete undefined
- delete[] undefined
2) reference to an element of an array
- supports indirection
- supports comparison
- supports increment/decrement
- delete undefined
- delete[] undefined
3) reference to a dynamically allocated array
- supports indirection
- supports comparison
- supports delete[]
- delete undefined
4) reference to a dynamically allocated object
- supports indirection
- supports comparison
- delete[] undefined
- supports delete
I see no reason these four cases should not each have a separate type. Does
anyone else find the the hypothetical idea of separation of pointers into
different types to have some allure?
--
Christopher Diggins
Object Oriented Template Library (OOTL)
http://www.ootl.org
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Andrew Koenig Guest
|
Posted: Wed Apr 13, 2005 5:53 am Post subject: Re: separation of pointer types |
|
|
""christopher diggins"" <cdiggins (AT) videotron (DOT) ca> wrote
| Quote: | I see no reason these four cases should not each have a separate type.
Does
anyone else find the the hypothetical idea of separation of pointers into
different types to have some allure?
|
Does that mean that whenever I write a function that takes a pointer
argument, and that function does only things with the pointer that all four
of your desired categories support, that I must overload the function for
each category anyway?
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
christopher diggins Guest
|
Posted: Thu Apr 14, 2005 5:07 am Post subject: Re: separation of pointer types |
|
|
""Andrew Koenig"" <ark (AT) acm (DOT) org> wrote
| Quote: | ""christopher diggins"" <cdiggins (AT) videotron (DOT) ca> wrote in message
news:xiy6e.58852$wl6.549361 (AT) weber (DOT) videotron.net...
I see no reason these four cases should not each have a separate type.
Does
anyone else find the the hypothetical idea of separation of pointers into
different types to have some allure?
Does that mean that whenever I write a function that takes a pointer
argument, and that function does only things with the pointer that all
four of your desired categories support, that I must overload the function
for each category anyway?
|
All four categories overlap only with regards to indirection. This means
that the appropirate type would be a reference.
--
Christopher Diggins
Object Oriented Template Library (OOTL)
http://www.ootl.org
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Marc Schoolderman Guest
|
Posted: Fri Apr 15, 2005 4:46 am Post subject: Re: separation of pointer types |
|
|
christopher diggins wrote:
| Quote: | All four categories overlap only with regards to indirection. This means
that the appropirate type would be a reference.
|
No. As was debated over and over in a recent thread, a reference can't
be "null", whereas a pointer can. Also, a pointer can be changed inside
the function, whereas a reference can't. So this isn't equivalent.
A more fundamental problem has to do with the low-level nature of
pointers. IMHO, they're not supposed to be some "pure" error-proof
language construct for the things you're suggesting, they're "just above
the machine level" abstractions for addresses, and the things you use
addresses for in machine language. Having four different pointer types
for the same low-level construct would be extremely confusing.
~Marc
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Fri Apr 15, 2005 4:47 am Post subject: Re: separation of pointer types |
|
|
christopher diggins wrote:
| Quote: | ""Andrew Koenig"" <ark (AT) acm (DOT) org> wrote in message
news:G9Q6e.564825$w62.517033 (AT) bgtnsc05-news (DOT) ops.worldnet.att.net...
""christopher diggins"" <cdiggins (AT) videotron (DOT) ca> wrote in message
news:xiy6e.58852$wl6.549361 (AT) weber (DOT) videotron.net...
I see no reason these four cases should not each have a separate type.
Does
anyone else find the the hypothetical idea of separation of pointers into
different types to have some allure?
Does that mean that whenever I write a function that takes a pointer
argument, and that function does only things with the pointer that all
four of your desired categories support, that I must overload the function
for each category anyway?
All four categories overlap only with regards to indirection. This means
that the appropirate type would be a reference.
|
I don't see how this could coexist with a notion of 'null pointer value'
(a pointer that is valid yet does not point to any object).
V
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
kuyper@wizard.net Guest
|
Posted: Fri Apr 15, 2005 4:50 am Post subject: Re: separation of pointer types |
|
|
"christopher diggins" wrote:
..
| Quote: | All four categories overlap only with regards to indirection. This
means
that the appropirate type would be a reference.
|
All four type support indirection, comparison, and increment.
References only support indirection.
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
christopher diggins Guest
|
Posted: Sat Apr 16, 2005 10:30 pm Post subject: Re: separation of pointer types |
|
|
"Marc Schoolderman" <squell (AT) alumina (DOT) nl> wrote
| Quote: | christopher diggins wrote:
All four categories overlap only with regards to indirection. This means
that the appropirate type would be a reference.
No. As was debated over and over in a recent thread, a reference can't be
"null", whereas a pointer can.
|
You are correct. All four categories do support comparison to null.
| Quote: | Also, a pointer can be changed inside the function, whereas a reference
can't.
|
You are correct here as well.
| Quote: | So this isn't equivalent.
|
I stand corrected.
In the end, though I still stand by my thesis that four separate pointer
classes can and probably should be used to replace the four different
categories of usage of regular pointers in most applications.
| Quote: | A more fundamental problem has to do with the low-level nature of
pointers. IMHO, they're not supposed to be some "pure" error-proof
language construct for the things you're suggesting, they're "just above
the machine level" abstractions for addresses,
|
Exactly! My point is programmers far too frequently just use pointers when
something more abstract would be more appropriate.
| Quote: | and the things you use addresses for in machine language. Having four
different pointer types for the same low-level construct would be
extremely confusing.
|
So we agree using pointers is neccessary when we need the low-level
construct. I am simply saying that in most applications it is more
appropriate to use a more accurate abstraction instead.
Christopher
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
Bob Bell Guest
|
Posted: Tue Apr 19, 2005 12:32 am Post subject: Re: separation of pointer types |
|
|
"christopher diggins" wrote:
| Quote: | "Marc Schoolderman" <squell (AT) alumina (DOT) nl> wrote in message
news:425E6DE0.7050206 (AT) alumina (DOT) nl...
So this isn't equivalent.
I stand corrected.
In the end, though I still stand by my thesis that four separate
pointer
classes can and probably should be used to replace the four different
categories of usage of regular pointers in most applications.
|
So what about Andrew's question: do I need to overload functions four
times four the four kinds of pointers?
Bob
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|