Thread View: comp.std.c++
1 messages
1 total messages
Started by Ari Juhani Huttunen
Fri, 08 Mar 1991 11:03
default/variable/implicit arguments
Author: Ari Juhani Huttunen
Date: Fri, 08 Mar 1991 11:03
Date: Fri, 08 Mar 1991 11:03
48 lines
2446 bytes
2446 bytes
Someone on this group or comp.lang.c++ (Sorry, but that article seems to be deleted
on this system) argued that the default arguments on c++ are not good because:
f(int a=0, int b=0, int c=0);
In this example it would be very unlikely that when programmer decides to omit
argument 'a' he has already decided to omit arguments 'b' and 'c' as well.
He also suggested the calling syntax f(b:=5, c:=4);. This would allow the omission
of argument 'a' only.
Now, consider this general function declaration syntax:
int func(int a, int b=0 ... int c=0);
1) Arguments like 'a' must be given explicitly when calling this function.
2) Arguments like 'b' can be given or omitted. They can also be given using syntax
b:=value, in any order.
3) ... denotes any number of arguments of any type.
4) Arguments like 'c' cannot be supplied to the function when calling it. BUT they
are _implicitly_ passed to the function when it is called. They are passed as the
last arguments, even after the variable arguments.
Example:
int min(int a ... int last=MAXINT);
Now these calls are legal:
min(1,5,6);
min(4,5,77,2,46);
As opposed to what would have to be written now:
min(1,5,6,MAXINT);
min(4,5,77,2,46,MAXINT);
Result: We have given a way to determine how many variable arguments were given
to this function. And the user of this function doesn't have to know that
a MAXINT must be given as the last argument.
Also no added runtime overhead is forced.
--
_ _____ _____ _____ _____ _____ _____ _____ _____ _____ ___
I___I I___I I___I I___I I___I I___I I___I I___I I___I I___I
Ari Huttunen ___I___ Oikotie on pisin matka ___I___I
_ __ ___I___I___I___I__ __ kahden pisteen v{lill{ _ ___I___I_
__I __I___I___I___I___I___I___________________________________________I___I__ _
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads