Re: #define and (brackets)
- From: "Alan Carre" <alan@xxxxxxxxxxxxxxxxx>
- Date: Fri, 28 Nov 2008 22:53:59 +0700
"Alexander Grigoriev" <alegr@xxxxxxxxxxxxx> wrote in message
news:ug9Hi0WUJHA.592@xxxxxxxxxxxxxxxxxxxxxxx
That's what I have warned against. That separate preprocessing and
compilation is NOT the same as one-shot preprocessing and compilation.
Per ANSI C standard, there is NO re-pre-process (NO re-tokenization).
So then you would characterize such behaviour as "a bug".
The compiler doesn't second-guess. It just follows the standard. May not
always be doing that, but in these cases it does.
Let me show you again:
cl /E test.cpp :
line0: int main(int,...) {
line1: printf("%d", --10);
line2: return 0;
line3: }
Please explain why line1 compiles under the current standard. Is it
compliant, compileable standard ANSI C code?
By the way, I don't see what's the point in your stringizing example.
Operator # replaces the whole proprocessing token sequence for an argument
with a string.
You don't see the point? I was trying to show that the preprocessor
evaluates MACRO arguments during the process of preprocessing. If a macro
argument is not re-used as an argument (or otherwise) in another macro then
it is NOT evaluated. That's why STRIZE(NUM) --> "NUM" and _STRIZE(NUM)_ -->
"-10". NUM gets evaluated (dereferenced) during preprocessing in the second
case, but NOT the first.
Know what I mean? If NUM appears in a macro it becomes -10, if it doesn't it
remains as NUM. Don't you think that might have some RELEVANCE here when
#define X -1
int main(int,...)
{
return -X;
}
compiles fine, but
#define X -1
#define Y -X
int main(int,....)
{
return Y;
}
doesn't?
- Alan Carre
.
- Follow-Ups:
- Re: #define and (brackets)
- From: Igor Tandetnik
- 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
- Re: #define and (brackets)
- From: Alexander Grigoriev
- #define and (brackets)
- Prev by Date: Re: #define and (brackets)
- Next by Date: Re: Conditional compiling according to C++ compiler version (Express or Professional)
- Previous by thread: Re: #define and (brackets)
- Next by thread: Re: #define and (brackets)
- Index(es):
Relevant Pages
|