home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11735 < prev    next >
Encoding:
Internet Message Format  |  1992-07-29  |  2.3 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!mips!mips!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  2. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: const on pass by value
  5. Message-ID: <1992Jul29.165553.28233@ucc.su.OZ.AU>
  6. Date: 29 Jul 92 16:55:53 GMT
  7. References: <1992Jul25.071559.4236@uunet.uu.net!mole-end> <9220801.5026@mulga.cs.mu.OZ.AU> <1992Jul27.154311.26719@cdsmn.mn.org>
  8. Sender: news@ucc.su.OZ.AU
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. Lines: 59
  11. Nntp-Posting-Host: extro.ucc.su.oz.au
  12.  
  13. In article <1992Jul27.154311.26719@cdsmn.mn.org> wells@cdsmn.UUCP (Rich Wells) writes:
  14. >In article <9220801.5026@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  15. >>mat@uunet.uu.net!mole-end writes:
  16. >>
  17. >>>In article <1992Jul24.151010.11969@PacBell.COM>, pjcondi@lepton (Paul Condie) writes:
  18. >>>> Should pass by value arguments be declared as "const" for
  19. >>>> good coding style?  Or is that nit picking?
  20. >>> 
  21. >>>> For example:
  22. >>> 
  23. >>>> void foo (const int a);
  24. >>>> or
  25. >>>> void foo (int a);
  26. >>>
  27. >>>It's not nitpicking.  It's part of something called const correctness.
  28. >>>Your program has it or doesn't.  Programs that have it are almost immune
  29. >>>to a certain large family of errors.
  30. >>
  31. >>Huh? In this example, it IS just nitpicking.
  32. >>How could the presence or absence of const in the declaration for foo
  33. >>affect the program's const correctness?
  34. >>
  35. >
  36. >Consider this case:
  37. >
  38. >void bar(int & a)
  39. >{
  40. >}
  41. >
  42. >void foo(const int a)
  43. >{
  44. >   bar(a);
  45. >}
  46. >
  47. >Should the compiler allow the call to bar() from foo()?  I think not.
  48. >I'm still a relative newcomer to C++ but it seems to my this is an
  49. >example of where  the presence or absence of const in the declaration
  50. >of foo DOES affect the program's const correctness.
  51.  
  52.     No, it is the const in the DEFINITION that is important here.
  53.  
  54.     The definition
  55.  
  56. void foo(int a) { ...}
  57.  
  58.     is clearly different to foo above.
  59.  
  60.     But the corresponding declarations
  61.  
  62.     foo(int);
  63.     foo(const int);
  64.  
  65. are ambiguous, they cannot be distinguished.
  66.  
  67. -- 
  68. ;----------------------------------------------------------------------
  69.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  70.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  71. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  72.