Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!brunix!sdm From: sdm@cs.brown.edu (Scott Meyers) Newsgroups: comp.lang.c++ Subject: Wrappers; Exception Handling Macros Message-ID: <29506@brunix.UUCP> Date: 16 Feb 90 05:22:13 GMT Sender: news@brunix.UUCP Reply-To: sdm@cs.brown.edu (Scott Meyers) Organization: Brown University Department of Computer Science Lines: 56 I have two questions for users of C++, one on wrappers, one on the exception handling macros in AT&T's : - Wrappers: In general, a wrapper function wf() for a function f() is a function that does some preprocessing, calls f, then does some postprocessing. That is, wf() usually looks something like this: returnType wf(params) { // do some preprocessing returnType result = f(params); // do some postprocessing return result; } g++ offers direct support for this idea (see "Function calls as first-class objects" in the User's Guide to GNU C++), cfront does not. I happen to be using cfront right now, and I've found a use for wrappers on more than one occasion. I'm curious to whether other people also use wrappers, and if so, how they implement them under cfront. What I do is make f a private function in a class, and make wf a public function. Users of a class then call wf, which in turn calls f. To indicate the relationship between wf and f, I choose a good name for wf (since it's in the public interface), then I give f the same name with an underbar appended. For example, the wrapper function evaluate() calls the function evaluate_(). This isn't exactly intuitive -- does someone know of a better way? - Exception handling: includes the following macros for doing exception handling, presumably in a manner similar to how the declare() and implement() macros in that file help one create pseudo-generic classes: extern genericerror(int,char*); typedef int (*GPT)(int,char*); #define set_handler(generic,type,x) name4(set_,type,generic,_handler)(x) #define errorhandler(generic,type) name3(type,generic,handler) #define callerror(generic,type,a,b) (*errorhandler(generic,type))(a,b) Dewhurst and Stark give an example of the use of the declare/implement macros, but not of the exception-handling macros. If somebody has an example of how these latter macros are supposed to be used, I'd really appreciate hearing about it. Thanks, Scott sdm@cs.brown.edu