home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!caen!zaphod.mps.ohio-state.edu!cs.utexas.edu!news
- From: wilson@cs.utexas.edu (Paul Wilson)
- Newsgroups: comp.lang.c++
- Subject: overload = for pointers? redefine pointer decl syntax?
- Date: 20 Dec 1992 15:21:02 -0600
- Organization: CS Dept, University of Texas at Austin
- Lines: 57
- Message-ID: <lj9otuINN7ll@boogie.cs.utexas.edu>
- NNTP-Posting-Host: boogie.cs.utexas.edu
-
- Are there any C++ compilers that let me define my own overloaded
- versions of (normally) builtin operations on builtin types? In
- particular, I'd very much like to be able to redefine the way
- operator = works on pointers, for garbage collection purposes.
- (And maybe redefine it for all primitive types, for checkpointing
- purposes.)
-
- Failing that, I have to define my own "smart" pointer classes,
- which runs into several problems, as has been discussed before.
- One problem is that I can't use the standard pointer declaration
- syntax, and therefore have to modify program sources that I'd
- otherwise be able to compile without change. Does any compiler
- support "overloading" declaration syntax in any way---that is,
- can I have a GC-able class foo and a GC-pointer class gcPtr<foo>,
- and set things up so that a declaration like
-
- foo *myfoo;
-
- is treated as though it were
-
- gcPtr<foo> myfoo;
-
- (NOTE: I do realize that this is not supported by standard C++,
- and it's a weird thing to do, but I'm a professional on a closed
- road, as it were. And when I redefine builtins, I intend to preserve
- their standard meanings while adding "extra-lingual" features to
- them, like garbage collection and checkpointing. I want to maintain
- compatibility with existing code as much as possible.)
-
- So the question is: does anybody make a C++ compiler that either
- allows me to redefine builtin operators on builtin types, or to
- extend the syntax of declarations?
-
- Anybody have an idea how hard each of those would be to hack into
- a compiler, say GNU C++? (It would seem to me that the machinery
- is likely to be mostly there already, for the purposes of getting
- the semantics of inline procedures right. Maybe the same bookkeeping
- could support more general lexically-scoped macros.)
-
- This sort of stuff is trivial in CLOS. Are there technical
- reasons it's difficult for C++? (I assume it would require
- a funkier compiler to support mutable declaration syntax in
- a language with nontrivial syntax, but redefining builtin
- operations doesn't seem hard at all. Then again, I'm not
- a compiler guy and may underestimate the difficulties.)
-
- Any pointers to useful info or software would be appreciated.
-
- Thanks,
-
- Paul
-
- --
- | Paul R. Wilson, Computer Sciences Dept., University of Texas at Austin |
- | Taylor Hall 2.124, Austin, TX 78712-1188 wilson@cs.utexas.edu |
- | (Recent papers on garbage collection, memory hierarchies, and persistence |
- | are available via anonymous ftp from cs.utexas.edu, in pub/garbage.) |
-