Path: utzoo!attcan!uunet!lll-winken!sol.ctr.columbia.edu!ira.uka.de!rusux1!jellosub.luftfahrt.uni-stuttgart.de!schmid From: schmid@jellosub.luftfahrt.uni-stuttgart.de (Georg Schmid) Newsgroups: comp.lang.c++ Subject: this in Heap-/Stack Objects Message-ID: <1990Oct9.162831@jellosub.luftfahrt.uni-stuttgart.de> Date: 9 Oct 90 15:28:31 GMT Sender: zrf80385@rusux1.rus.uni-stuttgart.de Reply-To: schmid@jellosub.luftfahrt.uni-stuttgart.de (Georg Schmid) Organization: Dept. for Statics & Dynamics of Aerospace Structures (ISD) Lines: 51 Just a simple question: One of my c++ books (Bruce Eckel, Using C++) states that one can determine the type (heap- or stack-based) of an instance at runtime by looking at 'this' in the constructor: "... code is secretly generated in a constructor to differ- entiate between objects created on the stack (the value of 'this' when the constructor is called is non-zero) and objects created on the free store (the value of 'this' when the con- structor is called is zero)..." I tested this with the following little program on an Apollo with Apollos (Glockenspiel) C++ 1.2.2: #include class Something { public: Something(); }; Something::Something() { printf("This is %lX\n", this); } int main(int, char**) { Something a; Something* b = new Something; } The output is: This is 3B3C7556 This is 10C00 Am I wrong, is Eckel wrong or is the compiler wrong ? Any hints appreciated. -- georg ________________________________________________________________________ Georg Schmid, ISD University of Stuttgart, Germany email: schmid@asterix.luftfahrt.uni-stuttgart.de (129.69.110.2) voice: +49 711-685-2053 fax: +49 711-685-3706 ________________________________________________________________________