Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > remotely legal?

Reply
Thread Tools

remotely legal?

 
 
Noah Roberts
Guest
Posts: n/a
 
      01-18-2007
#define new DEBUG_NEW


I can't imagine that has defined behavior.

 
Reply With Quote
 
 
 
 
Andre Kostur
Guest
Posts: n/a
 
      01-18-2007
"Noah Roberts" <> wrote in
news: ups.com:

> #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.
 
Reply With Quote
 
 
 
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      01-18-2007
Andre Kostur wrote:

> "Noah Roberts" <> wrote in
> news: ups.com:
>
>> #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.


Best

Kai-Uwe Bux
 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      01-18-2007

Kai-Uwe Bux wrote:

> 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.


Yeah, I didn't think it was legal.

 
Reply With Quote
 
Andre Kostur
Guest
Posts: n/a
 
      01-18-2007
Kai-Uwe Bux <> wrote in
news:eoonb9$olk$:

> Andre Kostur wrote:
>
>> "Noah Roberts" <> wrote in
>> news: ups.com:
>>
>>> #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).
 
Reply With Quote
 
Kai-Uwe Bux
Guest
Posts: n/a
 
      01-19-2007
Andre Kostur wrote:

> Kai-Uwe Bux <> wrote in
> news:eoonb9$olk$:
>
>> Andre Kostur wrote:
>>
>>> "Noah Roberts" <> wrote in
>>> news: ups.com:
>>>
>>>> #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?


No, the restrictions mentioned in this section are all about what client
code may or may not do. The point of these provisions is to make sure that
the standard library can rely on the meanings of all keywords and reserved
identifiers. From the standard [17.4.3] "Constraints on programs":

This subclause describes restrictions on C++ programs that use the
facilities of the C + + Standard Library.

As you see: restrictions on programs that _use_ the library not restrictions
on the implementation of the library.

They only thing funny is that you seem to be allowed to redefine new
provided you do not include any standard headers whatsoever.

> 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).


It's the other way around.


Best

Kai-Uwe Bux
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XPpro+SP2: Rotate WEP keys remotely? DevilsPGD Wireless Networking 3 11-07-2005 01:44 AM
Re: Watching cable t.v. remotely andre Wireless Networking 2 09-17-2004 10:15 PM
Printing Remotely Wireless Networking 0 08-25-2004 02:03 PM
Access Right for Perlscript to Read Windows EventLog Remotely Joe Perl 1 09-29-2003 05:29 PM
Re: Calling a .NET component from a COM component remotely Soni ASP .Net 0 07-25-2003 04:33 AM



Advertisments