Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!uflorida!mephisto!prism!prism.gatech.EDU!gt3930b From: gt3930b@prism.gatech.EDU (NICHOLS,STEVEN MALCOLM) Newsgroups: comp.lang.c++ Subject: value of 'this' in constructor Message-ID: <12680@hydra.gatech.EDU> Date: 16 Aug 90 22:10:10 GMT Sender: gt3930b@prism.gatech.EDU Distribution: na Organization: Georgia Institute of Technology Lines: 50 Consider the following piece of code. From p. 284 of "Using C++", and also p. 164 of "The C++ Programming Language", I am lead to believe that the value of the pointer 'this', on entry to a constructor, will be 0 if the instance of the class has been dynamically allocated. If the class has been statically allocated, the value of 'this' will be non-zero. However, I see non-zero values for this for both static and dynamic instances of the class test in the code fragment that follows. I see this behavior for both ZORTECH v. 2.06 on a 386 based PC, and a similar output for the same code compiled using Oregon C++ on a VMS based DEC micro-vax. Since this is happening for *two* compilers, I conclude that I have misunderstood Eckel and Stroustrup when they described this feature. If the error is in my understanding, or is well known, please e-mail me at gt3930b@prism.gatech.edu; if it is a bona fide bug, or a non-trivial language issue, please post for others to read. // the code sample, set up for ZORTECH #include class test { test* this_on_entry; public: test() { this_on_entry = this; } void show() {cout << "this_on_entry = " << (unsigned)this_on_entry << "\n"; } }; main() { test static_test; test* dynam_test; dynam_test = new test; cout << "static:"; static_test.show(); cout << "dynamic:"; dynam_test->show(); } // the output from ZORTECH static:this_on_entry = 9128 dynamic:this_on_entry = 9170 thanks for the help, steve nichols. gt3930b@prism.gatech.edu