Connecting Tech Pros Worldwide Help | Site Map

What's the usage?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 09:01 AM
ikl
Guest
 
Posts: n/a
Default 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!



  #2  
Old July 22nd, 2005, 09:01 AM
Mike Wahler
Guest
 
Posts: n/a
Default Re: What's the usage?


"ikl" <ikl72@dsp.com> wrote in message
news:PMscc.26067$vo5.826762@bgtnsc05-news.ops.worldnet.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


  #3  
Old July 22nd, 2005, 09:01 AM
Mike Wahler
Guest
 
Posts: n/a
Default Re: What's the usage?


"ikl" <ikl72@dsp.com> wrote in message
news:PMscc.26067$vo5.826762@bgtnsc05-news.ops.worldnet.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


  #4  
Old July 22nd, 2005, 09:01 AM
JaSeong Ju
Guest
 
Posts: n/a
Default 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]

  #5  
Old July 22nd, 2005, 09:01 AM
JaSeong Ju
Guest
 
Posts: n/a
Default 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]

  #6  
Old July 22nd, 2005, 09:03 AM
Kevin Goodsell
Guest
 
Posts: n/a
Default 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:

http://www.parashift.com/c++-faq-lite/

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
  #7  
Old July 22nd, 2005, 09:03 AM
Kevin Goodsell
Guest
 
Posts: n/a
Default 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:

http://www.parashift.com/c++-faq-lite/

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.