home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / g / lib / bug / 809 < prev    next >
Encoding:
Text File  |  1993-01-28  |  2.2 KB  |  81 lines

  1. Path: sparky!uunet!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!cygnus.com!brendan
  2. From: brendan@cygnus.com (Brendan Kehoe)
  3. Newsgroups: gnu.g++.lib.bug
  4. Subject: [djb@babypuss.mitre.org : ]
  5. Date: 26 Jan 1993 22:25:34 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 67
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-lib-g++@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <9301262333.AA29619@cygnus.com>
  12. Reply-To: brendan@cygnus.com (Brendan Kehoe)
  13.  
  14. ------- Start of forwarded message -------
  15. From: djb@babypuss.mitre.org (David J. Braunegg)
  16. To: bug-g++@prep.ai.mit.edu
  17. Cc: djb@babypuss.mitre.org
  18. Date: Fri, 22 Jan 93 17:29:04 -0500
  19.  
  20. This is a bug report for g++ (gcc) version 2.3.3, running on a Sun
  21. Sparcstation, OS 4.1.
  22.  
  23.  
  24. Your declaration of
  25.  
  26.         ostream& operator<<(void *p);
  27.  
  28. in iostream.h is in error.  Unless you have truly defined operator<<
  29. on void* pointers so that it modifies the pointer, the declaration
  30. should instead be
  31.  
  32.         ostream& operator<<(const void *p);
  33.  
  34.  
  35.  
  36. For example, the following program should *not* issue the const
  37. violation warning that it does.
  38.  
  39.  
  40.  
  41. #include <iostream.h>
  42.  
  43. int main()
  44. {
  45.   const char *foo = "stuff";
  46.  
  47.   cout << (const void *)foo << endl;
  48.  
  49.   return 0;
  50. }
  51.  
  52.  
  53.  
  54.  
  55. djb@bambam>g++ -g -Wall test.cc
  56. test.cc: In function `int  main ()':
  57. test.cc:7: warning: argument passing of non-`const *' pointer from `const *'
  58. test.cc:7: warning: argument passing of non-`const *' pointer from `const *'
  59.  
  60.  
  61.  
  62. I have encountered this warning frequently, because in my code I am
  63. often writing out the address of an object to help identify it.  If
  64. foo is `const <class> *', then I must cast it to `const void *' and
  65. *not* to `void *' when printing its address in order to avoid a const
  66. violation.
  67.  
  68.  
  69. Please contact me if you have any further questions.
  70.  
  71. Dave
  72.  
  73. ------- End of forwarded message -------
  74.  
  75. --
  76. Brendan Kehoe                                               brendan@cygnus.com
  77. Cygnus Support, Mountain View, CA                              +1 415 903 1400
  78.                      ``In a cruel and imperfect world,'' says critic Rex Reed,
  79.  ``[Audrey Hepburn] was living proof that God could still create perfection.''
  80.  
  81.