Re: #define and (brackets)
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Mon, 24 Nov 2008 22:00:32 -0500
"Alan Carre" <alan@xxxxxxxxxxxxxxxxx> wrote in message
news:OoQb5opTJHA.5860@xxxxxxxxxxxxxxxxxxxx
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:epMGpUoTJHA.3520@xxxxxxxxxxxxxxxxxxxxxxx
Alan Carre <alan@xxxxxxxxxxxxxxxxx> wrote:
-SHRINK_BOX_AMOUNT won't get parsed as --20, but as - -20 (which will
likely compile just fine, but I'm too lazy to check). Preprocessor
works after lexer, handling tokens rather than individual
characters. You need ## operator to create new tokens.
Nope, just try it. It won't compile, no spaces are inserted after the
minus sign.
This program successfully compiles:
#define X -1
int main()
{
return -X;
}
And --20 is not a *new* token, it is not a token at all!
--20 is parsed as two tokens, "--" and "20". -X in the above example
gets expanded to three tokens, "-", "-" and "1". Compiler proper works
on a stream of tokens (after lexer and preprocessor), not a stream of
characters. For more details, see C++ standard 2.1 "Phases of
translation".
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- 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
- #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
|
Loading