home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18259 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  2.8 KB

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