[lug] new operator in C++
Tkil
tkil at scrye.com
Sat Apr 27 15:34:44 MDT 2002
>>>>> "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.
More information about the LUG
mailing list