# operator under C implementation in D1

Sergey Gromov snake.scaly at gmail.com
Sat Mar 14 16:48:32 PDT 2009


Thu, 12 Mar 2009 21:19:11 -0400, Sam Hu wrote:

> I know a little that in C there is a # operator which under a macro
> can return any type's value in character format.Just wanna know
> whether there is an equivelent implementation in D1.Say,in C using
> a/m macro can easily output enum's character value other than
> integer.It would be grateful if anybody would like to paste a few
> lines of code to demostrate such implementation.

I know this doesn't help, but the C preprocessor's # operator does not
"return ... value in character format".  All it does it converts a macro
argument into a string literal:

#define STRINGIZE(x) #x
int foo = 43;
const char *s = STRINGIZE(foo); // s now is "foo", not "43"
const char *s1 = STRINGIZE(foo * 15 + 1); // s1 is "foo * 15 + 1"

This is exactly what D's .stringof does.


More information about the Digitalmars-d-learn mailing list