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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: const on pass by value
  5. Message-ID: <1992Jul24.185201.13330@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Jul24.151010.11969@PacBell.COM>
  10. Date: Fri, 24 Jul 1992 18:52:01 GMT
  11. Lines: 40
  12.  
  13. In article <1992Jul24.151010.11969@PacBell.COM> pjcondi@lepton (Paul Condie) writes:
  14. >Should pass by value arguments be declared as "const" for
  15. >good coding style?  Or is that nit picking?
  16. >
  17. >For example:
  18. >
  19. >void foo (const int a);
  20. >or
  21. >void foo (int a);
  22. >
  23.  
  24.     you usually declare const.
  25.  
  26.     However: this is a design flaw IMHO in the langauge.
  27.  
  28.     Const value arguments dont make sense: they're copied
  29. anyhow, so it makes no difference. The reason for having const
  30. parameters in declarations is that you sometimes want the
  31. COPIED value in the function *definition* to be const.
  32.  
  33. But this has nothing to do with the declaration except that
  34. the language is incapable of distinguishing them.
  35.  
  36. I think the following should be legal:
  37.  
  38. void foo (int a);
  39. void foo (const int a) { .... } // SAME as foo above
  40.  
  41. My argument breaks down if value parameters are not copied.
  42. Then 'const' can mean: it is ok to pass this one by reference.
  43.  
  44. A similar issue applies to const RETURN values from functions.
  45. And that one is very important and I think not resolved.
  46.  
  47.  
  48. -- 
  49. ;----------------------------------------------------------------------
  50.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  51.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  52. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  53.