Structs and Variadic Functions

Xinok xknnet at gmail.com
Sun Dec 17 13:30:31 PST 2006


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
}



In response to my last two suggestions:
Using aliases for constants - I greatly misunderstood how 'const' works in D.
As long as you initalize the variable, D forces the expression to be constant.
static int a;
const int* ptr = &a; // OK
const int* ptr = new int; // Error: non-constant expression new int

Virtual Import - I didn't think this was a great idea anyways. I was just
trying to suggest a way to define aliases for modules.



More information about the Digitalmars-d mailing list