Put a variable value inside a Compiler Directives

Hi, Good Morning!
I want to print a variable value inside a preprocessor directive! E.g.:

#define D(value) value


main(){
char[] test = "testing";
D(test); //I wanna send the value of test, and not the name of the variable
}


I already saw this in a C book, but i dont remember the name of the book...

Could Someone Help-me?

Thanks in advanced!!

Last edited on
Impossible. Macros are expanded before even starting compiling, so there's no way to pass something that doesn't exist, yet.
Maybe this is what you're trying to do? http://www.cplusplus.com/forum/beginner/11252/
Last edited on
Oh, Ok!

I'll Explain my project.
I'm making a programming language on top of C to improve the generation of report. So, we don't need lose more time with "printf" and anothers I/O functions.

The basic idea is use a language XML to generate the out of report. To interpret this language I use a file with the configuration and the semantic of the tags used in XML. Now, I would make a improvement, allowing the user to add some codes in configuration file. But, i'll need to try another way to make it!!

Thanks a lot!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

#define D(value) { std::cout << #value "=" << value << std::endl; }

int main()
{
        for (int value = -2; value < 3; ++value)
        {
                int j = 2*value;
                D(value);
                D(j);
        }

        return 0;
}
Topic archived. No new replies allowed.