#if #endif ?

B

boki

Dear All,

Could you please tell me what is a "#" stand for in c++?

Why there is "#if 1" in program description?

It go with "#endif"

Could you please explain it? thank you very much.

Best regards,
Boki.
 
P

Peter Kragh

boki said:
Dear All,

Could you please tell me what is a "#" stand for in c++?
The "#" indicates a preprocessor directive. Your favorite C/C++ book
will tell you more.

BR,
Peter
 
T

Thomas Matthews

boki said:
Dear All,

Could you please tell me what is a "#" stand for in c++?
The '#' character is an indicator that a preprocessor
keyword is coming up.

Why there is "#if 1" in program description?

It go with "#endif"
The #if..#endif sequence allows the preprocessor to
remove blocks of source code before it is passed to
the compiler. Thus it can behave as an easy way
to "comment-out" blocks of code.

Many programmers use:
#if 0
/* code not compiled */
#endif
To comment out the code. If the programmer wants
the code to be compiled, the '0' is changed to
a '1':
#if 1
/* code is now compiled */
#endif
Could you please explain it? thank you very much.

Best regards,
Boki.
Read up on preprocessor directives.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
O

Old Wolf

Thomas Matthews said:
The '#' character is an indicator that a preprocessor
keyword is coming up.

May be coming up: # by itself is a valid directive (which has
no effect).
 
B

boki

Thank you all very much.

Best regards,
Boki.

Thomas Matthews said:
The '#' character is an indicator that a preprocessor
keyword is coming up.


The #if..#endif sequence allows the preprocessor to
remove blocks of source code before it is passed to
the compiler. Thus it can behave as an easy way
to "comment-out" blocks of code.

Many programmers use:
#if 0
/* code not compiled */
#endif
To comment out the code. If the programmer wants
the code to be compiled, the '0' is changed to
a '1':
#if 1
/* code is now compiled */
#endif

Read up on preprocessor directives.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
 
D

David Lindauer

Thomas said:
The '#' character is an indicator that a preprocessor
keyword is coming up.

The #if..#endif sequence allows the preprocessor to
remove blocks of source code before it is passed to
the compiler. Thus it can behave as an easy way
to "comment-out" blocks of code.

Many programmers use:
#if 0
/* code not compiled */
#endif
To comment out the code. If the programmer wants
the code to be compiled, the '0' is changed to
a '1':
#if 1
/* code is now compiled */
#endif

the example you give is like a comment, however #if can also be used to
selectively add different options into the code at compile time. For
example:

#if defined(DEBUG)
#define MYERROR(x) printf("x")
#else
#define MYERROR(x)
#endif

which allows you to compile printf statements in your program for
debugging then easily take them out when you are done debugging, simply
by commenting out the line that defines DEBUG

David
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top