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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!gatech!rpi!batcomputer!munnari.oz.au!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
  3. From: fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: const on pass by value
  5. Message-ID: <9221212.10105@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <1992Jul24.151010.11969@PacBell.COM> <9220801.5026@mulga.cs.mu.OZ.AU> <1992Jul28.180713.16258@mole-end.matawan.nj.us>
  9. Date: Thu, 30 Jul 1992 02:14:14 GMT
  10. Lines: 48
  11.  
  12. mat@mole-end.matawan.nj.us writes:
  13.  
  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. >> >> 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. >> Huh? In this example, it IS just nitpicking.  How could the presence or
  29. >> absence of const in the declaration for foo affect the program's const
  30. >> correctness?
  31. >
  32. >It affects what version of overloads are applied to the variable/object
  33. >and the confidence of the reader that the variables are/are not changed.
  34.  
  35. It does NOT affect what version of overloads are applies to the variable/object.
  36. For example:
  37.  
  38.     fergus> cat > test.c
  39.     int foo(int a) { return a; }
  40.     int foo(const int a) { return -a; }
  41.  
  42.     fergus> CC test.c
  43.     "test.c", line 2: error: the overloading mechanism cannot tell a int (int ) from a int (const int )
  44.  
  45. Furthermore the only reason why it might affect the confidence of the reader
  46. that the variables are not changed is if the reader does not understand the
  47. semantics of pass-py-value in C. (If this is the case then the reader,
  48. not the program, is broken :-). Besides, the "confidence of the reader" is
  49. a fairly dubious thing in general; this is very much a matter of style (ie.
  50. "nitpicking").
  51.  
  52. Thus I still maintain that it IS just nitpicking.
  53.  
  54. -- 
  55. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  56. This .signature VIRUS is a self-referential statement that is true - but 
  57. you will only be able to consistently believe it if you copy it to your own
  58. .signature file!
  59.