ProDev7
ProDev7

Reputation: 75

Precedence of -D MACRO and #define MACRO 5

Hello everybody I'm programming on Visual C++ 6.0 IDE my problem is: I tried to define macros from the command line at first I did this: project->settings c++ command definitions and i entered this macro: -DHELLO="HELLO!" when I use it from my source code I entered:

#ifdef HELLO
HELLO;
#endif

Until this everything is OK.

But my problem is with macros those takes arguments, so how I set a macro with arguments and the second question is how to expand it from source code?

Any help is really appreciated. I spent a lot of time googling and searching, reading ebooks but this didn't help.

Upvotes: 1

Views: 290

Answers (1)

Pierre Fourgeaud
Pierre Fourgeaud

Reputation: 14510

It seems that it is not possible...

If you take a look at the Microsoft documentation, the /D option is constructed like :

/Dname[= | # [{string | number}] ]

As it seems to be impossible to add parantheses, I don't it is possible to create function-like macro with this command line option...


NB: It's weird that I tried on Visual Studio, my intellisense see it as function-like macro, so no error visible in the code (no red line under it), but when it's time to compile I get :

error C3861: 'MACRO_TEST': identifier not found 

With a definition of type :

/D"MACRO_TEST( tst )= tst" // or -D"MACRO_TEST( tst )= tst"

Upvotes: 1

Related Questions