skip to main content
article

Raw pointers in application classes of C++ considered harmful

Published:01 April 2007Publication History
Skip Abstract Section

Abstract

In order to achieve good reliability, clarity, scalability and re-usability of the application high-level programs written in C++ the raw pointers should not be used as class members (fields), because the raw pointers are too dangerous in this role and they do not represent meaningful relations between objects. Instead of raw pointers two smart pointers should be used. The first one describes exclusive unique ownership with synchronization of objects copying and deletion. The second one describes inclusive references to independent alien objects with invalidating the reference at the deletion of the addressed object. All power of object-oriented programming is preserved, but difficulties and errors are eliminated.

References

  1. E. W. Dijkstra, Go to statement considered harmful. Communications of the ACM 1968; 11(3): 147--148. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. D. B. Lomet, Making Pointers Safe in System Programming Languages. IEEE Transactions on Software Engineering 1985; SE-11(1): 87--96.Google ScholarGoogle Scholar
  3. B. T. Denvir, On Orthogonality in Programming Languages. ACM SIGPLAN Notices, 1979, 14(7): 18--30. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. B. Stroustrup, The C++ Programming Language. (Special ed.), Addison-Wesley, 2000. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. J. R. Ellis and D. L. Detlefs, Safe, efficient garbage collection for C++. In USENIX Sixth C++ Technical Conference, 1994. http://www.usenix.org/publications/library/proceedings/c++94/full_papers/ellis_a'. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. D. L. Heine and M. S. Lam, A Practical Flow-Sensitive and Context-Sensitive C and C++ Memory Leak Detector. Proceedings of the ACM SIGPLAN 2003 Conference on Programming Language Design and Implementation (PLDF'03), June 9-11, 2003, San Diego, California, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. F. V. Tkachov, Programming education: a Russian perspective. In Modular Programming Languages. Lecture Notes in Computer Science, Springer-Verlag, 2003, 2789: 69--77.Google ScholarGoogle Scholar
  8. J. Hogg, D. Lea, R. Holt, A. Wills, D. deChampeaux, The Geneva Convention On The Treatment of Object Aliasing. OOPS Messenger, April 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. N. H. Minsky, Towards Alias-Free Pointers. Proc. 10-th European Conf. Object-Oriented Programming, Springer-Verlag, 1996, 189--209. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. P. S. Almeida, Balloon Types: Controlling Sharing of State in Data Types. In ECOOP'97 --- Object Oriented Programming, II European Conf. Lecture Notes in Computer Science 1997; 1241: 32--59. Springer.Google ScholarGoogle Scholar
  11. D. G. Clarke, J. M. Potter and J. Nobble, Ownership Types for Flexible Alias Protection. In ACM Conf. on Object-Oriented Programming Systems, Languages and Applications (OOPSLA'98), Vancouver, Canada, October 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. J. Noble, J. Vitek and J. Potter, Flexible Alias Protection. ECOOP'98, Lecture Notes in Computer Science, Springer-Verlag, 1998; 1445: 158--185. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. J. Boyland, Alias burying: Unique variables without desctructive reads. Software --- Practice and Experience 2001; 31: 533--553. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. M. Barnett and D. A. Naumann, Friends Need a Bit More: Maintaining Inveriants Over Shared State. In Mathematics of Program Construction, Lecture Notes in Computer Science, Springer, July 2004.Google ScholarGoogle ScholarCross RefCross Ref
  15. A. Banerjee and D. Naumann, Ownership: transfer, sharing, and encapsulation, In ECOOP Workshop on Formal Techniques for Java-like Programs (FTfJP), July 2003.Google ScholarGoogle Scholar
  16. S. Meyers, More Effective C++. Addison-Wesley, 1996.Google ScholarGoogle Scholar
  17. J. J. Barton and L. R. Nackman, Scientific and Engineering C++. Addison-Wesley, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. G. Colvin, B. Dawes, P. Dimov, D. Adler, et al., The boost web site, smart pointers. 1999-2004. www.boost.org/libs/smart_ptr/smart_ptr.htm'.Google ScholarGoogle Scholar
  19. B. Milewski, Resource management in C++. Journal of Object Oriented Programming 1997; 10(1): 14--22.Google ScholarGoogle Scholar
  20. D. Lea, The GNU C++ Library, C++ Report, June 1993, revised as http://gee.cs.oswego.edu/dl/libg++paper/libg++/libg++.html, 1995.Google ScholarGoogle Scholar
  21. A. J. H. Simons, Borrow, Copy or Steal? Loans and Larceny in the Orthodox Canonical Form. ACM SIGPLAN Notices, Proceedings of the 13th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications (OOPSLA '98) 1998; 33(10): 65--83. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. A. Alexandrescu, Modern C++ Design: Generic Programming and Design Patterns Applied. Addison-Wesley, 2001, See chapter at http://www.informit.com. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. I. B. Smirnov, Likelihoodlib --- fitting, function maximization, and numerical analysis. PNPI Preprint 2001; 2421. http://cdsweb.cern.ch/.Google ScholarGoogle Scholar
  24. D. Lomet, Scheme for invalidating references to freed storage. IBM J. Res. Develop. 1975; 19(Jan): 26--35.Google ScholarGoogle Scholar
  25. A. Savidis, The implementation of generic smart pointers for advanced defensive programming. Software-Practice and Experience 2004; 34: 977--1009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. D. Litman, P. F. Patel-Schneider, A. Mishra, J. Crawford, and D. Dvorak, R++: Adding Path-Based Rules to C++. IEEE Transactions on Knowledge and Data Engineering 2002, 14: 638--658. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. I. B. Smirnov, http://cern.ch/ismirnov/safetl, 2005-2007.Google ScholarGoogle Scholar
  28. G. Booch Object-Oriented Analysis and Design with Applications. Addison-Wesley, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. I. B. Smirnov, Modeling of ionization produced by fast charged particles in gases. Nuclear Instruments and Methods in Physics Research A 2005; 554: 474--493.Google ScholarGoogle Scholar
  30. I. B. Smirnov, http://cern.ch/ismirnov/heed, 2005.Google ScholarGoogle Scholar
  31. I. B. Smirnov, Track reconstruction for forward spectrometer of SPES4-π experiment. PNPI Preprint 2000; 2345, http://cdsweb.cern.ch/, http://cern.ch/ismirnov/track.Google ScholarGoogle Scholar
  32. G. D. Alkhazov, V. V. Astashin, A. G. Atamanchuk, et al., SPES4-π: installation for exclusive study of nuclear reactions. Nuclear Instruments and Methods in Physics Research A 2005; 551: 290--311.Google ScholarGoogle Scholar

Index Terms

  1. Raw pointers in application classes of C++ considered harmful

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in

          Full Access

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader
          About Cookies On This Site

          We use cookies to ensure that we give you the best experience on our website.

          Learn more

          Got it!