N
niraj.tiwari
What is meaning of the following define:-
#define x(argl...) x1(##argl)
#define x(argl...) x1(##argl)
What is meaning of the following define:-
#define x(argl...) x1(##argl)
Bart said:I don't think variadic macros are allowed in C++, so the ... part is
not standard. The ## is the token pasting operator. It pastes the token
that you pass as an argument. For example the macro
#define var(n) var##n
would cause 'var(3)' to be expanded to 'var3'.
Regards,
Bart.
## operator in C++ is used inside macros to concatenate two tokens
I have tried this and this compiles on c++ compiler
I think normal syntax of variable number of argument is foo(some arg,...)
or simply foo(...).
Frederick said:flamexx7 posted:
It's nothing to do with the C++ language itself -- it's purely to do with the
preprocessor.
flamexx7 said:## operator in C++ is used inside macros to concatenate two tokens
Frederick said:flamexx7 posted:
It's nothing to do with the C++ language itself -- it's purely to do with
the preprocessor.
The preprocessor is part of the C++ language.
Frederick Gotham said:Rolf Magnus posted:
Yes, but the _actual_ C++ compiler doesn't know anything about #define...
all
of that has been stripped away in the preprocessor phase.
Couldn't you just admit that you shouldn't have made your initial post
and let it go at that?
Frederick said:Rolf Magnus posted:
Yes, but the _actual_ C++ compiler doesn't know anything about #define... all
of that has been stripped away in the preprocessor phase.
Couldn't you just admit that you shouldn't have made your initial post and
let it go at that? It is not necessary that you respond to each and every
message. AFAIK the preprocessor is a *conceptual* phase. Conceptual means
"not real".
It is true that there's no requirement that the phases of translation
necessarily produce successive versions of the source code, nor that the
version of the source code that would be the output of a given phase
necessarily exist at any point. Nonetheless, in the compilers I've
looked at, the preprocessor and compiler are distinct to at least some
degree. In some cases, they're entirely separate programs, while in
others they're compiled into a single program, but still operate
separately from each other.
Jerry Coffin wrote:
But the same could be said of other parts of the compiler as well.
While we're on the subject... I do have a question or two regarding
#defines...
1) Does the text-substitution occur across the whole file, or from the
#define onwards?
2) How / in what order does it do the substitutions? In that if I have:
#define DEF1 DEF2
#define DEF2 DEF3
#define DEF3 doStuff()
Would it do a pass for each #define, performing the substitution for
all occurences of DEF# in the file (including those in the other
#defines), remove the #define statement, then move onto the next define
statement? Or does it just do a single pass for the whole file,
performing text substitutions for the defined words only in the actual
c++ code (i.e. not performing text-substitutions for occurences within
another define statement)?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.