|
-
September 29th, 2010, 01:37 PM
#1
#define question
1.I see in some classes, there are
#ifndef IPADD_H
#define IPADD_H
#endif
What is that #xxx for ?
2.I also see
#define something somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse...........
Very long, the whole screen
WHy should they define something like that ? When should we do so ?
Thank you
--Sunny Smile
-
September 29th, 2010, 01:45 PM
#2
Re: #define question
 Originally Posted by SunnySmile
1.I see in some classes, there are
#ifndef IPADD_H
#define IPADD_H
#endif
What is that #xxx for ?
These are include guards. They prevent a given header from being #included more than once during a given compile. For instance, if A.h #includes both B.h and C.h, and C.h also #includes B.h, we only want one copy of B.h in the final preprocessed file and this ensures we only get one.
Note, include guards cannot protect against linker errors.
#define something somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse-somethingelse...........
Very long, the whole screen
WHy should they define something like that ? When should we do so ?
Some C programmers like to use macros to reduce the amount of repeated code they need to type. However, macros are difficult to debug, and in most cases C++ provides superior compile-time (as opposed to preprocess-time) alternatives such as templates and inline functions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|