Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!spool.mu.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: cast of a bound pointer: why ? Message-ID: <764@taumet.com> Date: 13 Jun 91 16:53:09 GMT Article-I.D.: taumet.764 References: <1991Jun11.191016.9873@beaver.cs.washington.edu> <763@taumet.com> <1991Jun12.180414.16718@beaver.cs.washington.edu> Organization: Taumetric Corporation, San Diego Lines: 43 pauld@stowe.cs.washington.edu (Paul Barton-Davis) writes: >This is the heart of the matter. C++ assumes that EVERY function >*requires* a "this" pointer. If one is using C++ for "systems" >programming, there are a number of cases where this is not true. The >particular one I'm facing involves the use of a much lower level call >(via direct asm macros) to a function whose address is already known. >The stack and frame pointers are set up *by the C++ code itself* >before calling, and it knows exactly what to pass the function. First of all, only non-static class member functions have a "this" pointer. You can declare a static member function, or a friend function, or even an ordinary function which takes a parameter of class pointer type and achieve the same effect. For example, instead of this: class C { ... foo(int); }; use this: class C { ... friend foo(C*, int); }; Now you can take foo's address and call it as any ordinary function, which it is. This is appropriate when interfacing to low-level system calls, but not necessarily for high-level C++ programming. What you describe is very system-specific, and far from being portable to other systems, may not even survive the next release of the same C++ compiler on the same system. It is not appropriate, IMHO, to mix low-level assembler interface code with C++. If you have to do work in assembler, write that code in assembler, but give it a standard function interface so it can be called from C++. Then your C++ code remains portable. The non- portable bits are well-isolated in assembler files. You can also use C functions similarly. For example, function foo above coulde be declared extern "C" and do whatever you want. -- Steve Clamage, TauMetric Corp, steve@taumet.com