N
Noah Roberts
#define new DEBUG_NEW
I can't imagine that has defined behavior.
I can't imagine that has defined behavior.
#define new DEBUG_NEW
I can't imagine that has defined behavior.
Andre said:Why not? That's just a preprocessor directive that wherever it sees
"new",
replace with "DEBUG_NEW". Whether that has a good or bad effect on the
rest of your code depends on the rest of your code. But that line in
isolation has perfectly defined behaviour.
Kai-Uwe Bux said:As soon as you find that line not in isolation but within a translation unit
(i.e., as soon as you try to actually compile that line), clause
[17.4.3.1.1/2] kicks in:
A translation unit that includes a header shall not contain any macros
that define names declared or defined in that header. Nor shall such a
translation unit define macros for names lexically identical to keywords.
Andre said:Why not? That's just a preprocessor directive that wherever it sees
"new",
replace with "DEBUG_NEW". Whether that has a good or bad effect on
the rest of your code depends on the rest of your code. But that
line in isolation has perfectly defined behaviour.
As soon as you find that line not in isolation but within a
translation unit (i.e., as soon as you try to actually compile that
line), clause [17.4.3.1.1/2] kicks in:
A translation unit that includes a header shall not contain any
macros that define names declared or defined in that header. Nor
shall such a translation unit define macros for names lexically
identical to keywords.
Andre said:Andre said:#define new DEBUG_NEW
I can't imagine that has defined behavior.
Why not? That's just a preprocessor directive that wherever it sees
"new",
replace with "DEBUG_NEW". Whether that has a good or bad effect on
the rest of your code depends on the rest of your code. But that
line in isolation has perfectly defined behaviour.
As soon as you find that line not in isolation but within a
translation unit (i.e., as soon as you try to actually compile that
line), clause [17.4.3.1.1/2] kicks in:
A translation unit that includes a header shall not contain any
macros that define names declared or defined in that header. Nor
shall such a translation unit define macros for names lexically
identical to keywords.
Huh... didn't know that it was explicitly disallowed. I would have
figured it would have been under the heading of "really bad idea to do",
like "#define if while"......
Oh wait... That's under the section of "Library introduction". Aren't
those restrictions only on headers that are supplied by the C++ Standard
Library, and is not imposing additional requirements on user-supplied
headers?
I interpret that to read that Standard Library headers will not
pull stunts like the aforementioned "#define if while" (or to word another
way, you can count on the standard library not messing with reserved
keywords).
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.