C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

separation of pointer types

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
christopher diggins
Guest





PostPosted: Mon Apr 11, 2005 5:57 pm    Post subject: separation of pointer types Reply with quote



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
Thomas Maeder
Guest





PostPosted: Tue Apr 12, 2005 9:49 am    Post subject: Re: separation of pointer types Reply with quote



[email]cdiggins (AT) videotron (DOT) ca[/email] ("christopher diggins") writes:

Quote:
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.

Backward compatibility is a very strong reason.


Quote:
Does anyone else find the the hypothetical idea of separation of
pointers into different types to have some allure?

Yes. Which is why we have a plethora of smart pointer and container
types that take care of cases 3) and 4).


The difference between 1) and 2) is blurry, by the way:

void f(int &i)
{
some_pointer_type pi(&i);
}

int main()
{
int i(0);
f(i);

int is[2] = { 0 };
f(is[1]);
}

---
[ 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
John Nagle
Guest





PostPosted: Tue Apr 12, 2005 9:50 am    Post subject: Re: separation of pointer types Reply with quote



christopher diggins wrote:
Quote:
What is currently referred to as a pointer in C++ is in my opinion several
different types inappropriately amalgamated as one.

I tend to agree, but it's one of those things that's too late
to fix in this language.

C++ has the needed concepts: arrays,
iterators, and references. But they're all convertable
to and from pointers, and most programmers don't see them
as distinct.

The array-as-pointer thing and the concept of pointer
arithmetic are there mostly because they mapped well to
PDP-11 hardware. Nobody has put that in a new language
in a long time.

John Nagle
Animats

---
[ 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





PostPosted: Wed Apr 13, 2005 6:52 am    Post subject: Re: separation of pointer types Reply with quote

christopher diggins wrote:
Quote:
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

Incorrect; increment is allowed, decrement isn't.

Quote:
- delete undefined
- delete[] undefined

2) reference to an element of an array
- supports indirection
- supports comparison
- supports increment/decrement

Decrement is not allowed for a pointer to the first element of an
array.

Quote:
- delete undefined
- delete[] undefined

3) reference to a dynamically allocated array
- supports indirection
- supports comparison

You left out:
- supports increment

Quote:
- supports delete[]
- delete undefined

4) reference to a dynamically allocated object
- supports indirection
- supports comparison

You left out:
- supports increment

Quote:
- delete[] undefined
- supports delete

Notice: the (corrected) differences with regard to increment and
decrement are all covered by one principle: a pointer to a single
object is treated as a pointer to the only element of a 1-element
array. It's never legal to decrement a pointer to the first element of
an array. It's always legal to increment a pointer to an element of an
array.

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?

You'll have to identify the advantages. I don't see any.

---
[ 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
Dave Thompson
Guest





PostPosted: Mon Apr 18, 2005 5:49 pm    Post subject: Re: separation of pointer types Reply with quote

On Tue, 12 Apr 2005 09:50:32 GMT, [email]nagle (AT) animats (DOT) com[/email] (John Nagle)
wrote:
<snip>
Quote:
The array-as-pointer thing and the concept of pointer
arithmetic are there mostly because they mapped well to
PDP-11 hardware. Nobody has put that in a new language
in a long time.

Actually they mapped better onto the word machines where BCPL was

first implemented, like PDP-10 and I think 709x. AIUI it was actually
the PDP-11's need for differing strides that drove _reintroduction_ of
types into C over B, but without dropping pointer arithmetic which has
since been such an opportunity for, ahem, infelicities.

Have there been any new SILs, but Oberon by Wirth who always goes for
safe? The entire category seems to have fallen out of favor.

- David.Thompson1 at worldnet.att.net

---
[ 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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.