Article View: comp.std.c++
Article #3066Re: STL experts, please comment
From: Joe Buck
Date: Mon, 22 Jan 1996 21:52
Date: Mon, 22 Jan 1996 21:52
47 lines
2783 bytes
2783 bytes
David Byrden <100101.2547@compuserve.com> writes:
>In the HP STL, deque::iterator has a default ctor which initialises
>several of its members with the value 0
>
> iterator() : current(0), first(0), last(0), node(0) {}
Checking the code, this initialization to 0 is evidently not used
anywhere. However, if the members are not initialized at all, tools
like Purify may complain about uninitialized memory reads. Perhaps
this is why it's there. The problem is the "default constructor"
for pointers doesn't do anything; it leaves the pointer with a random
value.
Almost seems like what you'd really want for STL is a template for
initializing iterators that would be specialized for pointers; pointers
would be initialized to zero; other class types would just get initialized
by their default constructor (this would need partial specialization, I
think). But that would in effect create an implicit NIL for all iterators
(well, we could always argue about that question again). But maybe a NIL
is only needed for allocator pointers and not iterators in general.
>These members have the type deque::pointer, which is a typedef
>for the pointer in deque's allocator.
>An allocator pointer, according to the standard, has exactly the same
>semantics as a random access iterator.
So you're trying to create an allocator that is not based on pointers.
>I can find no place where it says that all random access iterators
>should be constructable from the int value zero, neither in
>documentation from the time of the HP STL, nor the latest draft standard.
Correct.
>So, this ctor seems to break the rules. Yet it was written by the
>inventors of STL.
Well, they goofed, I suppose. Seems the types of allocators they used
were all pointers, so they didn't test out other cases.
--
-- Joe Buck <jbuck@synopsys.com> (not speaking for Synopsys, Inc)
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<4e1034$5ar@hermes.synopsys.com>Path:
arc1-ca.pugleaf.net!fido.asd.sgi.com!austernReferences:
<4dnteb$6fo@news.bridge.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern From: jbuck@Synopsys.COM (Joe Buck) Newsgroups: comp.std.c++ Subject: Re: STL experts, please comment Date: 22 Jan 1996 13:52:26 PST Organization: Synopsys Inc., Mountain View, CA 94043-4033 Approved: austern@isolde.mti.sgi.com Message-ID: <4e1034$5ar@hermes.synopsys.com> References: <4dnteb$6fo@news.bridge.net> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 22 Jan 1996 21:37:40 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMQQHK0y4NqrwXLNJAQH1RwH+PorMyPbKxU1d95lrC1weXzY6i6mKneIq JoEGbksEgXkpU/cyPXdES56N0XCCz4JPmX4P1B7FGCqNUUJMH+aojw== =9iaz Originator: austern@isolde.mti.sgi.com