[lug] new operator in C++

Stephen Queen svq at peakpeak.com
Sat Apr 27 15:59:35 MDT 2002


Tkil wrote:

> >>>>> "Tkil" == tkil  <tkil at scrye.com> writes:
>
> Tkil> i think i got it right this time.  the bit i cited in the
> Tkil> previous message had to do with static initialization; both
> Tkil> automatic and dynamic initializations have the above rules (that
> Tkil> is, "if there are no initializers, then it's indeterminate").
>
> to wit:
>
> | #include <iostream>
> | using std::cout;
> | using std::endl;
> |
> | int main( int argc, char * argv [] )
> | {
> |     for (int i = 0; i < 100 ; ++i)
> |     {
> |         int * pi = new int;
> |         ++(*pi);
> |         cout << *pi << endl;
> |         delete pi;
> |     }
> |     return 0;
> | }
>
> gives this output:
>
> | $ ./test-new
> | 1
> | 1075981201
> | [...]
> | 1075981201
> | 1075981201
> | 1075981201
> | $
>
> which surprises me a little -- i had hoped for something more
> consistent -- but shows that you do not get the zero initialization
> that you asked for.
>
> t.
>
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug

Thanks, that is what I was looking for. That was a nice experiment you
designed.




More information about the LUG mailing list