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

Discussion in 'C++' started by leonm54@gmail.com, Oct 25, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. 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
     
    Stuart Redmann, Oct 25, 2006
    #2
    1. Advertising

  3. 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
     
    Victor Bazarov, Oct 25, 2006
    #3
  4. VJ Guest

    Stuart Redmann wrote:
    > 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)
     
    VJ, Oct 25, 2006
    #4
  5. Greg Comeau Guest

    In article <eho5q9$rsm$>,
    Stuart Redmann <> wrote:
    > 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?
     
    Greg Comeau, Oct 26, 2006
    #5
  6. Guest

    VJ wrote:
    > 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, 2006
    #6
  7. Bart Guest

    wrote:
    > VJ wrote:
    > > 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.
     
    Bart, Oct 26, 2006
    #7
  8. 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.

    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?
     
    Buckaroo Banzai, Nov 3, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,157
  2. theotyflos
    Replies:
    3
    Views:
    482
    Thomas Matthews
    Feb 19, 2004
  3. Monk
    Replies:
    10
    Views:
    1,502
    Michael Wojcik
    Apr 20, 2005
  4. robin liu
    Replies:
    3
    Views:
    832
    Robin Liu
    Apr 21, 2006
  5. Replies:
    4
    Views:
    634
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page