home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17912 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  2.3 KB

  1. Path: sparky!uunet!pipex!warwick!uknet!glasgow!unix.brighton.ac.uk!je
  2. From: je@unix.brighton.ac.uk (John English)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: do variable names in header and source need to match
  5. Message-ID: <1992Dec14.105905.3929@unix.brighton.ac.uk>
  6. Date: 14 Dec 92 10:59:05 GMT
  7. References: <444@genie.UUCP>
  8. Organization: University of Brighton, UK
  9. Lines: 50
  10.  
  11. roger@genie.UUCP (Roger H. Scott) writes:
  12. : In article <1992Dec3.112538.11314@unix.brighton.ac.uk> je@unix.brighton.ac.uk (John English) writes:
  13. : >...
  14. : >One extension to the language is the ability to use arg names given in
  15. : >declarations to identify parameter ordering in calls (like Ada). For example:
  16. : >
  17. : >   int f (int x = 0, int y = 0, int z = 0);
  18. : >   f (10, z:5);   // equivalent to f (10, 0, 5);
  19. : >
  20. : >Obviously if names aren't given in the declaration, you can't do this.
  21. : >If they are, it would seem to make sense to use them somehow!
  22. : >This doesn't imply that the names in the definition have to match.
  23. : I believe it does.  Consider the following:
  24. : extern void f(int a =0, int b =0);
  25. : extern void g(int a =0, int b =0);
  26. : void g(int b, int a) { // recent C++ disallows default parameter values here
  27. :     ...
  28. : }
  29. : void h(int b =0, int a =0) {
  30. :     ...
  31. : }
  32. : ...
  33. :     // what do these mean?
  34. :     f(a:3);
  35. :     g(a:3);
  36. :     h(a:3);
  37. I would say they mean f(3,0), g(3,0) and h(0,3) respectively. The point
  38. at which you can supply defaults (i.e. the first declaration) would be
  39. the point at which you take parameter names. The names in the definition
  40. (not the declaration) of g are ignored.
  41. : This example shows that you can have a declaration, a declaration and a
  42. : definition, or only a definition, for such a function.  If you don't require
  43. : the declaration formal parameter names to match those in the definition how
  44. : are you going to come up with consistent, unambiguous semantics for the three
  45. : calls above?
  46. -- 
  47. -------------------------------------------------------------------------------
  48. John English            | Fudd's first law of opposition:
  49. Dept. of Computing        |    If you push something hard enough, it
  50. University of Brighton        |    *will* fall over.
  51. E-mail: je@unix.brighton.ac.uk    | Testlicle's deviant to Fudd's law:
  52. Fax:    0273 642405        |    What goes in, must come out.
  53. -------------------------------------------------------------------------------
  54.