[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Vector new bug ??
From: |
Günter Neiß |
Subject: |
Re: Vector new bug ?? |
Date: |
Thu, 11 Oct 2001 14:45:12 +0200 |
André Pönitz schrieb:
Thank's for Your answer.
> Günter Neiß <address@hidden> wrote:
> > I found the following bug:
> >
> > Using some templates that uses:
> >
> > template<class T>
> > ....
> > t * p = new T[ size ];
> >
> >
> > Everything works fine, as long as 'size' isn't 0.
>
> Which version of g++ is that?
>
> It seems to work in 2.95.2
That's the Version I am using...
.. and it doesn't work :-(((
> > if( size == 0 )
> > p = NULL;
> > else
> > p = new T[ size ];
> > ...
> >
> > But I assume that this behaviour should already implemented inside
> > (vector) new !
>
> Note that there is a difference between an array of zero items and a null
> pointer.
.... it depends :-))
assuming: T = char
char * p = new char [ size ];
.. is really/nearly the same as
char * p = (char*)malloc( size );
and this should be NULL in case of size==0...
But, ofcourse if new will return a seperate unique value, that's even
more sophisticated than returning NULL.
> > I am not shure what the C++ standard says to this, but if it don't
> > specify it, I assume returning NULL should be the default behaviour in
> > this case ( as malloc( 0 ) does ).
>
> Your assumption is wrong. From CD2 (similar wording in Final under 5.3.4.7)
>
> 5.3.4
> 8 When the value of the expression in a direct-new-declarator is zero,
> the allocation function is called to allocate an array with no ele-
> ments. The pointer returned by the new-expression is non-null and
> distinct from the pointer to any other object.
As stated above that's good, but isn't the case in my environment.
I got an exception instead.
BTW.: What's the meaning of 'direct-new-declarator' ??
Is vector-new meant here ?
> Andre'
>
> PS:
>
> > application/x-pkcs7-signature; name="smime.p7s"
> > Content-Transfer-Encoding: base64 Content-Disposition: attachment;
> > filename="smime.p7s" Content-Description: Kryptographische Unterschrift
> > mit S/MIME
>
> [Is this really necessary?]
Sorry, I forgot to disable signing for this forum
> André Pönitz .............................................. address@hidden
But this is (nearly) the same :-)))
Günter