Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!oliveb!pyramid!voder!apple!kanner From: kanner@apple.UUCP Newsgroups: comp.lang.c++ Subject: Explanation desired Message-ID: <807@apple.UUCP> Date: Wed, 20-May-87 21:43:41 EDT Article-I.D.: apple.807 Posted: Wed May 20 21:43:41 1987 Date-Received: Sat, 23-May-87 01:18:34 EDT Organization: Apple Computer, Inc., Cupertino, USA Lines: 45 Keywords: virtual I have been very puzzled by some of the C code produced by cfront when declaring an object for a class that has virtual functions. Here is part of an example: C++ source: struct base{ virtual void f1(); virtual void f2(); virtual void f3(); }; struct d1 : base { virtual void f1(); virtual void f2(); }; struct d11 : d1 { virtual void f1(); virtual void f2(); }; d11 od11; ... Now the C code produced by "d1 od11;" follows; I have removed 17 levels of redundant parentheses, include 14 consecutive left-hand ones at the start, and I have simplified the identifier _au1_od11 to od11 for readability: (struct base *) (struct d1 *) &od11->_base__vptr = base__vtbl, (struct base *) (struct d1 *) &od11, (struct d1 *) &d11->_base__vptr = d1__vtbl, (struct d1 *) &od11; &od11->_base__vptr = d11__vtbl, // This line appears to be valid &od11; As far as I can tell, only the line I have commented appears to do anything correct and useful. Can anyone tell me what is going on? -- Herb Kanner Apple Computer, Inc. {idi, ios, nsc}!apple!kanner