## digitalmars.D.learn - port c macro to D

• Matthias Pleh (18/18) Sep 15 2011 When porting c-code to D, I come consitently to the problem,
• Trass3r (4/19) Sep 15 2011 If you are willing to write V(+1,-1,+1) instead you can just turn them
• Matthias Pleh (4/7) Sep 15 2011 No, I meant for mixin I nead static functions, but I just realized,
• Trass3r (2/5) Sep 15 2011 I think static has no meaning in global scope, only in function scope
Matthias Pleh <user example.net> writes:
```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
```
Sep 15 2011
Trass3r <un known.com> writes:
```Am 15.09.2011, 13:37 Uhr, schrieb Matthias Pleh <user example.net>:

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~");";
}

If you are willing to write V(+1,-1,+1) instead you can just turn them
into functions.
Also by static function you probably mean private in D.
```
Sep 15 2011
Matthias Pleh <user example.net> writes:
```On 15.09.2011 13:48, Trass3r wrote:
If you are willing to write V(+1,-1,+1) instead you can just turn them
into functions.

really a good point! :)

Also by static function you probably mean private in D.

No, I meant for mixin I nead static functions, but I just realized,
it also works without the static keyword.
```
Sep 15 2011
Trass3r <un known.com> writes:
``` Also by static function you probably mean private in D.

No, I meant for mixin I nead static functions, but I just realized,
it also works without the static keyword.

I think static has no meaning in global scope, only in function scope
where it tells the compiler you don't want a closure.
```
Sep 15 2011