Connecting Tech Pros Worldwide Help | Site Map

What's the usage?

ikl
Guest
 
Posts: n/a
#1: Jul 22 '05
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
Guest
 
Posts: n/a
#2: Jul 22 '05

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


Mike Wahler
Guest
 
Posts: n/a
#3: Jul 22 '05

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


JaSeong Ju
Guest
 
Posts: n/a
#4: Jul 22 '05

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]

JaSeong Ju
Guest
 
Posts: n/a
#5: Jul 22 '05

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]

Kevin Goodsell
Guest
 
Posts: n/a
#6: Jul 22 '05

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.
Kevin Goodsell
Guest
 
Posts: n/a
#7: Jul 22 '05

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.
Closed Thread