January 09, 2007 Re: Structs and Variadic Functions (Keyword arguments) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Xinok | Xinok wrote: > Don Clugston Wrote: > >> Bill Baxter wrote: >>> And this one's not about keyword args, but about default parameters and function pointers in general. Started by Don Clugston. >>> http://www.digitalmars.com/d/archives/digitalmars/D/27291.html >> Wow! That was my third ever D post! > > While this post is still here, I'd like to make this suggestion: > We have the 'default' keyword, let's use it! > > void func(int a = 15, int b = 30, int c = 45); > func(45, default, 60); Neat. I suppose 'default' could be used for non default args as well? void foo(int x); foo(default); // x = int.init -- - EricAnderton at yahoo |
January 09, 2007 Re: Structs and Variadic Functions (Keyword arguments) | ||||
---|---|---|---|---|
| ||||
Posted in reply to Xinok | Xinok Wrote: > > While this post is still here, I'd like to make this suggestion: We have the 'default' keyword, let's use it! > > void func(int a = 15, int b = 30, int c = 45); > func(45, default, 60); Just one more thing I'd like to add, this could propose a slight problem with overloading functions: void func(int a = 15, int b = 30, int c = 45); void func(int a = 15, string b = "Thirty", int c = 45); func(45, default, 60); // Error - Cannot overload default argument A simple suggestion for this: func(45, default int, 60); func(45, default string, 60); To the original post, perhaps we could introduce a new kind of default parameter to D? Something like a 'static default argument'. > PROPOSAL > The solution is really very simple. > > int afunc(int x, int y=3) > { > ..dosomething > } > > should be *identical* to declaring TWO functions: > > int afunc(int x) > { > afunc(x, 3); > } > > int afunc(int x, int y) > { > .. dosomething > } I know nothing about assembly, but would it be possible to simply put all the initalizers into a single function, and depending on the type of the function pointer, it jumps to the proper location in the function to initalize the rest of the parameters? int func(int a = 15, int b = 30, int c = 45){ a = 15; // int func() b = 30; // int func(int) c = 45; // int func(int, int) return a + b + c; // int func(int, int, int) } IAW, if you were to create a pointer to this function: int delegate(int, int) ptr = &func; This delegate would point directly to the address of the code where you see 'c = 45' This would eliminate any performance issues and 'ghost functions'. |
Copyright © 1999-2021 by the D Language Foundation