home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!pipex!warwick!uknet!glasgow!unix.brighton.ac.uk!je
- From: je@unix.brighton.ac.uk (John English)
- Newsgroups: comp.lang.c++
- Subject: Re: do variable names in header and source need to match
- Message-ID: <1992Dec14.105905.3929@unix.brighton.ac.uk>
- Date: 14 Dec 92 10:59:05 GMT
- References: <444@genie.UUCP>
- Organization: University of Brighton, UK
- Lines: 50
-
- roger@genie.UUCP (Roger H. Scott) writes:
- : In article <1992Dec3.112538.11314@unix.brighton.ac.uk> je@unix.brighton.ac.uk (John English) writes:
- : >...
- : >One extension to the language is the ability to use arg names given in
- : >declarations to identify parameter ordering in calls (like Ada). For example:
- : >
- : > int f (int x = 0, int y = 0, int z = 0);
- : > f (10, z:5); // equivalent to f (10, 0, 5);
- : >
- : >Obviously if names aren't given in the declaration, you can't do this.
- : >If they are, it would seem to make sense to use them somehow!
- : >This doesn't imply that the names in the definition have to match.
- :
- : I believe it does. Consider the following:
- :
- : extern void f(int a =0, int b =0);
- : extern void g(int a =0, int b =0);
- :
- : void g(int b, int a) { // recent C++ disallows default parameter values here
- : ...
- : }
- :
- : void h(int b =0, int a =0) {
- : ...
- : }
- :
- : ...
- : // what do these mean?
- : f(a:3);
- : g(a:3);
- : h(a:3);
- I would say they mean f(3,0), g(3,0) and h(0,3) respectively. The point
- at which you can supply defaults (i.e. the first declaration) would be
- the point at which you take parameter names. The names in the definition
- (not the declaration) of g are ignored.
- :
- :
- : This example shows that you can have a declaration, a declaration and a
- : definition, or only a definition, for such a function. If you don't require
- : the declaration formal parameter names to match those in the definition how
- : are you going to come up with consistent, unambiguous semantics for the three
- : calls above?
- --
- -------------------------------------------------------------------------------
- John English | Fudd's first law of opposition:
- Dept. of Computing | If you push something hard enough, it
- University of Brighton | *will* fall over.
- E-mail: je@unix.brighton.ac.uk | Testlicle's deviant to Fudd's law:
- Fax: 0273 642405 | What goes in, must come out.
- -------------------------------------------------------------------------------
-