473,382 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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?

Oct 25 '06 #1
7 6763
le*****@gmail.com 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
Oct 25 '06 #2
le*****@gmail.com 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
Oct 25 '06 #3
VJ
Stuart Redmann wrote:
le*****@gmail.com 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)
Oct 25 '06 #4
In article <eh**********@news.dtag.de>,
Stuart Redmann <De*******@web.dewrote:
>le*****@gmail.com 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?
Oct 26 '06 #5
VJ wrote:
le*****@gmail.com 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

Oct 26 '06 #6
Mi*************@tomtom.com wrote:
VJ wrote:
le*****@gmail.com 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.

Oct 26 '06 #7
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.

le*****@gmail.com 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?
Nov 3 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Uwe Ziegenhagen | last post by:
Hello, my fellows and me implement a c++ tool that is able to divide blank/tab separated files into <number>, <text>, <c-singlelinecomment> and <multilinecomment>. So far it's not working bad,...
12
by: Nobody | last post by:
DB2 500G database, Wintel, heavily loaded OLTP (5M+ transactions a day; all transactions are extremely small, all selects are controlled (no ad-hoc), 99% of all selects are very small (no table...
1
by: djinni | last post by:
It's been a while since I've written anything in C, and I was hoping to get some feedback on the following code. As far as I can tell, the program works fine, but I'm not sure I'm cleaning all the...
19
by: Alex Vinokur | last post by:
Is there any tool to count C-program lines except comments? Thanks, ===================================== Alex Vinokur mailto:alexvn@connect.to http://mathforum.org/library/view/10978.html...
22
by: Adam Barr | last post by:
For a book I am working on, I have written a brief (7 page) summary of C. The intent of this is that an experienced programmer who did not know C would be able to get enough information to read and...
10
by: William L. Bahn | last post by:
I'm looking for a few kinds of feedback here. First, there is a program at the end of this post that has a function kgets() that I would like any feedback on - including style. Second, for...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
100
by: jacob navia | last post by:
Recently, a heated debate started because of poor mr heathfield was unable to compile a program with // comments. Here is a utility for him, so that he can (at last) compile my programs :-) ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.