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

L

leonm54

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?
 
S

Stuart Redmann

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
 
V

Victor Bazarov

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
 
V

VJ

Stuart said:
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)
 
G

Greg Comeau

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

Michiel.Salters

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
 
B

Bart

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

Buckaroo Banzai

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.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top