Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > // comments following a #define; issue or not.

Reply
Thread Tools

// comments following a #define; issue or not.

 
 
leonm54@gmail.com
Guest
Posts: n/a
 
      10-25-2006
I have nightmares about code similar to the following:

#define NUM_TRIES 10 // Number of tries before we eject them

....

if ( iCurrentTicks > NUM_TRIES)
{
....
}

Maybe preprocessors and compilers have progressed where the previous is
no longer an issue. I remember distinctly that on the compilers I have
used in the past the previous if statement would become, after
pre-processing:


if( iCurrentTicks > 10 // Number of tries before we eject them)

This would cause all kinds of issues when the code compiled.

Am I out of touch, or is this sort of thing still a potential issue?

 
Reply With Quote
 
 
 
 
Stuart Redmann
Guest
Posts: n/a
 
      10-25-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> I have nightmares about code similar to the following:
>
> #define NUM_TRIES 10 // Number of tries before we eject them
>
> ...
>
> if ( iCurrentTicks > NUM_TRIES)
> {
> ...
> }
>
> Maybe preprocessors and compilers have progressed where the previous is
> no longer an issue. I remember distinctly that on the compilers I have
> used in the past the previous if statement would become, after
> pre-processing:
>
>
> if( iCurrentTicks > 10 // Number of tries before we eject them)
>
> This would cause all kinds of issues when the code compiled.
>
> Am I out of touch, or is this sort of thing still a potential issue?
>


I think you're definitely out of touch. Most headers I encountered
contained tons of such documented defines.

Stuart
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      10-25-2006
(E-Mail Removed) wrote:
> I have nightmares about code similar to the following:
>
> #define NUM_TRIES 10 // Number of tries before we eject them
>
> ...
>
> if ( iCurrentTicks > NUM_TRIES)
> {
> ...
> }
>
> Maybe preprocessors and compilers have progressed where the previous
> is no longer an issue. I remember distinctly that on the compilers I
> have used in the past the previous if statement would become, after
> pre-processing:
>
>
> if( iCurrentTicks > 10 // Number of tries before we eject them)
>
> This would cause all kinds of issues when the code compiled.
>
> Am I out of touch, or is this sort of thing still a potential issue?


Out of touch. Comments are replaced with a single space before any
macros are substituted.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
VJ
Guest
Posts: n/a
 
      10-25-2006
Stuart Redmann wrote:
> (E-Mail Removed) wrote:
>
>> I have nightmares about code similar to the following:
>>
>> #define NUM_TRIES 10 // Number of tries before we eject them
>>
>> ...
>>
>> if ( iCurrentTicks > NUM_TRIES)
>> {
>> ...
>> }
>>
>> Maybe preprocessors and compilers have progressed where the previous is
>> no longer an issue. I remember distinctly that on the compilers I have
>> used in the past the previous if statement would become, after
>> pre-processing:
>>
>>
>> if( iCurrentTicks > 10 // Number of tries before we eject them)
>>
>> This would cause all kinds of issues when the code compiled.
>>
>> Am I out of touch, or is this sort of thing still a potential issue?
>>

>
> I think you're definitely out of touch. Most headers I encountered
> contained tons of such documented defines.
>
> Stuart


isnt next better?

static const int NUM_TRIES 10; // Number of tries before we eject them

(type depends on the type of iCurrentTicks)
 
Reply With Quote
 
Greg Comeau
Guest
Posts: n/a
 
      10-26-2006
In article <eho5q9$rsm$(E-Mail Removed)>,
Stuart Redmann <(E-Mail Removed)> wrote:
>(E-Mail Removed) wrote:
>
>> I have nightmares about code similar to the following:
>>
>> #define NUM_TRIES 10 // Number of tries before we eject them
>>
>> ...
>>
>> if ( iCurrentTicks > NUM_TRIES)
>> {
>> ...
>> }
>>
>> Maybe preprocessors and compilers have progressed where the previous is
>> no longer an issue. I remember distinctly that on the compilers I have
>> used in the past the previous if statement would become, after
>> pre-processing:
>>
>>
>> if( iCurrentTicks > 10 // Number of tries before we eject them)
>>
>> This would cause all kinds of issues when the code compiled.
>>
>> Am I out of touch, or is this sort of thing still a potential issue?
>>

>
>I think you're definitely out of touch. Most headers I encountered
>contained tons of such documented defines.


Once upon a time, some C++ compilers were using C preprocessors
(preprocessors from C compilers, usually run stand alone)
which meant //'s were being processed out of sync if you will.
--
Greg Comeau / 20 years of Comeauity! Intel Mac Port now in beta!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
 
Reply With Quote
 
Michiel.Salters@tomtom.com
Guest
Posts: n/a
 
      10-26-2006
VJ wrote:
> (E-Mail Removed) wrote:
>
> > I have nightmares about code similar to the following:
> >
> > #define NUM_TRIES 10 // Number of tries before we eject them


> isnt next better?
>
> static const int NUM_TRIES 10; // Number of tries before we eject them


Yes, of course, assuming you add the =

namespace { } instead of static may be even better.

HTH,
Michiel Salters

 
Reply With Quote
 
Bart
Guest
Posts: n/a
 
      10-26-2006
(E-Mail Removed) wrote:
> VJ wrote:
> > (E-Mail Removed) wrote:
> >
> > > I have nightmares about code similar to the following:
> > >
> > > #define NUM_TRIES 10 // Number of tries before we eject them

>
> > isnt next better?
> >
> > static const int NUM_TRIES 10; // Number of tries before we eject them

>
> Yes, of course, assuming you add the =
>
> namespace { } instead of static may be even better.


Actually, it's superfluous because const objects already have internal
linkage by default.

Note: This is different from C where const has extern linkage by
default.

Regards,
Bart.

 
Reply With Quote
 
Buckaroo Banzai
Guest
Posts: n/a
 
      11-03-2006
Thank you to everyone that responded.

I will attempt to force a mental paradigm shift so when I see a
"//" type comment in C++, I won't freak out

Personally, I don't think I will ever code that way. As I said, I
have too many bad memories.

(E-Mail Removed) wrote:
> I have nightmares about code similar to the following:
>
> #define NUM_TRIES 10 // Number of tries before we eject them
>
> ...
>
> if ( iCurrentTicks > NUM_TRIES)
> {
> ...
> }
>
> Maybe preprocessors and compilers have progressed where the previous is
> no longer an issue. I remember distinctly that on the compilers I have
> used in the past the previous if statement would become, after
> pre-processing:
>
>
> if( iCurrentTicks > 10 // Number of tries before we eject them)
>
> This would cause all kinds of issues when the code compiled.
>
> Am I out of touch, or is this sort of thing still a potential issue?


 
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
The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/822319ev1'. 'HTTP/1.1 500 Internal Server Error'. chanmm ASP .Net 2 09-07-2010 07:37 AM
A program to replace all JS comments with JSP comments in jsp files tungchau81@yahoo.com Javascript 4 06-03-2006 02:00 PM
A program to replace all JS comments with JSP comments in jsp files tungchau81@yahoo.com Java 0 06-02-2006 06:35 AM
Comments format: comments extending over multi-line Monk C Programming 10 04-20-2005 05:09 PM
RE: The Web server reported the following error when attempting to create or open the Web project located at the following URL: <URL> =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?= ASP .Net 0 06-07-2004 07:36 AM



Advertisments