home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11632 < prev    next >
Encoding:
Text File  |  1992-07-27  |  1.8 KB  |  54 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!mmm.serc.3m.com!pwcs!cdsmn!wells
  3. From: wells@cdsmn.mn.org (Rich Wells)
  4. Subject: Re: const on pass by value
  5. Message-ID: <1992Jul27.154311.26719@cdsmn.mn.org>
  6. Reply-To: wells@cdsmn.UUCP (Rich Wells)
  7. Organization: Dicomed, Inc., Burnsville, MN
  8. References: <1992Jul24.151010.11969@PacBell.COM> <1992Jul25.071559.4236@uunet.uu.net!mole-end> <9220801.5026@mulga.cs.mu.OZ.AU>
  9. Date: Mon, 27 Jul 92 15:43:11 GMT
  10. Lines: 42
  11.  
  12. In article <9220801.5026@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  13. >mat@uunet.uu.net!mole-end writes:
  14. >
  15. >>In article <1992Jul24.151010.11969@PacBell.COM>, pjcondi@lepton (Paul Condie) writes:
  16. >>> Should pass by value arguments be declared as "const" for
  17. >>> good coding style?  Or is that nit picking?
  18. >> 
  19. >>> For example:
  20. >> 
  21. >>> void foo (const int a);
  22. >>> or
  23. >>> void foo (int a);
  24. >>
  25. >>It's not nitpicking.  It's part of something called const correctness.
  26. >>Your program has it or doesn't.  Programs that have it are almost immune
  27. >>to a certain large family of errors.
  28. >
  29. >Huh? In this example, it IS just nitpicking.
  30. >How could the presence or absence of const in the declaration for foo
  31. >affect the program's const correctness?
  32. >
  33.  
  34. Consider this case:
  35.  
  36. void bar(int & a)
  37. {
  38. }
  39.  
  40. void foo(const int a)
  41. {
  42.    bar(a);
  43. }
  44.  
  45. Should the compiler allow the call to bar() from foo()?  I think not.
  46. I'm still a relative newcomer to C++ but it seems to my this is an
  47. example of where  the presence or absence of const in the declaration
  48. of foo DOES affect the program's const correctness.
  49.  
  50. Granted, this is a contrived example, but replace the 'int' with
  51. a 'struct' and it is no longer quite so contrived.
  52.  
  53. Richard Wells   wells@cdsmn.mn.org  or  ...!tcnet!cdsmn!wells
  54.