Re: #define and (brackets)
- From: "Alex Blekhman" <tkfx.REMOVE@xxxxxxxxx>
- Date: Fri, 28 Nov 2008 17:37:19 +0200
"Alan Carre" wrote:
So now then, the question is (or should be) "why does this
work"?
int main(int argc,...)
{
printf("%d", -NUM);
}
Well I passed this through cl /E (preprocess to stdout) and got
this as the result:
int main(int argc, ...)
{
...lots of space...
printf("%d", --10);
return 0;
...lots of space...
}
Again, no spaces after the first minus sign, which should
clearly have generated a compiler error. CLEARLY.
I think you missed the Igor's point. You do the same logical
mistake that Tommy does. The preprocessor doesn't work with text
and doesn't output text. It works with the list of tokens, which
is prepared by previous stage of parsing. So, the representation
of the "printf("%d", -NUM);" statement is (in pseudocode):
// tokenization phase
typedef list<string> token_stream;
token_stream t;
t[0] = "printf";
t[1] = "(";
t[2] = "\"%d\"";
t[3] = ",";
t[4] = "-";
t[5] = "NUM";
t[6] = ")";
t[7] = ";";
// macros expansion phase
for(token_stream::iterator it = t.begin();
it != t.end();
++it)
{
if(*it == "NUM")
{
parse_result pr = tokenize(macros["NUM"]);
t.insert(it, pr.begin(), pr.end());
}
}
HTH
Alex
.
- Follow-Ups:
- Re: #define and (brackets)
- From: Alan Carre
- Re: #define and (brackets)
- References:
- #define and (brackets)
- From: Gerry Hickman
- Re: #define and (brackets)
- From: David Webber
- Re: #define and (brackets)
- From: Alan Carre
- Re: #define and (brackets)
- From: Igor Tandetnik
- Re: #define and (brackets)
- From: Alan Carre
- Re: #define and (brackets)
- From: Alan Carre
- Re: #define and (brackets)
- From: Igor Tandetnik
- Re: #define and (brackets)
- From: Alan Carre
- #define and (brackets)
- Prev by Date: Re: #define and (brackets)
- Next by Date: Re: #define and (brackets)
- Previous by thread: Re: #define and (brackets)
- Next by thread: Re: #define and (brackets)
- Index(es):
Relevant Pages
|