port c macro to D

Matthias Pleh user at example.net
Thu Sep 15 04:37:02 PDT 2011


When porting c-code to D, I come consitently to the problem,
how to convert such a c-macro:

#define V(a,b,c) glVertex3d( a size, b size, c size );
#define N(a,b,c) glNormal3d( a, b, c );
N( 1.0, 0.0, 0.0); V(+,-,+); V(+,-,-); V(+,+,-); V(+,+,+);
...

Ok, I could just write it out, but that's not the case.
Sometimes I just want to keep it small and clear as in this example.
I've started with some static functions and use it in mixins:

static string V(string a, string b, string c) {
	return "glVertex3d("~a~" size, "~b~" size, "~c~" size)";	
}
static string N(string a, string b, string c) {
	return "glNormal3d("~a~","~b~","~c~");";
}


But I wonder, if there is another clean solution for this?
Any regards.

Matthias


More information about the Digitalmars-d-learn mailing list