Re: #define and (brackets)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"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


.



Relevant Pages

  • Re: question about code comment
    ... Ethan Meyers wrote: ... there are two programs in a file: int mainint main ... How to use other preprocess to comment out one of the mainrather ... Robert ...
    (comp.lang.c)
  • question about code comment
    ... {int x;return 0;} ... How to use other preprocess to comment out one of the mainrather ... Prev by Date: ...
    (comp.lang.c)
  • Re: question about code comment
    ... Ethan Meyers a écrit: ... there are two programs in a file: int mainint main ... How to use other preprocess to comment out one of the mainrather ... C is a sharp tool. ...
    (comp.lang.c)