What's the usage?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ikl

    What's the usage?

    What's the usage of #ifdef and #endif in the code below?

    #ifdef C_DEF
    class C
    {
    public:
    void Repair();
    };

    void C::Repair () {
    ....
    }
    #endif

    Since I understand using like:

    #ifdef C_DEF
    class C
    {
    public:
    void Repair();
    };
    #endif

    void C::Repair () {
    ....
    }


    Thanks!


  • Mike Wahler

    #2
    Re: What's the usage?


    "ikl" <ikl72@dsp.co m> wrote in message
    news:PMscc.2606 7$vo5.826762@bg tnsc05-news.ops.worldn et.att.net...[color=blue]
    > What's the usage of #ifdef and #endif in the code below?
    >
    > #ifdef C_DEF[/color]

    if the symbol 'C_DEF' is defined (with a #define directive),
    then translate all the following code...
    [color=blue]
    > class C
    > {
    > public:
    > void Repair();
    > };
    >
    > void C::Repair () {
    > ...
    > }[/color]

    .... until a
    [color=blue]
    > #endif[/color]

    ... directive is encountered.
    [color=blue]
    >
    > Since I understand using like:
    >
    > #ifdef C_DEF
    > class C
    > {
    > public:
    > void Repair();
    > };
    > #endif[/color]

    This is the same as above, except it doesn't
    include the definition of the member function
    'Repair()'.
    [color=blue]
    >
    > void C::Repair () {[/color]

    A class 'C' must be visible at this point for
    this to be valid.
    [color=blue]
    > ...
    > }[/color]


    Look up 'preprocessor directives' in your C++ book.

    -Mike


    Comment

    • Mike Wahler

      #3
      Re: What's the usage?


      "ikl" <ikl72@dsp.co m> wrote in message
      news:PMscc.2606 7$vo5.826762@bg tnsc05-news.ops.worldn et.att.net...[color=blue]
      > What's the usage of #ifdef and #endif in the code below?
      >
      > #ifdef C_DEF[/color]

      if the symbol 'C_DEF' is defined (with a #define directive),
      then translate all the following code...
      [color=blue]
      > class C
      > {
      > public:
      > void Repair();
      > };
      >
      > void C::Repair () {
      > ...
      > }[/color]

      .... until a
      [color=blue]
      > #endif[/color]

      ... directive is encountered.
      [color=blue]
      >
      > Since I understand using like:
      >
      > #ifdef C_DEF
      > class C
      > {
      > public:
      > void Repair();
      > };
      > #endif[/color]

      This is the same as above, except it doesn't
      include the definition of the member function
      'Repair()'.
      [color=blue]
      >
      > void C::Repair () {[/color]

      A class 'C' must be visible at this point for
      this to be valid.
      [color=blue]
      > ...
      > }[/color]


      Look up 'preprocessor directives' in your C++ book.

      -Mike


      Comment

      • JaSeong Ju

        #4
        Re: What's the usage?

        #ifdef and #endif are used for conditional compilation.
        If C_DEF is defined, then compile in the class C and its
        public member functions.

        If C_DEF is not defined, then class C is
        not included. Then of course you dont want to include
        the
        void C::Repair () {
        ....
        }
        member function, since its an error.

        [color=blue]
        > What's the usage of #ifdef and #endif in the code below?
        >
        > #ifdef C_DEF
        > class C
        > {
        > public:
        > void Repair();
        > };
        >
        > void C::Repair () {
        > ...
        > }
        > #endif
        >
        > Since I understand using like:
        >
        > #ifdef C_DEF
        > class C
        > {
        > public:
        > void Repair();
        > };
        > #endif
        >
        > void C::Repair () {
        > ...
        > }
        >
        >
        > Thanks!
        >
        >[/color]

        Comment

        • JaSeong Ju

          #5
          Re: What's the usage?

          #ifdef and #endif are used for conditional compilation.
          If C_DEF is defined, then compile in the class C and its
          public member functions.

          If C_DEF is not defined, then class C is
          not included. Then of course you dont want to include
          the
          void C::Repair () {
          ....
          }
          member function, since its an error.

          [color=blue]
          > What's the usage of #ifdef and #endif in the code below?
          >
          > #ifdef C_DEF
          > class C
          > {
          > public:
          > void Repair();
          > };
          >
          > void C::Repair () {
          > ...
          > }
          > #endif
          >
          > Since I understand using like:
          >
          > #ifdef C_DEF
          > class C
          > {
          > public:
          > void Repair();
          > };
          > #endif
          >
          > void C::Repair () {
          > ...
          > }
          >
          >
          > Thanks!
          >
          >[/color]

          Comment

          • Kevin Goodsell

            #6
            Re: What's the usage?

            JaSeong Ju wrote:
            <A top-posted message.>

            Please stop top-posting. Read section 5 of the FAQ (which you should
            have already read) for posting guidelines:



            -Kevin
            --
            My email address is valid, but changes periodically.
            To contact me please use the address from a recent posting.

            Comment

            • Kevin Goodsell

              #7
              Re: What's the usage?

              JaSeong Ju wrote:
              <A top-posted message.>

              Please stop top-posting. Read section 5 of the FAQ (which you should
              have already read) for posting guidelines:



              -Kevin
              --
              My email address is valid, but changes periodically.
              To contact me please use the address from a recent posting.

              Comment

              Working...