Structs and Variadic Functions

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Dec 17 15:27:10 PST 2006


"Xinok" <xknnet at gmail.com> wrote in message 
news:em4ctn$hhu$1 at digitaldaemon.com...
>I think combining structs with variadic functions can introduce some new
> interesting possibilities.
>
> struct SS{
> int a, b, c;
> }
> static SS obj = {10, 20, 30}; // Full initalization
> static SS obj = {a : 15, c : 35}; // Partial initalization
>
>
> Apply this to a variadic function:
> void func(SS arg ...){
> writefln(arg.a);
> writefln(arg.b);
> writefln(arg.c);
> }
>
> int main(){
> func(15, 30, 45); // Full initalization
> func(b : 45, c : 30); // Partial initalization
> }

I really like that.  It also wouldn't impose any extra overhead, since the 
size of the structure on the stack would be the same size as if you were to 
pass those parameters, and accessing those struct members in the function 
would also be virtually the same as accessing parameters. 





More information about the Digitalmars-d mailing list