# operator under C implementation in D1
Denis Koroskin
2korden at gmail.com
Thu Mar 12 18:44:29 PDT 2009
On Fri, 13 Mar 2009 04:19:11 +0300, Sam Hu <samhu.samhu at gmail.com> 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.
>
> Regards,
> Sam
// C version
#include <stdio.h>
#define Stringize(x) #x
int main()
{
int foo = 42;
const char* s = Stringize(foo);
printf("%s", s);
return 0;
}
// D version
import std.stdio;
template Stringize(alias s)
{
auto Stringize = s.stringof;
}
int main()
{
auto foo = 42;
string s = Stringize!(foo);
writefln("%s", s);
return 0;
}
More information about the Digitalmars-d-learn
mailing list