home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / g / bug / 2317 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.6 KB  |  66 lines

  1. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!babypuss.mitre.org!djb
  2. From: djb@babypuss.mitre.org (David J. Braunegg)
  3. Newsgroups: gnu.g++.bug
  4. Subject: (none)
  5. Date: 22 Jan 1993 21:49:39 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 53
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-g++@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <9301222229.AA06362@bambam.mitre.org>
  12.  
  13. This is a bug report for g++ (gcc) version 2.3.3, running on a Sun
  14. Sparcstation, OS 4.1.
  15.  
  16.  
  17. Your declaration of
  18.  
  19.         ostream& operator<<(void *p);
  20.  
  21. in iostream.h is in error.  Unless you have truly defined operator<<
  22. on void* pointers so that it modifies the pointer, the declaration
  23. should instead be
  24.  
  25.         ostream& operator<<(const void *p);
  26.  
  27.  
  28.  
  29. For example, the following program should *not* issue the const
  30. violation warning that it does.
  31.  
  32.  
  33.  
  34. #include <iostream.h>
  35.  
  36. int main()
  37. {
  38.   const char *foo = "stuff";
  39.  
  40.   cout << (const void *)foo << endl;
  41.  
  42.   return 0;
  43. }
  44.  
  45.  
  46.  
  47.  
  48. djb@bambam>g++ -g -Wall test.cc
  49. test.cc: In function `int  main ()':
  50. test.cc:7: warning: argument passing of non-`const *' pointer from `const *'
  51. test.cc:7: warning: argument passing of non-`const *' pointer from `const *'
  52.  
  53.  
  54.  
  55. I have encountered this warning frequently, because in my code I am
  56. often writing out the address of an object to help identify it.  If
  57. foo is `const <class> *', then I must cast it to `const void *' and
  58. *not* to `void *' when printing its address in order to avoid a const
  59. violation.
  60.  
  61.  
  62. Please contact me if you have any further questions.
  63.  
  64. Dave
  65.  
  66.