Topic: proposal: pointers


Author: "Atle Slagsvold" <atleslag@online.no>
Date: Mon, 4 Feb 2002 16:35:37 GMT
Raw View
"John Nagle" <nagle@animats.com> skrev i melding
news:3C5ADFEE.3000104@animats.com...
>     I proposed something like this a few months back.
> Look in archives for "strict C++".  It's tough to do right
> without breaking existing programs.  And there didn't
> seem to be much enthusiasm for it.

My point is that the system would be added to C++.
This would not break existing programs.

> There
> are many "smart pointer" libraries, but they all
> have safety holes in them that can't be fixed within
> the existing C++ model.

I do not propose this to fix security in C++. My point is that
smart pointers are somthing many people use, and should
be standardised.

>      There's a garbage collection lobby, but that
> has its own problems.  All the usual GC problems
> apply, plus the interaction between GC and a language
> that uses destructors extensively is difficult.

The user should be able to choose what data should be garbagecollected.

>      The biggest single weakness of C++ is that
> program design has to obsess on who owns what, yet
> the language provides no help with the problem.

I agree and I think more pointertypes could help.


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





Author: "Atle Slagsvold" <atleslag@online.no>
Date: Thu, 31 Jan 2002 11:22:40 CST
Raw View
One area the next C++ standard should be stronger is pointers.
In the current standard std::auto_ptr and plain pointers are the
alternatives.
In the next standard there should be reference-counted pointers, and
possibly
garbage-collected pointers. To use these in an uniform way all the
pointerstypes should
be convertable to at least one common type. Mabe an hierarchy of pointers
are needed.
Somthing like this:

auto_ptr, refcnt_ptr(shared_ptr), grbcol_ptr and manual_ptr
converts to owning_ptr.

weak_ptr, plain pointer, owning_ptr
converts to ptr.

this will be used in this way:

void func(ptr<string> in)
{
    cout<<*in<<endl;
}

int main()
{
    func(new string("test"));
    auto_ptr<string> ap=new string("auto_ptr");
    func(ap);
    refcnt_ptr<string> rcp=new string("refcnt_ptr");
    func(rcp);
}

--
Atle Slagsvold - Software Development Engineer
THALES COMMUNICATIONS AS - http://www.thalesgroup.no
Phone: +47 22 63 83 00 - Direct: +47 22 63 81 46

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





Author: John Nagle <nagle@animats.com>
Date: Fri, 1 Feb 2002 19:24:10 GMT
Raw View
    I proposed something like this a few months back.
Look in archives for "strict C++".  It's tough to do right
without breaking existing programs.  And there didn't
seem to be much enthusiasm for it.

    My main suggestion was to go for reference counting,
strong and weak pointers on the Perl model (not the
Java model) and local temporary pointers which can't
outlive their objects for performance.  It's a
reasonable concept, but hard to retrofit.  There
are many "smart pointer" libraries, but they all
have safety holes in them that can't be fixed within
the existing C++ model.

     There's a garbage collection lobby, but that
has its own problems.  All the usual GC problems
apply, plus the interaction between GC and a language
that uses destructors extensively is difficult.

     The biggest single weakness of C++ is that
program design has to obsess on who owns what, yet
the language provides no help with the problem.

    John Nagle
    Animats

Atle Slagsvold wrote:

> One area the next C++ standard should be stronger is pointers.
> In the current standard std::auto_ptr and plain pointers are the
> alternatives.
> In the next standard there should be reference-counted pointers, and
> possibly
> garbage-collected pointers. To use these in an uniform way all the
> pointerstypes should
> be convertable to at least one common type. Mabe an hierarchy of pointers
> are needed.
> Somthing like this:
>
> auto_ptr, refcnt_ptr(shared_ptr), grbcol_ptr and manual_ptr
> converts to owning_ptr.
>
> weak_ptr, plain pointer, owning_ptr
> converts to ptr.
>
> this will be used in this way:
>
> void func(ptr<string> in)
> {
>     cout<<*in<<endl;
> }
>
> int main()
> {
>     func(new string("test"));
>     auto_ptr<string> ap=new string("auto_ptr");
>     func(ap);
>     refcnt_ptr<string> rcp=new string("refcnt_ptr");
>     func(rcp);
> }
>
> --
> Atle Slagsvold - Software Development Engineer
> THALES COMMUNICATIONS AS - http://www.thalesgroup.no
> Phone: +47 22 63 83 00 - Direct: +47 22 63 81 46
>
> ---
> [ 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                ]
>
>

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