Getting the source text of an expression
Dave P.
dave287091 at gmail.com
Thu Dec 17 19:45:38 UTC 2020
In C, you can use a macro to get the source text of an expression
as a string. For example
#include <stdio.h>
#define PRINT_INT(x) printf(#x " = %d\n", x)
int main(){
// prints "3 = 3"
PRINT_INT(3);
int x = 4;
// prints "x = 4"
PRINT_INT(x);
#define FOO 5
// prints "FOO = 5"
PRINT_INT(FOO);
#define BAR FOO
// prints "BAR = 5"
PRINT_INT(BAR);
return 0;
}
Is there a feature of D that allows you to achieve a similar
goal? I’ve used this in the past for logging for example.
More information about the Digitalmars-d-learn
mailing list